Skip to content

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

Merged
merged 4 commits into from
Nov 7, 2022

Conversation

jyemin
Copy link
Collaborator

@jyemin jyemin commented Nov 5, 2022

String accessToken;
Optional<String> cachedValue = cachedAccessToken.getValue();
if (cachedValue.isPresent()) {
accessToken = cachedValue.get();
Copy link
Collaborator Author

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

}
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)));
Copy link
Collaborator Author

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
@jyemin jyemin requested a review from stIncMale November 6, 2022 14:45
Copy link
Contributor

@DmitryLukyanov DmitryLukyanov left a 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

@jyemin jyemin requested a review from DmitryLukyanov November 7, 2022 15:04
Copy link
Contributor

@DmitryLukyanov DmitryLukyanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jyemin jyemin merged commit b5b395c into mongodb:master Nov 7, 2022
@jyemin jyemin deleted the j4706-2 branch November 7, 2022 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants