-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added profile override functionality
- Loading branch information
Showing
88 changed files
with
2,869 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package awsconfig | ||
|
||
import ( | ||
"log" | ||
"os" | ||
|
||
"github.com/aws/aws-sdk-go-v2/config" | ||
"gopkg.in/ini.v1" | ||
) | ||
|
||
type Profile struct { | ||
Name string | ||
Region string | ||
} | ||
|
||
var awsProfiles []Profile | ||
|
||
func GetAwsProfiles() []Profile { | ||
if awsProfiles == nil || len(awsProfiles) <= 0 { | ||
loadAwsProfiles() | ||
} | ||
return awsProfiles | ||
} | ||
|
||
func loadAwsProfiles() { | ||
credentialsIniFile, err := ini.Load(GetAwsCredentialsFilePath()) | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
configIniFile, err := ini.Load(GetAwsProfileFilePath()) | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
|
||
awsProfiles = nil | ||
if credentialsIniFile != nil { | ||
for _, section := range credentialsIniFile.Sections() { | ||
if section.Name() == ini.DefaultSection { | ||
// AWS does not specify anything useful in the root section | ||
continue | ||
} | ||
profile := Profile{ | ||
Name: section.Name(), | ||
} | ||
|
||
if configIniFile != nil { | ||
var sectionName string | ||
if profile.Name == "default" { | ||
sectionName = profile.Name | ||
} else { | ||
// all other non-"default" profiles have special prefix | ||
sectionName = "profile " + profile.Name | ||
} | ||
configProfileSection, _ := configIniFile.GetSection(sectionName) | ||
if configProfileSection != nil { | ||
regionKey, _ := configProfileSection.GetKey("region") | ||
if regionKey != nil { | ||
profile.Region = regionKey.Value() | ||
} | ||
} | ||
} | ||
awsProfiles = append(awsProfiles, profile) | ||
} | ||
} | ||
} | ||
|
||
func GetAwsCredentialsFilePath() string { | ||
// see https://docs.aws.amazon.com/sdkref/latest/guide/file-location.html | ||
path, _ := os.LookupEnv("AWS_SHARED_CREDENTIALS_FILE") | ||
if path == "" { | ||
path = config.DefaultSharedCredentialsFilename() | ||
} | ||
return path | ||
} | ||
|
||
func GetAwsProfileFilePath() string { | ||
// see https://docs.aws.amazon.com/sdkref/latest/guide/file-location.html | ||
path, _ := os.LookupEnv("AWS_CONFIG_FILE") | ||
if path == "" { | ||
path = config.DefaultSharedConfigFilename() | ||
} | ||
return path | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package awsworkflow | ||
package awsconfig | ||
|
||
type Region struct { | ||
Name string | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(*parsers.Query)({ | ||
RawQuery: (string) (len=1) "@", | ||
Service: (*awsworkflow.AwsService)(<nil>), | ||
SubService: (*awsworkflow.AwsService)(<nil>), | ||
HasTrailingWhitespace: (bool) false, | ||
HasOpenAll: (bool) false, | ||
HasDefaultSearchAlias: (bool) false, | ||
regionOverride: (*awsconfig.Region)(<nil>), | ||
RegionQuery: (*string)(<nil>), | ||
ProfileOverride: (*awsconfig.Profile)(<nil>), | ||
ProfileQuery: (*string)(""), | ||
RemainingQuery: (string) "" | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(*parsers.Query)({ | ||
RawQuery: (string) (len=5) "@prof", | ||
Service: (*awsworkflow.AwsService)(<nil>), | ||
SubService: (*awsworkflow.AwsService)(<nil>), | ||
HasTrailingWhitespace: (bool) false, | ||
HasOpenAll: (bool) false, | ||
HasDefaultSearchAlias: (bool) false, | ||
regionOverride: (*awsconfig.Region)(<nil>), | ||
RegionQuery: (*string)(<nil>), | ||
ProfileOverride: (*awsconfig.Profile)(<nil>), | ||
ProfileQuery: (*string)((len=4) "prof"), | ||
RemainingQuery: (string) "" | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(*parsers.Query)({ | ||
RawQuery: (string) (len=8) "@profile", | ||
Service: (*awsworkflow.AwsService)(<nil>), | ||
SubService: (*awsworkflow.AwsService)(<nil>), | ||
HasTrailingWhitespace: (bool) false, | ||
HasOpenAll: (bool) false, | ||
HasDefaultSearchAlias: (bool) false, | ||
regionOverride: (*awsconfig.Region)(<nil>), | ||
RegionQuery: (*string)(<nil>), | ||
ProfileOverride: (*awsconfig.Profile)(<nil>), | ||
ProfileQuery: (*string)((len=7) "profile"), | ||
RemainingQuery: (string) "" | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.