-
Notifications
You must be signed in to change notification settings - Fork 914
ProfileTokenProvider Reload ProfileFile #3608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ProfileTokenProvider Reload ProfileFile #3608
Conversation
495181a
to
9db71b4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We lose the immutable nature of the class, which is not the end of the world if it is required, but I was wondering if there was a way to make this change while keeping the immutable nature if this class.
core/auth/src/main/java/software/amazon/awssdk/auth/token/credentials/ProfileTokenProvider.java
Show resolved
Hide resolved
} | ||
|
||
private void handleProfileFileReload(ProfileFile profileFile) { | ||
tokenProvider = createTokenProvider(profileFile, profileName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be synchronized?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zoewangg? If needed, will have to make same change to ProfileCredentialsProvider
.
|
||
ProfileFile cachedOrRefreshedProfileFile = refreshProfileFile(); | ||
if (isNewProfileFile(cachedOrRefreshedProfileFile)) { | ||
currentProfileFile = cachedOrRefreshedProfileFile; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be synchronized?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zoewangg? If needed, will have to make same change to ProfileCredentialsProvider
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, could (update: resolveToken is invoked per request)resolveToken()
be invoked by different threads at the same time? I'd assume no.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, not sure what the exact use case is. I'd assume a main thread would be resolving?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took another look and I think we should use some locking mechanism. Here is an example of how it could be done: https://github.com/aws/aws-sdk-java-v2/blob/master/utils/src/main/java/software/amazon/awssdk/utils/cache/CachedSupplier.java#L185
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After offline discussion, decided to use CAS
...th/src/test/java/software/amazon/awssdk/auth/token/credentials/ProfileTokenProviderTest.java
Outdated
Show resolved
Hide resolved
|
||
ProfileFile cachedOrRefreshedProfileFile = refreshProfileFile(); | ||
if (isNewProfileFile(cachedOrRefreshedProfileFile)) { | ||
currentProfileFile = cachedOrRefreshedProfileFile; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, could (update: resolveToken is invoked per request)resolveToken()
be invoked by different threads at the same time? I'd assume no.
ceeef19
to
82f045e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
1091e59
to
c594e62
Compare
c594e62
to
deff952
Compare
SonarCloud Quality Gate failed.
|
* ProfileCredentialsProvider can now reload credentials when profile files change (#3487) * ProfileFile can update if disk changed, reload as new instance * ProfileCredentialsProvider reloads credentials if profile file has changes * Created class ProfileFileRefresher * Created ReloadingProfileCredentialsProvider; moved new logic in ProfileFile to ProfileFileRefresher * Fix ReloadingProfileCredentialsBehavior when missing ProfileFile Supplier or Predicate, and dealing with defaults * Consolidated ReloadingProfileCredentialsProvider functionality into ProfileCredentialsProvider * Fix behavior when dealing with defaults * Created ProfileFileSupplier interface; refactored * Misc fixes * Created package-private ProfileFileSupplierBuilder; ProfileFileSupplier now extends Supplier; Fixed Javadoc * Fixed unit tests for default credentials file * Removed ProfileFileSupplier.Builder interface * Code cleanup * ProfileFileSupplier API changes, aggregating (#3558) * Added methods for aggregating ProfileFile objects * Removed redundant logic, changelog entry * Removed redundant methods * Use compare and set to make thread safe * DefaultCredentialsProvider reload profile (#3580) * Misc fixes * Reload credentials by DefaultCredentialsProvider; pass supplier to InstanceProfileCredentialsProvider * Fix code alignment * Update public APIs to Supplier<ProfileFile> instead of ProfileFileSupplier (#3607) * ProfileTokenProvider Reload ProfileFile (#3608) * Updated ProfileTokenProvider * Updated tests, do not explicitly swallow exceptions * ProfileTokenProviderLoader can use Supplier<Profilefile> internally * Simplified ProfileTokenProviderLoader API; implemented synchronized block * Use synchronized block (#3646) * S3 support classes take Supplier<ProfileFile> (#3653) * S3 support classes take Supplier<ProfileFile> * Review comments * Presigners, other Support classes take Supplier<ProfileFile> (#3677) * Presigners, other Support classes take Supplier<ProfileFile> * Split new ProfileFile tests from existing parameterized tests * Improved tests readability * ProfileFile updates to BaseClientBuilderClass, other S3 classes (#3685) * Leverage SdkClientOption and SdkExecutionAttributes; fallback to simp… (#3692) * Leverage SdkClientOption and SdkExecutionAttributes; fallback to simple ProfileFile * Addressed review comments * Updated changelog entry (#3699) * Fixed review comments * Removed unnecessary logic * Deprecated SdkClientOption PROFILE_FILE * Deprecated SdkExecutionAttribute PROFILE_FILE * Updated changelog entry
…8861fe626 Pull request: release <- staging/a7fc70f6-4e18-45a1-9d53-0b18861fe626
Motivation and Context
Update
ProfileTokenProvider
so that the generated token uses the current contents of aProfileFile
if desired. This change mimics what was done with PR 3487.Modifications
Mirrored new behavior of
ProfileCredentialsProvider
.Testing
Added single test case.
Screenshots (if appropriate)
Types of changes
Checklist
mvn install
succeedsscripts/new-change
script and following the instructions. Commit the new file created by the script in.changes/next-release
with your changes.License