Skip to content
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

feat: enable pre-emptive async oauth token refreshes #646

Merged
merged 21 commits into from May 20, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0e7326c
feat: add pre-emptive async oauth token refreshes
igorbernstein2 Apr 29, 2021
76f5c54
minor doc
igorbernstein2 Apr 29, 2021
30e3587
update broken test
igorbernstein2 Apr 30, 2021
1be67a5
prep for merging with master: The initial async refresh feature was i…
igorbernstein2 May 3, 2021
c4e8955
merge with origin/master
igorbernstein2 May 3, 2021
8687928
in blocking mode, when a token is stale, only block the first caller …
igorbernstein2 May 3, 2021
383f65a
use private monitor to minimize change noise
igorbernstein2 May 3, 2021
fa101b2
minor tweaks and test
igorbernstein2 May 3, 2021
706ec19
format
igorbernstein2 May 3, 2021
bad38dd
fix ExternalAccountCredentials
igorbernstein2 May 3, 2021
6ce036c
fix boundary checks and add a few more tests
igorbernstein2 May 4, 2021
617d50c
Merge branch 'master' into async-refresh
igorbernstein2 May 4, 2021
909b9e4
add another test for making sure that blocking stacktraces include th…
igorbernstein2 May 4, 2021
b7b585b
address feedback
igorbernstein2 May 4, 2021
14f21e3
optimize for the common case
igorbernstein2 May 5, 2021
f337392
Merge branch 'master' into async-refresh
igorbernstein2 May 5, 2021
a1c53f0
Merge branch 'master' into async-refresh
igorbernstein2 May 10, 2021
a17186e
codestyle
igorbernstein2 May 12, 2021
a69c2b0
use Date to calculate cache state to fix tests that mock access token
igorbernstein2 May 13, 2021
b3d5605
remove accidental double call
igorbernstein2 May 13, 2021
a5a5a47
Merge branch 'master' into async-refresh
lesv May 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -35,6 +35,7 @@

import com.google.api.client.json.GenericJson;
import com.google.api.client.json.JsonObjectParser;
import com.google.auth.RequestMetadataCallback;
import com.google.auth.http.HttpTransportFactory;
import com.google.auth.oauth2.AwsCredentials.AwsCredentialSource;
import com.google.auth.oauth2.IdentityPoolCredentials.IdentityPoolCredentialSource;
Expand All @@ -48,6 +49,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
import javax.annotation.Nullable;

/**
Expand Down Expand Up @@ -208,6 +210,27 @@ private ImpersonatedCredentials initializeImpersonatedCredentials() {
.build();
}

@Override
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to reviewer: before this PR, the blocking version getRequestMetadata() was the primary codepath, so ExternalAccountCredentials only had to override that method. This subclass expected that the async version would just call the sync version. Which I think is a poor assumption since its an implementation detail. I corrected the behavior by overriding both.

Arguably a better approach is to make both getRequestMetadata final and have subclasses use asyncFetch() as the source of truth, but I didn't want to leak guava to the surface of this library

public void getRequestMetadata(
URI uri, Executor executor, final RequestMetadataCallback callback) {
super.getRequestMetadata(
uri,
executor,
new RequestMetadataCallback() {
@Override
public void onSuccess(Map<String, List<String>> metadata) {
metadata = addQuotaProjectIdToRequestMetadata(quotaProjectId, metadata);
igorbernstein2 marked this conversation as resolved.
Show resolved Hide resolved
callback.onSuccess(metadata);
}

@Override
public void onFailure(Throwable exception) {
callback.onFailure(exception);
}
});
super.getRequestMetadata(uri, executor, callback);
}

@Override
public Map<String, List<String>> getRequestMetadata(URI uri) throws IOException {
Map<String, List<String>> requestMetadata = super.getRequestMetadata(uri);
Expand Down