jaxxstorm / aws-sso-creds

Get AWS SSO temporary creds from an SSO profile
MIT License
187 stars 24 forks source link

Cached SSO credentials files can be looked up without looping #15

Open adamrothman opened 1 year ago

adamrothman commented 1 year ago

The names of the JSON files in ~/.aws/sso/cache seem random but it turns out they're actually just hex-encoded SHA1 digests of your various SSO start URLs. This means it's not necessary to loop over all the files in ~/.aws/sso/cache to find the one we're looking for – we can just go straight to the right one.

Given a start URL https://d-xxxxxxxxxx.awsapps.com/start, we can expect to find its cached SSO credentials file (if it exists) at ~/.aws/sso/cache/5c26431228bc0d538e12104a3cbc37975e46c8f9.json.

$ echo -n "https://d-xxxxxxxxxx.awsapps.com/start" | shasum -a 1 | awk '{print $1}'
5c26431228bc0d538e12104a3cbc37975e46c8f9
jaxxstorm commented 1 year ago

oh wow, TIL. I'll have a look at implementing this.