Skip to content

Commit 385904d

Browse files
author
Barry Lagerweij
committed
Fixed ISO8601 format issue; Updated doucmentation and Makefile
1 parent 63351ee commit 385904d

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,24 @@ build:
33

44
run:
55
./dist/aws-sso-fetcher_darwin_amd64/aws-sso-fetcher hpydev_dev
6+
7+
VERSION := $(shell cat ./VERSION)
8+
9+
all: install
10+
11+
12+
install:
13+
go install -v
14+
15+
test:
16+
go test ./... -v
17+
18+
fmt:
19+
go fmt ./... -v
20+
21+
release:
22+
git tag -a $(VERSION) -m "Release" || true
23+
git push origin $(VERSION)
24+
goreleaser --rm-dist
25+
26+
.PHONY: install test fmt release

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ sso_account_id = 0123456789
2020
sso_role_name = AWSAdministratorAccess
2121
region = us-east-2
2222
output = json
23+
```
2324

25+
And in your `~/.aws/credentials`, you'll need something like this:
26+
```ini
2427
[profile wrap_acme_dev]
2528
credential_process = /Users/alice/bin/aws-sso-fetcher acme_dev
2629
region = us-west-1
@@ -31,8 +34,7 @@ output = json
3134
Once you get SSO credentials with:
3235

3336
```bash
34-
export AWS_PROFILE=acme_dev
35-
aws sso login
37+
aws sso login --profile=acme_dev
3638
```
3739

3840
You can then start using software with the other wrapper profile:

main.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type CredentialProcessJson struct {
3232
AccessKeyID string `json:"AccessKeyId"`
3333
SecretAccessKey string `json:"SecretAccessKey"`
3434
SessionToken string `json:"SessionToken"`
35-
Expiration time.Time `json:"Expiration"`
35+
Expiration AWSTime `json:"Expiration"`
3636
}
3737

3838
type Profile struct {
@@ -46,16 +46,20 @@ type AWSTime struct {
4646
time.Time
4747
}
4848

49-
func (t *AWSTime) UnmarshalJSON(buf []byte) error {
50-
51-
tt, err := time.Parse(time.RFC3339, strings.Trim(strings.Replace(string(buf), "UTC", "Z", 1), `"`))
52-
if err != nil {
53-
return err
49+
func (it *AWSTime) UnmarshalJSON(data []byte) error {
50+
t, err := time.Parse("2006-01-02T15:04:05Z07:00", strings.Trim(strings.Replace(string(data), "UTC", "Z", 1), `"`))
51+
if err == nil {
52+
*it = AWSTime{t}
5453
}
55-
t.Time = tt
56-
return nil
54+
55+
return err
56+
}
57+
58+
func (it AWSTime) MarshalJSON() ([]byte, error) {
59+
return []byte(fmt.Sprintf("\"%sZ\"", it.Time.UTC().Format("2006-01-02T15:04:05"))), nil
5760
}
5861

62+
5963
func main(){
6064
zerolog.SetGlobalLevel(zerolog.InfoLevel)
6165
_, ok := os.LookupEnv("DEBUG")
@@ -152,7 +156,7 @@ func getCachedFile(awsSsoCachePath, awsSSOProfileName string) (*CredentialProces
152156
if err != nil {
153157
return nil, err
154158
}
155-
if time.Now().After(credentialProcessJson.Expiration) {
159+
if time.Now().After(credentialProcessJson.Expiration.Time) {
156160
log.Debug().Str("expire", credentialProcessJson.Expiration.String()).Msg("credentials expired")
157161
return nil, nil
158162
}
@@ -197,7 +201,7 @@ func getSsoRoleCredentials(profile Profile, awsSSOCredential AWSSSOCredential) (
197201
AccessKeyID: *resp.RoleCredentials.AccessKeyId,
198202
SecretAccessKey: *resp.RoleCredentials.SecretAccessKey,
199203
SessionToken: *resp.RoleCredentials.SessionToken,
200-
Expiration: aws.MillisecondsTimeValue(resp.RoleCredentials.Expiration),
204+
Expiration: AWSTime{aws.MillisecondsTimeValue(resp.RoleCredentials.Expiration)},
201205
}, nil
202206
}
203207

0 commit comments

Comments
 (0)