amzn / smoke-aws-credentials

A library to obtain and assume automatically rotating AWS IAM roles written in the Swift programming language.
Apache License 2.0
19 stars 14 forks source link

Use structured concurrency to background refresh credentials #35

Closed tachyonics closed 1 year ago

tachyonics commented 1 year ago

Issue #, if available:

Description of changes:

  1. Migrate to using Swift concurrency tasks to manage credential refreshes. This is handled by the new AwsRotatingCredentialsProviderV2 type, replacing AwsRotatingCredentialsProvider which is retained as it is public
  2. use NSLock rather than a raw mutex. Ensure there is sufficient locking around retrieving and updating credentials
  3. Add new async versions of the public APIs, deprecating the existing versions. The only difference between the now deprecated versions and the new APIs is that the initial credential retrieval will now be done async - in both cases the subsequent background refreshes will use the Swift-concurrency tasks.
  4. Clean-up AwsContainerRotatingCredentialsProvider+get.swift to allow for testing of the code without having to duplicate all functions between async and non-async versions. The exact AwsRotatingCredentialsProviderV2 initializer that is used is the only difference between the async and non-async versions so this is handled within the initial public functions.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.