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

Add HttpClient based implementation of HttpTransportFactory #1015

Merged
merged 15 commits into from
Jan 25, 2024

Conversation

jeremyg484
Copy link
Contributor

@jeremyg484 jeremyg484 commented Jan 12, 2024

An implementation of the GCP SDK API HttpTransportFactory is added that internally uses the default Micronaut
HttpClient. This API is used by the GCP GoogleCredentials for refreshing OAuth tokens for use in API calls. This
implementation adds enhanced logging of token refresh requests that is useful in debugging misconfigured
credentials. Using the default HttpClient also allows the potential for setting timeouts and other such properties
via typical Micronaut configuration.

The implementation uses the blocking version of the HttpClient API. This is safe to use in this case as the GCP
library is already executing these tasks using its own managed threads, so these requests should not block the main
Micronaut event loop.

The implementation is only activated if HttpClient is found to be on the classpath. If it is not, the default
implementation provided by the SDK will be used instead.

This is initially most useful as a replacement for the enhanced logging that was being done in the problematic AuthenticationLoggingInterceptor. As the tests show, this approach allows the GoogleCredentials API to still be used to its full extent by end users as needed.

An implementation of the GCP SDK API `HttpTransportFactory` is added that internally uses the default Micronaut
`HttpClient`. This API is used by the GCP `GoogleCredentials` for refreshing OAuth tokens for use in API calls. This
implementation adds enhanced logging of token refresh requests that is useful in debugging misconfigured
credentials. Using the default `HttpClient` also allows the potential for setting timeouts and other such properties
via typical Micronaut configuration.

The implementation uses the blocking version of the `HttpClient` API. This is safe to use in this case as the GCP
library is already executing these tasks using its own managed threads, so these requests should not block the main
Micronaut event loop.

The implementation is only activated if `HttpClient` is found to be on the classpath. If it is not, the default
implementation provided by the SDK will be used instead.
@jeremyg484 jeremyg484 changed the base branch from master to remove-authentication-interceptor January 12, 2024 02:22
@jeremyg484 jeremyg484 self-assigned this Jan 12, 2024
Co-authored-by: Tim Yates <tim.yates@gmail.com>
gcp-common/build.gradle Outdated Show resolved Hide resolved
@jeremyg484 jeremyg484 requested a review from sdelamo January 16, 2024 16:28
Base automatically changed from remove-authentication-interceptor to master January 23, 2024 17:15
@sdelamo
Copy link
Contributor

sdelamo commented Jan 23, 2024

@jeremyg484 can you merge master into this?

@jeremyg484
Copy link
Contributor Author

@jeremyg484 can you merge master into this?

Done.

@@ -111,4 +119,11 @@ public void close() throws Exception {
}
}
}

boolean isRunning(ProjectSubscriptionName subscriptionName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It is weird to expose a method only to be used in a test.

@sdelamo sdelamo merged commit 26da79e into master Jan 25, 2024
8 checks passed
@sdelamo sdelamo deleted the http-transport-impl branch January 25, 2024 10:59
@sdelamo sdelamo added the type: improvement A minor improvement to an existing feature label Jan 25, 2024
Copy link

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

5 New issues
0 Security Hotspots
84.1% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: improvement A minor improvement to an existing feature
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants