-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Cache Azure credential obtained from environment #1038
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
Conversation
String accessToken; | ||
Optional<String> cachedValue = cachedAccessToken.getValue(); | ||
if (cachedValue.isPresent()) { | ||
accessToken = cachedValue.get(); |
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.
This is the only untested line
driver-core/src/main/com/mongodb/internal/authentication/AzureCredentialHelper.java
Show resolved
Hide resolved
} | ||
accessToken = responseDocument.getString(ACCESS_TOKEN_FIELD).getValue(); | ||
int expiresInSeconds = Integer.parseInt(responseDocument.getString(EXPIRES_IN_FIELD).getValue()); | ||
cachedAccessToken = ExpirableValue.unexpired(accessToken, Duration.ofSeconds(expiresInSeconds).minus(Duration.ofMinutes(1))); |
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.
Create the new cached access token with the expiration as the duration from the HTTP response minus one minute
… Duration is <=0 Added another not-null assertion Added a few more tests
driver-core/src/main/com/mongodb/internal/authentication/AzureCredentialHelper.java
Outdated
Show resolved
Hide resolved
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.
See minor comment about how calculate expired date. Then it will be LGTM
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
JAVA-4706