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

sort sso profiles by profile name #7

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions awscfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ func Merge(opts MergeOpts) error {
opts.SectionNameTemplate = "{{ .AccountName }}/{{ .RoleName }}"
}

// Sort profiles by CombinedName (AccountName/RoleName)
sort.SliceStable(opts.Profiles, func(i, j int) bool {
profileNameI := opts.Prefix + opts.Profiles[i].RoleName
profileNameJ := opts.Prefix + opts.Profiles[j].RoleName
return profileNameI < profileNameJ
combinedNameI := opts.Profiles[i].AccountName + "/" + opts.Profiles[i].RoleName
combinedNameJ := opts.Profiles[j].AccountName + "/" + opts.Profiles[j].RoleName
return combinedNameI < combinedNameJ
})

funcMap := sprig.TxtFuncMap()
Expand Down
63 changes: 63 additions & 0 deletions awscfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,69 @@ granted_sso_account_id = 123456789012
granted_sso_role_name = DevRole
common_fate_generated_from = aws-sso
credential_process = granted credential-process --profile testing-title-case-with-space/DevRole --url https://commonfate.example.com
`,
},
{
name: "profile names (AccountName/RoleName) sorted alphabetically",
args: MergeOpts{
Config: parseIni(t, ""),
Profiles: []SSOProfile{
{
SSOStartURL: "https://example.awsapps.com/start",
SSORegion: "ap-southeast-2",
AccountID: "123456789012",
AccountName: "account1",
RoleName: "DevRoleTwo",
GeneratedFrom: "aws-sso",
Region: "us-west-2",
},
{
SSOStartURL: "https://example.awsapps.com/start",
SSORegion: "ap-southeast-2",
AccountID: "123456789012",
AccountName: "account1",
RoleName: "DevRoleOne",
GeneratedFrom: "aws-sso",
Region: "us-west-2",
},
{
SSOStartURL: "https://example.awsapps.com/start",
SSORegion: "ap-southeast-2",
AccountID: "123456789012",
AccountName: "account2",
RoleName: "DevRoleOne",
GeneratedFrom: "aws-sso",
Region: "us-west-2",
},
},
},
want: `
[profile account1/DevRoleOne]
granted_sso_start_url = https://example.awsapps.com/start
granted_sso_region = ap-southeast-2
granted_sso_account_id = 123456789012
granted_sso_role_name = DevRoleOne
common_fate_generated_from = aws-sso
credential_process = granted credential-process --profile account1/DevRoleOne
region = us-west-2

[profile account1/DevRoleTwo]
granted_sso_start_url = https://example.awsapps.com/start
granted_sso_region = ap-southeast-2
granted_sso_account_id = 123456789012
granted_sso_role_name = DevRoleTwo
common_fate_generated_from = aws-sso
credential_process = granted credential-process --profile account1/DevRoleTwo
region = us-west-2

[profile account2/DevRoleOne]
granted_sso_start_url = https://example.awsapps.com/start
granted_sso_region = ap-southeast-2
granted_sso_account_id = 123456789012
granted_sso_role_name = DevRoleOne
common_fate_generated_from = aws-sso
credential_process = granted credential-process --profile account2/DevRoleOne
region = us-west-2
`,
},
}
Expand Down
Loading