Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Add roleName option #82

Merged
merged 1 commit into from
Mar 17, 2020
Merged

Add roleName option #82

merged 1 commit into from
Mar 17, 2020

Conversation

holidayworking
Copy link
Contributor

assam is great tools. But this tool cannot be used in my environment.

I have two IAM roles as below.

  • TestRole1
  • TestRole2

I want to use TestRole2, but this tool uses TestRole1.

I can choose the role I want to use.

$ assam --role TestRole2

Copy link
Contributor

@miyajan miyajan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@holidayworking Thank you for your great PR!👍 I've left a few comments that should be addressed before this gets merged.😸

aws/saml.go Outdated
Comment on lines 116 to 118
if roleName != "" && !strings.HasSuffix(roleArn, roleName) {
continue
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HasSuffix can cause a problem. For example, when there are two roles "SuperTestRole" and "TestRole" and "TestRole" is specified as roleName, strings.HasSuffix("SuperTestRole", "TestRole") can return true. This is not expected behavior.

I suggest to split roleArn by "/" and compare the last substring with roleName.

Suggested change
if roleName != "" && !strings.HasSuffix(roleArn, roleName) {
continue
}
splitStrings := strings.Split(roleArn, "/")
attrRoleName := splitStrings[len(splitStrings) - 1]
if roleName != "" && attrRoleName != roleName {
continue
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I overlooked that.
Fixed 8d256af.

aws/saml_test.go Outdated
},
wantRoleArn: "arn:aws:iam::012345678901:role/TestRole",
wantPrincipalArn: "arn:aws:iam::012345678901:saml-provider/TestProvider",
},
{
name: "returns first role when role role attribute are multi and no roleName argument",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix "role role" to "role".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 047604d.

aws/saml_test.go Outdated
wantPrincipalArn: "arn:aws:iam::012345678901:saml-provider/TestProvider1",
},
{
name: "returns specify role when role role attribute are multi and roleName argument",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix this too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 047604d.

@holidayworking
Copy link
Contributor Author

@miyajan
Thank you for your confirmation.
I fixed your advice. Please check again.

Copy link
Contributor

@miyajan miyajan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Member

@ganta ganta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@holidayworking
Thank you for your contribution!

This looks good.
Can you squash your commits into meaningful units?
In this case, I think one is enough.

@holidayworking
Copy link
Contributor Author

@ganta

Can you squash your commits into meaningful units?
In this case, I think one is enough.

I squashed my commits.

Copy link
Member

@ganta ganta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@ganta ganta merged commit 9150250 into cybozu:master Mar 17, 2020
@holidayworking holidayworking deleted the add_role_name branch March 17, 2020 02:36
@holidayworking
Copy link
Contributor Author

@ganta @miyajan Thank you.

@ganta
Copy link
Member

ganta commented Mar 17, 2020

@holidayworking v1.2.0 is released! Please try it.

@holidayworking
Copy link
Contributor Author

@ganta
Thank you for the release.
I confirmed that it works as expected.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants