Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws/session: Add Assume role for credential process from aws profile #2674

Merged
merged 26 commits into from
Jul 10, 2019

Conversation

skotambkar
Copy link
Contributor

  • Enabled support to assume role using Credential Process from AWS Profile.
  • Added and updated test files, configuration files accordingly.

@ghost
Copy link

ghost commented Jun 29, 2019

How I’m lost

Copy link
Contributor

@jasdel jasdel left a comment

Choose a reason for hiding this comment

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

Looks good, couple suggestion.

Also need to make sure we test for windows.

os.Clearenv()
// StashEnv stashes the current environment variables except variables listed in envToKeep
// Returns an array of all environment values as key=val strings.
func StashEnv(envToKeep ...string) []string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest updating aws/credentials/processcreds test, preserveImportantStashEnv function to use this updated utility.


[cred_proc_arn_set]
role_arn = assume_role_w_creds_proc_role_arn
credential_process = echo "{\"Version\": 1, \"AccessKeyId\": \"accesskey\", \"SecretAccessKey\": \"secretkey\"}"
Copy link
Contributor

Choose a reason for hiding this comment

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

will want to test this against windows to ensure tests work.

@jasdel jasdel added the pr/work-in-progress This PR is a draft and needs further work. label Jul 2, 2019
@skotambkar skotambkar requested a review from jasdel July 8, 2019 19:39
@jasdel jasdel added needs-review This issue or pull request needs review from a core team member. and removed pr/work-in-progress This PR is a draft and needs further work. labels Jul 9, 2019
Copy link
Contributor

@jasdel jasdel left a comment

Choose a reason for hiding this comment

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

Looks good, minor suggestions with how the environments are stashed between tests.

os.Clearenv()

restoreEnvFn := sdktesting.StashEnv()
restoreEnvFn()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is missing the defer

os.Clearenv()

restoreEnvFn := sdktesting.StashEnv()
restoreEnvFn()
Copy link
Contributor

Choose a reason for hiding this comment

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

missing defer

@@ -69,7 +69,9 @@ func (m *mockCredsProvider) IsExpired() bool {
}

func TestAfterRetryRefreshCreds(t *testing.T) {
os.Clearenv()
restoreEnvFn := sdktesting.StashEnv()
restoreEnvFn()
Copy link
Contributor

Choose a reason for hiding this comment

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

missing defer

@@ -29,7 +31,8 @@ func TestEnvProviderRetrieve(t *testing.T) {
}

func TestEnvProviderIsExpired(t *testing.T) {
os.Clearenv()
sdktesting.StashEnv()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these stashes also restore the env after the test runs?

"github.com/aws/aws-sdk-go/internal/shareddefaults"
)

func TestSharedCredentialsProvider(t *testing.T) {
os.Clearenv()

sdktesting.StashEnv()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these restore the stashed env after the test runs?

if netErr, ok := err.(*net.OpError); ok && netErr.Op == "dial" {
return true
}
// If the error is temporary, we want to allow continuation of the
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, minor spacing/gofmt here

}

awsError := awserr.New("ErrorTestShouldRetry", "Test should retry when error received", &urlError)
origError := awsError.OrigErr()
Copy link
Contributor

Choose a reason for hiding this comment

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

is awsError needed in this test?

@@ -1101,6 +1101,11 @@ func TestRequestNoConnection(t *testing.T) {
t.Fatal("expect error, but got none")
}

t.Log(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, would be good to include prefix for this log statement.

@@ -76,8 +77,7 @@ func TestLoadEnvConfig_Creds(t *testing.T) {
}

for _, c := range cases {
os.Clearenv()

sdktesting.StashEnv()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these restore the env after test is done?

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest adding, t.Run for this test with // +build go1.7

Copy link
Contributor

@jasdel jasdel left a comment

Choose a reason for hiding this comment

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

Looks good, minor issue with the t.Run in test case.

for k, v := range c.Env {
os.Setenv(k, v)
}
t.Run("", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

the first param of t.Run in this case should be the case index number. e.g.

for i, c := range cases {
    t.Run(strconv.Itoa(i), func(t *testing.T) {

...

Copy link
Contributor

Choose a reason for hiding this comment

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

Or change the cases from a slice to map, and provide name for each test case.

@jasdel jasdel changed the title Assume role for credential process from aws profile aws/session: Add Assume role for credential process from aws profile Jul 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-review This issue or pull request needs review from a core team member.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants