Skip to content

Commit 8f1fa0d

Browse files
authored
Merge pull request #502 from synfinatic/leading-zero-list
Leading zero list
2 parents 186a3d2 + 3b9db07 commit 8f1fa0d

18 files changed

+258
-129
lines changed

.github/workflows/codeql-analysis.yml

+47-31
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,82 @@
1-
name: codeql-analysis
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
214
on:
315
push:
4-
branches: [main]
16+
branches: [ "main" ]
517
pull_request:
618
# The branches below must be a subset of the branches above
7-
branches: [main]
19+
branches: [ "main" ]
820
schedule:
9-
- cron: '0 20 * * 2'
21+
- cron: '42 17 * * 5'
1022

1123
jobs:
1224
analyze:
1325
name: Analyze
14-
runs-on: ubuntu-latest
26+
# Runner size impacts CodeQL analysis time. To learn more, please see:
27+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
28+
# - https://gh.io/supported-runners-and-hardware-resources
29+
# - https://gh.io/using-larger-runners
30+
# Consider using larger runners for possible analysis time improvements.
31+
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
32+
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
33+
permissions:
34+
actions: read
35+
contents: read
36+
security-events: write
1537

1638
strategy:
1739
fail-fast: false
1840
matrix:
19-
# Override automatic language detection by changing the below list
20-
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
21-
language: ['go']
22-
# Learn more...
23-
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
41+
language: [ 'go' ]
42+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
43+
# Use only 'java' to analyze code written in Java, Kotlin or both
44+
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
45+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
2446

2547
steps:
2648
- name: Checkout repository
27-
uses: actions/checkout@v2
28-
with:
29-
# We must fetch at least the immediate parents so that if this is
30-
# a pull request then we can checkout the head.
31-
fetch-depth: 2
32-
33-
# If this run was triggered by a pull request event, then checkout
34-
# the head of the pull request instead of the merge commit.
35-
# Note: no longer recommended!
36-
# - run: git checkout HEAD^2
37-
# if: ${{ github.event_name == 'pull_request' }}
49+
uses: actions/checkout@v3
3850

3951
# Initializes the CodeQL tools for scanning.
4052
- name: Initialize CodeQL
4153
uses: github/codeql-action/init@v2
4254
with:
4355
languages: ${{ matrix.language }}
4456
# If you wish to specify custom queries, you can do so here or in a config file.
45-
# By default, queries listed here will override any specified in a config file.
57+
# By default, queries listed here will override any specified in a config file.
4658
# Prefix the list here with "+" to use these queries and those in the config file.
47-
# queries: ./path/to/local/query, your-org/your-repo/queries@main
4859

49-
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
60+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
61+
# queries: security-extended,security-and-quality
62+
63+
64+
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
5065
# If this step fails, then you should remove it and run the build manually (see below)
5166
- name: Autobuild
5267
uses: github/codeql-action/autobuild@v2
5368

5469
# ℹ️ Command-line programs to run using the OS shell.
55-
# 📚 https://git.io/JvXDl
70+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
5671

57-
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
58-
# and modify them (or add more) to build your code if your project
59-
# uses a compiled language
72+
# If the Autobuild fails above, remove it and uncomment the following three lines.
73+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
6074

61-
#- run: |
62-
# make bootstrap
63-
# make release
75+
# - run: |
76+
# echo "Run, Build Application using script"
77+
# ./location_of_script_within_repo/buildscript.sh
6478

6579
- name: Perform CodeQL Analysis
6680
uses: github/codeql-action/analyze@v2
81+
with:
82+
category: "/language:${{matrix.language}}"

CHANGELOG.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
# AWS SSO CLI Changelog
22

3-
## Unreleased
3+
## [v1.11.0] - 2023-07-31
44

55
### Bugs
66

77
* Fix `process --profile` flag not working
8+
* Fix `AccountId` still not zero padding in `list` output
89

910
### Changes
1011

1112
* No longer show usage on error
13+
* Add `AccountIdPad` as a new field name for the `list` command to pad with zeros
14+
as appropriate.
15+
* Change default `ProfileFormat` to `{{ .AccountIdPad }}:{{ .RoleName }}`
16+
* `ExpiresStr` field name is now `Expires` to match the header
17+
* `Expires` is now `ExpiresEpoch` as both field name and header
18+
* `ARN` header is now `Arn` to match the field name
19+
20+
### Deprecated
21+
22+
* `AccountIdStr` function for `ProfileFormat`. Use the `.AccountIdPad` variable instead.
23+
* `ExpiresStr` is now deprecated. Use `Expires` instead.
1224

1325
## [v1.10.0] - 2023-07-30
1426

@@ -502,7 +514,8 @@
502514

503515
Initial release
504516

505-
[Unreleased]: https://github.com/synfinatic/aws-sso-cli/compare/v1.10.0...main
517+
[Unreleased]: https://github.com/synfinatic/aws-sso-cli/compare/v1.11.0...main
518+
[v1.11.0]: https://github.com/synfinatic/aws-sso-cli/releases/tag/v1.10.0
506519
[v1.10.0]: https://github.com/synfinatic/aws-sso-cli/releases/tag/v1.9.10
507520
[v1.9.10]: https://github.com/synfinatic/aws-sso-cli/releases/tag/v1.9.9
508521
[v1.9.9]: https://github.com/synfinatic/aws-sso-cli/releases/tag/v1.9.9

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PROJECT_VERSION := 1.10.0
1+
PROJECT_VERSION := 1.11.0
22
DOCKER_REPO := synfinatic
33
PROJECT_NAME := aws-sso
44

cmd/aws-sso/list_cmd.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ type ListCmd struct {
4040
Reverse bool `kong:"help='Reverse sort results',env='AWS_SSO_FIELD_SORT_REVERSE'"`
4141
}
4242

43+
// Actually used in main.go, but definied here for locality
44+
var DEFAULT_LIST_FIELDS []string = []string{"AccountIdPad", "AccountAlias", "RoleName", "Profile", "Expires"}
45+
4346
// what should this actually do?
4447
func (cc *ListCmd) Run(ctx *RunContext) error {
4548
var err error
@@ -118,12 +121,12 @@ func printRoles(ctx *RunContext, fields []string, csv bool, prefixSearch []strin
118121

119122
var sortError error
120123
sort.SliceStable(allRoles, func(i, j int) bool {
121-
a, err := allRoles[i].GetField(sortby)
124+
a, err := allRoles[i].GetSortableField(sortby)
122125
if err != nil {
123126
sortError = fmt.Errorf("Invalid --sort value: %s", sortby)
124127
return false
125128
}
126-
b, _ := allRoles[j].GetField(sortby)
129+
b, _ := allRoles[j].GetSortableField(sortby)
127130

128131
if a.Type == sso.Sval {
129132
if !reverse {
@@ -189,7 +192,7 @@ func printRoles(ctx *RunContext, fields []string, csv bool, prefixSearch []strin
189192
if exp, err := utils.TimeRemain(ctr.ExpiresAt, true); err != nil {
190193
log.Errorf("Unable to determine time remain for %d: %s", ctr.ExpiresAt, err)
191194
} else {
192-
expires = fmt.Sprintf(" [Expires in: %s]", exp)
195+
expires = fmt.Sprintf(" [Expires in: %s]", strings.TrimSpace(exp))
193196
}
194197
}
195198
fmt.Printf("List of AWS roles for SSO Instance: %s%s\n\n", ctx.Settings.DefaultSSO, expires)

cmd/aws-sso/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ var DEFAULT_CONFIG map[string]interface{} = map[string]interface{}{
8282
"DefaultRegion": "us-east-1",
8383
"HistoryLimit": 10,
8484
"HistoryMinutes": 1440, // 24hrs
85-
"ListFields": []string{"AccountId", "AccountAlias", "RoleName", "Profile", "ExpiresStr"},
85+
"ListFields": DEFAULT_LIST_FIELDS,
8686
"ConsoleDuration": 60,
8787
"UrlAction": "open",
8888
"ConfigProfilesUrlAction": "open",
8989
"LogLevel": "warn",
9090
"DefaultSSO": "Default",
9191
"FirefoxOpenUrlInContainer": false,
9292
"AutoConfigCheck": false,
93-
"ProfileFormat": `{{ AccountIdStr .AccountId }}:{{ .RoleName }}`,
93+
"ProfileFormat": sso.DEFAULT_PROFILE_TEMPLATE,
9494
"CacheRefresh": 24, // in hours
9595
"Threads": 5,
9696
}

cmd/aws-sso/setup_cmd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func setupWizard(ctx *RunContext, reconfig, addSSO bool) error {
133133
}
134134

135135
// should we prompt user to override default browser?
136-
if s.UrlAction == url.Open || s.ConfigProfilesUrlAction == url.Open {
136+
if s.UrlAction == url.Open || s.ConfigProfilesUrlAction == url.ConfigProfilesOpen {
137137
s.Browser = promptDefaultBrowser(s.Browser)
138138
}
139139

docs/FAQ.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,15 @@ purposes:
187187
2. Makes it easy to select a role via the `$AWS_PROFILE` environment variable
188188
when you use the [config-profiles](commands.md#config-profiles) command.
189189

190-
By default, `ProfileFormat` is set to `{{ AccountIdStr .AccountId }}:{{ .RoleName }}`
190+
By default, `ProfileFormat` is set to `{{ .AccountIdPad }}:{{ .RoleName }}`
191191
which will generate a value like `02345678901:MyRoleName`.
192192

193193
Some examples:
194194

195195
* `ProfileFormat: '{{ FirstItem .AccountName .AccountAlias }}'` -- If there
196196
is an Account Name set in the config.yaml print that, otherwise print the
197197
Account Alias defined by the AWS administrator.
198-
* `ProfileFormat: '{{ AccountIdStr .AccountId }}'` -- Pad the AccountId with
199-
leading zeros if it is < 12 digits long
198+
* `ProfileFormat: '{{ .AccountIdPad }}'` -- Pad the AccountId with leading zeros if it is < 12 digits long
200199
* `ProfileFormat: '{{ .AccountId }}'` -- Print the AccountId as a regular number
201200
* `ProfileFormat: '{{ StringsJoin ":" .AccountAlias .RoleName }}'` -- Another
202201
way of writing `{{ .AccountAlias }}:{{ .RoleName }}`

docs/commands.md

+15-7
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Flags:
144144
* `--account <account>`, `-A` -- AWS AccountID of role to assume (requires `--role`)
145145
* `--role <role>`, `-R` -- Name of AWS Role to assume (requires `--account`)
146146
* `--profile <profile>`, `-p` -- Name of AWS Profile to assume
147-
* `--no-region` -- Do not set the AWS_DEFAULT_REGION from config.yaml
147+
* `--no-region` -- Do not set the [AWS_DEFAULT_REGION](config.md#DefaultRegion) from config.yaml
148148
* `--refresh` -- Refresh current IAM credentials
149149

150150
Priority is given to:
@@ -191,7 +191,7 @@ Flags:
191191
* `--env`, `-e` -- Use existing ENV vars generated by AWS SSO to generate a URL
192192
* `--role <role>`, `-R` -- Name of AWS Role to assume (`$AWS_SSO_ROLE_NAME`)
193193
* `--profile <profile>`, `-p` -- Name of AWS Profile to assume
194-
* `--no-region` -- Do not set the AWS_DEFAULT_REGION from config.yaml
194+
* `--no-region` -- Do not set the [AWS_DEFAULT_REGION](config.md#DefaultRegion) from config.yaml
195195

196196
Arguments: `[<command>] [<args> ...]`
197197

@@ -257,7 +257,7 @@ which fields are printed by specifying the field names as arguments.
257257
Flags:
258258

259259
* `--list-fields`, `-f` -- List the available fields to print
260-
* `--prefix <FieldName>=<Prefix>`, `-P` -- Filter results by the given field
260+
* `--prefix <FieldName>=<Prefix>`, `-P` -- Filter results by the given field
261261
value & prefix value
262262
* `--csv` -- Generate results in CSV format
263263
* `--sort <FieldName>`, `-s` -- Sort results by the provided field name
@@ -266,16 +266,20 @@ Flags:
266266
Arguments: `[<field> ...]`
267267

268268
The arguments are a list of fields to display in the report. Overrides the
269-
defaults and/or the specified `ListFields` in the `config.yaml`.
269+
defaults and/or the specified [ListFields](config.md#ListFields) in the
270+
`config.yaml`.
270271

271272
Default fields:
272273

273-
* `AccountId`
274+
* `AccountIdPad`
274275
* `AccountAlias`
275276
* `RoleName`
276-
* `ExpiresStr`
277+
* `Expires`
277278

278-
**Note:** Sorting always happens in a case-sensitive and alphabetic manner.
279+
**Note:** Sorting for `AccountIdPad` and `Expires` is done via their respective
280+
`AccountId` and `ExpiresEpoch` integer values. Expired entries are considered
281+
to be very large. All other fields are sorted alphabetically and in a
282+
case-sensitive manner.
279283

280284
---
281285

@@ -291,6 +295,10 @@ Flags:
291295
* `sso` -- Flush temporary AWS SSO credentials
292296
* `all` -- Flush temporary STS and SSO credentials
293297

298+
**Note:** Flushing non-expired SSO credentials will not cause new credentials to be issued
299+
on the next call to the AWS SSO API, but rather the existing credentials will be refreshed
300+
from the browser session.
301+
294302
---
295303

296304
### tags

docs/config.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,12 @@ tooling.
374374
The following variables are accessible from the `AWSRoleFlat` struct:
375375

376376
* `Id` -- Unique integer defined by AWS SSO CLI for this role
377-
* `AccountId` -- AWS Account ID (int64! See `AccountIdStr()` below)
377+
* `AccountId` -- AWS Account ID (int64! not zero padded)
378+
* `AccountIdPad` -- AWS Account ID (zero padded)
378379
* `AccountAlias` -- AWS Account Alias defined in AWS by the account owner
379380
* `AccountName` -- AWS Account Name defined in `~/.aws-sso/config.yaml`
380381
* `EmailAddress` -- Root account email address associated with the account in AWS
382+
* `ExpiresEpoch` -- When your API credentials expire (UNIX epoch)
381383
* `Expires` -- When your API credentials expire (string)
382384
* `Arn` -- AWS ARN for this role
383385
* `RoleName` -- The role name
@@ -388,12 +390,12 @@ The following variables are accessible from the `AWSRoleFlat` struct:
388390
* `Tags` -- Map of additional custom key/value pairs
389391
* `Via` -- Role AWS SSO CLI will assume before assuming this role
390392

391-
By default, `ProfileFormat` is set to `{{ AccountIdStr .AccountId }}:{{ .RoleName }}`.
393+
By default, `ProfileFormat` is set to `{{ .AccountIdPad }}:{{ .RoleName }}`.
392394

393395
AWS SSO CLI uses [sprig](http://masterminds.github.io/sprig/) for most of its
394396
functions, but a few custom functions are available:
395397

396-
* `AccountIdStr(x)` -- Converts an AWS Account ID to a string
398+
* `AccountIdStr(x)` -- Converts the `.AccountId` variable to a string. Deprecated. Use `.AccountIdPad` variable instead.
397399
* `EmptyString(x)` -- Returns true/false if the value `x` is an empty string
398400
* `FirstItem([]x)` -- Returns the first item in a list that is not an empty string
399401
* `StringsJoin(x, []y)` -- Joins the items in `y` with the string `x`
@@ -509,8 +511,8 @@ Specify which fields to display via the `list` command. Valid options are:
509511
* `Arn` -- Role ARN
510512
* `DefaultRegion` -- Configured default region
511513
* `EmailAddress` -- Email address of root account associated with AWS Account
512-
* `Expires` -- Unix epoch time when cached STS creds expire
513-
* `ExpiresStr` -- Hours and minutes until cached STS creds expire
514+
* `ExpiresEpoch` -- Unix epoch time when cached STS creds expire
515+
* `Expires` -- Hours and minutes until cached STS creds expire
514516
* `Profile` -- Value used for `$AWS_SSO_PROFILE` and the profile name in `~/.aws/config`
515517
* `RoleName` -- Role name
516518
* `SSO` -- AWS SSO instance name

internal/predictor/constants.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ package predictor
2222
var AllListFields = map[string]string{
2323
"Id": "Column Index",
2424
"Arn": "AWS Role Resource Name",
25-
"AccountId": "AWS AccountID",
25+
"AccountId": "AWS AccountID (integer)",
26+
"AccountIdPad": "AWS AccountID (zero padded)",
2627
"AccountName": "Configured Account Name",
2728
"AccountAlias": "AWS Account Alias",
2829
"DefaultRegion": "Default AWS Region",

internal/url/url.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ const (
8383
Clip Action = "clip" // copy to clipboard
8484
Print Action = "print" // print message & url to stderr
8585
PrintUrl Action = "printurl" // print only the url to stderr
86-
Exec = "exec" // Exec comand
87-
Open = "open" // auto-open in default or specified browser
88-
GrantedContainer = "granted-containers"
89-
OpenUrlContainer = "open-url-in-container"
86+
Exec Action = "exec" // Exec comand
87+
Open Action = "open" // auto-open in default or specified browser
88+
GrantedContainer Action = "granted-containers"
89+
OpenUrlContainer Action = "open-url-in-container"
9090
)
9191

9292
func (u Action) IsContainer() bool {
@@ -98,10 +98,10 @@ type ConfigProfilesAction string
9898
const (
9999
ConfigProfilesUndef ConfigProfilesAction = "" // undefined
100100
ConfigProfilesClip ConfigProfilesAction = "clip" // copy to clipboard
101-
ConfigProfilesExec = "exec" // Exec comand
102-
ConfigProfilesOpen = "open" // auto-open in default or specified browser
103-
ConfigProfilesGrantedContainer = "granted-containers"
104-
ConfigProfilesOpenUrlContainer = "open-url-in-container"
101+
ConfigProfilesExec ConfigProfilesAction = "exec" // Exec comand
102+
ConfigProfilesOpen ConfigProfilesAction = "open" // auto-open in default or specified browser
103+
ConfigProfilesGrantedContainer ConfigProfilesAction = "granted-containers"
104+
ConfigProfilesOpenUrlContainer ConfigProfilesAction = "open-url-in-container"
105105
)
106106

107107
func (u ConfigProfilesAction) IsContainer() bool {

0 commit comments

Comments
 (0)