| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -44,6 +44,7 @@ | |
| import com.google.api.gax.tracing.ApiTracerFactory; | ||
| import com.google.api.gax.tracing.BaseApiTracerFactory; | ||
| import com.google.auth.ApiKeyCredentials; | ||
| import com.google.auth.CredentialTypeForMetrics; | ||
| import com.google.auth.Credentials; | ||
| import com.google.auth.oauth2.GdchCredentials; | ||
| import com.google.auto.value.AutoValue; | ||
| Expand Down Expand Up | @@ -210,7 +211,8 @@ public static ClientContext create(StubSettings settings) throws IOException { | |
| if (transportChannelProvider.needsExecutor() && settings.getExecutorProvider() != null) { | ||
| transportChannelProvider = transportChannelProvider.withExecutor(backgroundExecutor); | ||
| } | ||
| Map<String, String> headers = getHeadersFromSettings(settings); | ||
|
|
||
| Map<String, String> headers = getHeaders(settings, credentials); | ||
| if (transportChannelProvider.needsHeaders()) { | ||
| transportChannelProvider = transportChannelProvider.withHeaders(headers); | ||
| } | ||
| Expand Down Expand Up | @@ -318,8 +320,11 @@ static GdchCredentials getGdchCredentials( | |
| /** | ||
| * Getting a header map from HeaderProvider and InternalHeaderProvider from settings with Quota | ||
| * Project Id. | ||
| * | ||
| * <p>Then if credentials is present and its type for metrics is not {@code | ||
| * CredentialTypeForMetrics.DO_NOT_SEND}, append this type info to x-goog-api-client header. | ||
| */ | ||
| private static Map<String, String> getHeadersFromSettings(StubSettings settings) { | ||
| private static Map<String, String> getHeaders(StubSettings settings, Credentials credentials) { | ||
| // Resolve conflicts when merging headers from multiple sources | ||
| Map<String, String> userHeaders = settings.getHeaderProvider().getHeaders(); | ||
| Map<String, String> internalHeaders = settings.getInternalHeaderProvider().getHeaders(); | ||
| Expand All | @@ -346,6 +351,20 @@ private static Map<String, String> getHeadersFromSettings(StubSettings settings) | |
| effectiveHeaders.putAll(userHeaders); | ||
| effectiveHeaders.putAll(conflictResolution); | ||
|
|
||
| return appendCredentialTypeToHeaderIfPresent(effectiveHeaders, credentials); | ||
| } | ||
|
|
||
| private static Map<String, String> appendCredentialTypeToHeaderIfPresent( | ||
| Map<String, String> effectiveHeaders, Credentials credentials) { | ||
| CredentialTypeForMetrics credentialTypeForMetrics = | ||
| credentials == null | ||
| ? CredentialTypeForMetrics.DO_NOT_SEND | ||
| : credentials.getMetricsCredentialType(); | ||
| if (credentialTypeForMetrics != CredentialTypeForMetrics.DO_NOT_SEND) { | ||
| effectiveHeaders.computeIfPresent( | ||
| ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), | ||
|
Comment thread
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIs it decided to append cred-type/ to x-goog-api-client header? It seems all other header tokens in x-goog-api-client are static values from the client, not from user input. I wonder why we didn't choose to use a separate header key for this purpose?
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
yes, this design is already implemented for other some languages. See details in design go/googleapis-auth-metric-design section 2.3.2. I don't think I saw discussion on using a different header specifically though.
IIUC, this header is eventually sent per request, at that time, I don't see credentials type much different than other client lib info? Do you have specific concerns about this?
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThe concern is that x-goog-api-client was constructed in the generated layer only with static values, the name of the header api-client also seems to indicate that the header is supposed to contain only info for the client, not for requests.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI see your point.
Sorry, something went wrong.
All reactions
|
||
| (key, value) -> value + " cred-type/" + credentialTypeForMetrics.getLabel()); | ||
| } | ||
| return ImmutableMap.copyOf(effectiveHeaders); | ||
| } | ||
|
|
||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Qualitynit: extract this to a private method for better readability.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.