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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6fe148c
Added support for Credential Process to assume role for AWS-SDK-GO
Jun 28, 2019
9db3f0a
Added support for Credential Process to assume role for AWS-SDK-GO
Jun 28, 2019
4020e0d
Merge branch 'GoSDK-543' of github.com:skotambkar/aws-sdk-go into GoS…
Jun 28, 2019
f3b7a90
Modified config file to unable support for Windows as well as Linux.
Jun 28, 2019
d659cb3
code cleanup
Jun 28, 2019
f1658b4
Eliminated redundant code from credential process tests, formatting c…
Jul 1, 2019
0def7bf
Updated travis to support make for windows
Jul 1, 2019
8a9d14d
Updated travis configuration file to support unit test on Windows wit…
Jul 1, 2019
7a1f20e
Fixed syntax error in Travis config file
Jul 1, 2019
cb77c1e
resolved dependency issue for travis configuration
Jul 1, 2019
2ec081f
Updated environment stashing logic to preserve SYSTEMROOT settings fo…
Jul 1, 2019
44f511f
Added system root in environments to keep when stashing
Jul 2, 2019
0759f56
changes in stashing systemroot for windows
Jul 2, 2019
d9cb70f
removed additional print statements
Jul 2, 2019
b8555c4
Refactored code with sdktesting with platform specific config environ…
Jul 2, 2019
8150197
Fixed minor bugs for tests and config files
Jul 3, 2019
a0e6b4c
Fix for TestNoConnection retry bug on Windows OS
Jul 3, 2019
4e8dc55
Code cleanup, added unit test for request connection retry, custom ca…
Jul 3, 2019
f313908
Updated readme file for awstesting
Jul 3, 2019
a6e326a
Updated request retry test
Jul 3, 2019
3ea246b
updated test log for supporting Go version 1.5
Jul 3, 2019
2c88c3f
Fixed TestShouldRetry to solve nil pointer dereference issue with *ur…
Jul 3, 2019
a7dc165
code cleanup
Jul 8, 2019
3c5b464
Added suggested changes
Jul 9, 2019
26d07ad
Added suggested changes
Jul 9, 2019
2239254
Added case index number in t.Run() for env_config_test
Jul 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactored code with sdktesting with platform specific config environ…
…ment
  • Loading branch information
