fugue / credstash

A little utility for managing credentials in the cloud
Apache License 2.0
2.06k stars 214 forks source link

Alias cached sessions #264

Closed mike-luminal closed 4 years ago

mike-luminal commented 4 years ago

Resolves #255

Currently, get_session caches sessions in a single variable, and the cached session takes priority over explicitly-passed-in parameters. This means that there can only be a single Session each time credstash is imported, which is set the first time get_session is called. All subsequent calls to get_session return that session, regardless of input.

This PR adds aliased caching by aws_access_key_id to get_session. On the first call with any aws_access_key_id, a Session is created and stored in a dictionary. All subsequent calls with that AKID will re-use the cached Session. The existing caching behavior, where a call to get_session returns the last-used Session is maintained using a last_session variable.

Both the cache and last_session can be reset by calling reset_sessions.