Skip to content

Commit

Permalink
Merge pull request #19 from jaxxstorm/enhance_session_support
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxxstorm authored Dec 15, 2022
2 parents 94c7a8b + bb5ed00 commit 3a10d7e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ linters:
- deadcode
- errcheck
- goconst
- gofmt
- golint
- gosec
- govet
Expand Down
54 changes: 40 additions & 14 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,54 @@ func GetSSOConfig(profile string, homedir string) (*SSOConfig, error) {

// FIXME: make this better
if p.HasSection(section) {
ssoStartURL, err := p.Get(section, "sso_start_url")
if err != nil {
return nil, fmt.Errorf("no SSO url in profile: %s", profile)
}
ssoRegion, err := p.Get(section, "sso_region")
if err != nil {
return nil, fmt.Errorf("no SSO region in profile: %s", profile)
var startURL string
var region string
var roleName string

// check if we have an sso_session section
// if we do, retrieve the vars from that
// if not, retrieve it from the profile
ssoSession, err := p.Get(section, "sso_session")
if err == nil {
ssoSection := fmt.Sprintf("sso-session %s", ssoSession)

startURL, err = p.Get(ssoSection, "sso_start_url")
if err != nil {
return nil, fmt.Errorf("no SSO url in sso-session: %s", ssoSection)
}
region, err = p.Get(ssoSection, "sso_region")
if err != nil {
return nil, fmt.Errorf("no SSO region in sso-session: %s", ssoSection)
}
roleName, err = p.Get(ssoSection, "sso_role_name")
if err != nil {
return nil, fmt.Errorf("no SSO role name in sso-session: %s", ssoSection)
}
} else {
startURL, err = p.Get(section, "sso_start_url")
if err != nil {
return nil, fmt.Errorf("no SSO url in profile: %s", profile)
}
region, err = p.Get(section, "sso_region")
if err != nil {
return nil, fmt.Errorf("no SSO region in profile: %s", profile)
}
roleName, err = p.Get(section, "sso_role_name")
if err != nil {
return nil, fmt.Errorf("no SSO role name in profile: %s", profile)
}
}
// account id is always going to exist within the profile
ssoAccountID, err := p.Get(section, "sso_account_id")
if err != nil {
return nil, fmt.Errorf("no SSO account id in profile: %s", profile)
}
ssoRoleName, err := p.Get(section, "sso_role_name")
if err != nil {
return nil, fmt.Errorf("no SSO role name in profile: %s", profile)
}

return &SSOConfig{
StartURL: ssoStartURL,
Region: ssoRegion,
StartURL: startURL,
Region: region,
AccountID: ssoAccountID,
RoleName: ssoRoleName,
RoleName: roleName,
}, nil

}
Expand Down

0 comments on commit 3a10d7e

Please sign in to comment.