Kotambkar committed Jul 2, 2019
commit b8555c445fb39320579d3ed76e01d140bd41f71f
17 changes: 11 additions & 6 deletions aws/corehandlers/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package corehandlers_test
import (
"bytes"
"fmt"
"github.com/aws/aws-sdk-go/internal/sdktesting"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
"time"
Expand All @@ -22,8 +22,9 @@ import (
)

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

// 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

svc := awstesting.NewClient(aws.NewConfig().WithRegion("us-west-2"))
svc.Handlers.Clear()
svc.Handlers.Validate.PushBackNamed(corehandlers.ValidateEndpointHandler)
Expand All @@ -37,8 +38,9 @@ func TestValidateEndpointHandler(t *testing.T) {
}

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

// 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

svc := awstesting.NewClient()
svc.Handlers.Clear()
svc.Handlers.Validate.PushBackNamed(corehandlers.ValidateEndpointHandler)
Expand Down Expand Up @@ -69,7 +71,10 @@ func (m *mockCredsProvider) IsExpired() bool {
}

func TestAfterRetryRefreshCreds(t *testing.T) {
os.Clearenv()
// 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


credProvider := &mockCredsProvider{}

svc := awstesting.NewClient(&aws.Config{
Expand Down
5 changes: 4 additions & 1 deletion aws/corehandlers/user_agent_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package corehandlers

import (
"github.com/aws/aws-sdk-go/internal/sdktesting"
"net/http"
"os"
"testing"
Expand All @@ -19,7 +20,9 @@ func TestAddHostExecEnvUserAgentHander(t *testing.T) {
}

for i, c := range cases {
os.Clearenv()
// os.Clearenv()
restoreEnvFn := sdktesting.StashEnv()
restoreEnvFn()
os.Setenv(execEnvVar, c.ExecEnv)

req := &request.Request{
Expand Down
21 changes: 16 additions & 5 deletions aws/credentials/env_provider_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package credentials

import (
"github.com/aws/aws-sdk-go/internal/sdktesting"
"os"
"testing"
)

func TestEnvProviderRetrieve(t *testing.T) {
os.Clearenv()
//os.Clearenv()
restoreEnvFn := sdktesting.StashEnv()
restoreEnvFn()
os.Setenv("AWS_ACCESS_KEY_ID", "access")
os.Setenv("AWS_SECRET_ACCESS_KEY", "secret")
os.Setenv("AWS_SESSION_TOKEN", "token")
Expand All @@ -29,7 +32,9 @@ func TestEnvProviderRetrieve(t *testing.T) {
}

func TestEnvProviderIsExpired(t *testing.T) {
os.Clearenv()
//os.Clearenv()
restoreEnvFn := sdktesting.StashEnv()
restoreEnvFn()
os.Setenv("AWS_ACCESS_KEY_ID", "access")
os.Setenv("AWS_SECRET_ACCESS_KEY", "secret")
os.Setenv("AWS_SESSION_TOKEN", "token")
Expand All @@ -51,7 +56,9 @@ func TestEnvProviderIsExpired(t *testing.T) {
}

func TestEnvProviderNoAccessKeyID(t *testing.T) {
os.Clearenv()
// os.Clearenv()
restoreEnvFn := sdktesting.StashEnv()
restoreEnvFn()
os.Setenv("AWS_SECRET_ACCESS_KEY", "secret")

e := EnvProvider{}
Expand All @@ -62,7 +69,9 @@ func TestEnvProviderNoAccessKeyID(t *testing.T) {
}

func TestEnvProviderNoSecretAccessKey(t *testing.T) {
os.Clearenv()
// os.Clearenv()
restoreEnvFn := sdktesting.StashEnv()
restoreEnvFn()
os.Setenv("AWS_ACCESS_KEY_ID", "access")

e := EnvProvider{}
Expand All @@ -73,7 +82,9 @@ func TestEnvProviderNoSecretAccessKey(t *testing.T) {
}

func TestEnvProviderAlternateNames(t *testing.T) {
os.Clearenv()
// os.Clearenv()
restoreEnvFn := sdktesting.StashEnv()
restoreEnvFn()
os.Setenv("AWS_ACCESS_KEY", "access")
os.Setenv("AWS_SECRET_KEY", "secret")

Expand Down
88 changes: 35 additions & 53 deletions aws/credentials/processcreds/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package processcreds_test
import (
"encoding/json"
"fmt"
"github.com/aws/aws-sdk-go/internal/sdktesting"
"io/ioutil"
"os"
"os/exec"
Expand All @@ -15,12 +16,11 @@ import (
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials/processcreds"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/awstesting"
)

func TestProcessProviderFromSessionCfg(t *testing.T) {
oldEnv := preserveImportantStashEnv()
defer awstesting.PopEnv(oldEnv)
restoreEnvFn := sdktesting.StashEnv()
defer restoreEnvFn()

os.Setenv("AWS_SDK_LOAD_CONFIG", "1")
if runtime.GOOS == "windows" {
Expand Down Expand Up @@ -57,8 +57,8 @@ func TestProcessProviderFromSessionCfg(t *testing.T) {
}

func TestProcessProviderFromSessionWithProfileCfg(t *testing.T) {
oldEnv := preserveImportantStashEnv()
defer awstesting.PopEnv(oldEnv)
restoreEnvFn := sdktesting.StashEnv()
defer restoreEnvFn()

os.Setenv("AWS_SDK_LOAD_CONFIG", "1")
os.Setenv("AWS_PROFILE", "non_expire")
Expand Down Expand Up @@ -88,8 +88,8 @@ func TestProcessProviderFromSessionWithProfileCfg(t *testing.T) {
}

func TestProcessProviderNotFromCredProcCfg(t *testing.T) {
oldEnv := preserveImportantStashEnv()
defer awstesting.PopEnv(oldEnv)
restoreEnvFn := sdktesting.StashEnv()
defer restoreEnvFn()

os.Setenv("AWS_SDK_LOAD_CONFIG", "1")
os.Setenv("AWS_PROFILE", "not_alone")
Expand Down Expand Up @@ -123,8 +123,8 @@ func TestProcessProviderNotFromCredProcCfg(t *testing.T) {
}

func TestProcessProviderFromSessionCrd(t *testing.T) {
oldEnv := preserveImportantStashEnv()
defer awstesting.PopEnv(oldEnv)
restoreEnvFn := sdktesting.StashEnv()
defer restoreEnvFn()

if runtime.GOOS == "windows" {
os.Setenv("AWS_SHARED_CREDENTIALS_FILE", "testdata\\shcred_win.ini")
Expand Down Expand Up @@ -160,8 +160,8 @@ func TestProcessProviderFromSessionCrd(t *testing.T) {
}

func TestProcessProviderFromSessionWithProfileCrd(t *testing.T) {
oldEnv := preserveImportantStashEnv()
defer awstesting.PopEnv(oldEnv)
restoreEnvFn := sdktesting.StashEnv()
defer restoreEnvFn()

os.Setenv("AWS_PROFILE", "non_expire")
if runtime.GOOS == "windows" {
Expand Down Expand Up @@ -190,8 +190,8 @@ func TestProcessProviderFromSessionWithProfileCrd(t *testing.T) {
}

func TestProcessProviderNotFromCredProcCrd(t *testing.T) {
oldEnv := preserveImportantStashEnv()
defer awstesting.PopEnv(oldEnv)
restoreEnvFn := sdktesting.StashEnv()
defer restoreEnvFn()

os.Setenv("AWS_PROFILE", "not_alone")
if runtime.GOOS == "windows" {
Expand Down Expand Up @@ -224,8 +224,8 @@ func TestProcessProviderNotFromCredProcCrd(t *testing.T) {
}

func TestProcessProviderBadCommand(t *testing.T) {
oldEnv := preserveImportantStashEnv()
defer awstesting.PopEnv(oldEnv)
restoreEnvFn := sdktesting.StashEnv()
defer restoreEnvFn()

creds := processcreds.NewCredentials("/bad/process")
_, err := creds.Get()
Expand All @@ -235,8 +235,8 @@ func TestProcessProviderBadCommand(t *testing.T) {
}

func TestProcessProviderMoreEmptyCommands(t *testing.T) {
oldEnv := preserveImportantStashEnv()
defer awstesting.PopEnv(oldEnv)
restoreEnvFn := sdktesting.StashEnv()
defer restoreEnvFn()

creds := processcreds.NewCredentials("")
_, err := creds.Get()
Expand All @@ -247,8 +247,8 @@ func TestProcessProviderMoreEmptyCommands(t *testing.T) {
}

func TestProcessProviderExpectErrors(t *testing.T) {
oldEnv := preserveImportantStashEnv()
defer awstesting.PopEnv(oldEnv)
restoreEnvFn := sdktesting.StashEnv()
defer restoreEnvFn()

creds := processcreds.NewCredentials(
fmt.Sprintf(
Expand Down Expand Up @@ -300,8 +300,8 @@ func TestProcessProviderExpectErrors(t *testing.T) {
}

func TestProcessProviderTimeout(t *testing.T) {
oldEnv := preserveImportantStashEnv()
defer awstesting.PopEnv(oldEnv)
restoreEnvFn := sdktesting.StashEnv()
defer restoreEnvFn()

command := "/bin/sleep 2"
if runtime.GOOS == "windows" {
Expand All @@ -319,8 +319,8 @@ func TestProcessProviderTimeout(t *testing.T) {
}

func TestProcessProviderWithLongSessionToken(t *testing.T) {
oldEnv := preserveImportantStashEnv()
defer awstesting.PopEnv(oldEnv)
restoreEnvFn := sdktesting.StashEnv()
defer restoreEnvFn()

creds := processcreds.NewCredentials(
fmt.Sprintf(
Expand Down Expand Up @@ -349,8 +349,8 @@ type credentialTest struct {
}

func TestProcessProviderStatic(t *testing.T) {
oldEnv := preserveImportantStashEnv()
defer awstesting.PopEnv(oldEnv)
restoreEnvFn := sdktesting.StashEnv()
defer restoreEnvFn()

// static
creds := processcreds.NewCredentials(
Expand All @@ -371,8 +371,8 @@ func TestProcessProviderStatic(t *testing.T) {
}

func TestProcessProviderNotExpired(t *testing.T) {
oldEnv := preserveImportantStashEnv()
defer awstesting.PopEnv(oldEnv)
restoreEnvFn := sdktesting.StashEnv()
defer restoreEnvFn()

// non-static, not expired
exp := &credentialTest{}
Expand Down Expand Up @@ -408,8 +408,8 @@ func TestProcessProviderNotExpired(t *testing.T) {
}

func TestProcessProviderExpired(t *testing.T) {
oldEnv := preserveImportantStashEnv()
defer awstesting.PopEnv(oldEnv)
restoreEnvFn := sdktesting.StashEnv()
defer restoreEnvFn()

// non-static, expired
exp := &credentialTest{}
Expand Down Expand Up @@ -445,8 +445,8 @@ func TestProcessProviderExpired(t *testing.T) {
}

func TestProcessProviderForceExpire(t *testing.T) {
oldEnv := preserveImportantStashEnv()
defer awstesting.PopEnv(oldEnv)
restoreEnvFn := sdktesting.StashEnv()
defer restoreEnvFn()

// non-static, not expired

Expand Down Expand Up @@ -499,8 +499,8 @@ func TestProcessProviderForceExpire(t *testing.T) {
}

func TestProcessProviderAltConstruct(t *testing.T) {
oldEnv := preserveImportantStashEnv()
defer awstesting.PopEnv(oldEnv)
restoreEnvFn := sdktesting.StashEnv()
defer restoreEnvFn()

// constructing with exec.Cmd instead of string
myCommand := exec.Command(
Expand All @@ -523,8 +523,8 @@ func TestProcessProviderAltConstruct(t *testing.T) {
}

func BenchmarkProcessProvider(b *testing.B) {
oldEnv := preserveImportantStashEnv()
defer awstesting.PopEnv(oldEnv)
restoreEnvFn := sdktesting.StashEnv()
defer restoreEnvFn()

creds := processcreds.NewCredentials(
fmt.Sprintf(
Expand All @@ -547,24 +547,6 @@ func BenchmarkProcessProvider(b *testing.B) {
}
}

func preserveImportantStashEnv() []string {
envsToKeep := []string{"PATH"}
if runtime.GOOS == "windows" {
envsToKeep = append(envsToKeep, "ComSpec")
envsToKeep = append(envsToKeep, "SYSTEM32")
}
return awstesting.StashEnv(envsToKeep...)
}

func getEnvs(envs []string) map[string]string {
extraEnvs := make(map[string]string)
for _, env := range envs {
if val, ok := os.LookupEnv(env); ok && len(val) > 0 {
extraEnvs[env] = val
}
}
return extraEnvs
}

func getOSCat() string {
if runtime.GOOS == "windows" {
Expand Down
Loading