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

SharedConfigState (work in progress) #86

Merged
merged 4 commits into from
Dec 29, 2020
Merged
Changes from all commits
Commits
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
11 changes: 8 additions & 3 deletions pkg/conn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func getRegionFromECSMetadata() string {
log.Errorf("Unable to open ECS metadata file: %v\n", err)
} else {
if err := json.Unmarshal(metadataFile, &dat); err != nil {
log.Errorf("Unable to read ECS metadatafile contents: %v", err)
log.Errorf("Unable to read ECS metadata file contents: %v", err)
} else {
taskArn = strings.Split(dat["TaskARN"].(string), ":")
region = taskArn[3]
Expand Down Expand Up @@ -156,9 +156,14 @@ func GetAWSConfigSession(cn connAttr, c *cfg.Config, roleArn string, region stri
log.Debugf("Fetch region %v from ec2 metadata", awsRegion)
}
}
} else {
es := getDefaultSession()
awsRegion = *es.Config.Region
log.Debugf("Fetched region %v from session config", awsRegion)

}
if awsRegion == "" {
log.Errorf("Cannot fetch region variable from config file, environment variables, ecs metadata, or ec2 metadata.")
log.Errorf("Cannot fetch region variable from config file, environment variables, ecs metadata, or ec2 metadata. Use local-mode to use the local session region.")
os.Exit(1)
}
s = cn.newAWSSession(roleArn, awsRegion)
Expand Down Expand Up @@ -286,7 +291,7 @@ func getSTSRegionalEndpoint(r string) string {
}

func getDefaultSession() *session.Session {
result, serr := session.NewSession()
result, serr := session.NewSessionWithOptions(session.Options{SharedConfigState: session.SharedConfigEnable})
if serr != nil {
log.Errorf("Error in creating session object : %v\n.", serr)
os.Exit(1)
Expand Down