fix: quotaProjectId should be applied for cached getRequestMetadata(URI, Executor, RequestMetadataCallback)#509
Conversation
oauth2_http/javatests/com/google/auth/oauth2/UserCredentialsTest.java
Outdated
Show resolved
Hide resolved
oauth2_http/javatests/com/google/auth/oauth2/UserCredentialsTest.java
Outdated
Show resolved
Hide resolved
…d and other headers
Codecov Report
@@ Coverage Diff @@
## master #509 +/- ##
============================================
+ Coverage 79.80% 79.91% +0.11%
- Complexity 409 413 +4
============================================
Files 28 28
Lines 1936 1947 +11
Branches 201 203 +2
============================================
+ Hits 1545 1556 +11
Misses 283 283
Partials 108 108
Continue to review full report at Codecov.
|
getRequestMetadata(URI, Executor, RequestMetadataCallback)
| temporaryAccess = null; | ||
| useAccessToken(Preconditions.checkNotNull(refreshAccessToken(), "new access token")); | ||
| useAccessToken( | ||
| Preconditions.checkNotNull(refreshAccessToken(), "new access token"), |
There was a problem hiding this comment.
This is a very strange and possibly inappropriate use of Preconditions.
There was a problem hiding this comment.
I agree, it's been there for years.
Filed #510 to track.
| /** | ||
| * Provide additional headers to return as request metadata. | ||
| * | ||
| * @return Map of additional headers. |
There was a problem hiding this comment.
nit: "map of additional headers" or just "additional headers" since the map is provided by the type
There was a problem hiding this comment.
Changed to "additional headers"
|
|
||
| private static final long serialVersionUID = 4556936364828217687L; | ||
| private static final long MINIMUM_TOKEN_MILLISECONDS = 60000L * 5L; | ||
| private static final Map<String, List<String>> EMPTY_EXTRA_HEADERS = Collections.emptyMap(); |
There was a problem hiding this comment.
will this be added to by subclasses? I'm not quite following but it looks like it might be; but this is immutable.
There was a problem hiding this comment.
addQuotaProjectIdToRequestMetadata returns a new ImmutableMap so nothing should be added to this (nor do we want anyone to).
| * | ||
| * @return Map of additional headers. | ||
| */ | ||
| protected Map<String, List<String>> getAdditionalHeaders() { |
There was a problem hiding this comment.
nested types (Map of List) suggest there's a missed opportunity for a more semantic class.
There was a problem hiding this comment.
HTTP headers behave as maps of Strings to a list of Strings. We could possible wrap it, but we're not adding any extra behavior. For a general purpose HTTP client, we might do so, but it seem unnecessary here.
Note: getRequestMetadata() does return this same type (but we really can't feasibly change that as everything that depends on google-auth-library expects that return type).
🤖 I have created a release \*beep\* \*boop\* --- ### [0.22.2](https://www.github.com/googleapis/google-auth-library-java/compare/v0.22.1...v0.22.2) (2020-12-11) ### Bug Fixes * quotaProjectId should be applied for cached `getRequestMetadata(URI, Executor, RequestMetadataCallback)` ([#509](https://www.github.com/googleapis/google-auth-library-java/issues/509)) ([0a8412f](https://www.github.com/googleapis/google-auth-library-java/commit/0a8412fcf9de4ac568b9f88618e44087dd31b144)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please).
Refactors the injection of the quota project id (and possibly other future headers) into the entrypoint that caches the request metadata (in OAuth2Credentials).
Fixes #507