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(gax): add API key authentication to ClientSettings #3137

Merged
merged 42 commits into from
Oct 2, 2024
Merged

Conversation

ldetmer
Copy link
Contributor

@ldetmer ldetmer commented Aug 28, 2024

Allow gax client libraries to authenticate using API key via setApiKey method exposed from ClientSettings. Also added deduping to GRPC calls for api key headers.

Tested using LanguageServiceSettings

cc @westarle

Copy link

conventional-commit-lint-gcf bot commented Aug 28, 2024

🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use automerge label. Good luck human!

-- conventional-commit-lint bot
https://conventionalcommits.org/

@product-auto-label product-auto-label bot added the size: s Pull request size is small. label Aug 28, 2024
@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: s Pull request size is small. labels Aug 28, 2024
@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Sep 17, 2024
@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: l Pull request size is large. labels Sep 17, 2024
@ldetmer ldetmer changed the title POC: add setApiKey() method to client settings feat: add API key authentication to Clientettings Sep 19, 2024
@ldetmer ldetmer changed the title feat: add API key authentication to Clientettings feat: add API key authentication to ClientSettings Sep 19, 2024
@ldetmer ldetmer changed the title feat: add API key authentication to ClientSettings feat(gax): add API key authentication to ClientSettings Sep 19, 2024
@ldetmer ldetmer marked this pull request as ready for review September 19, 2024 15:26
import io.grpc.Status;

/** Implements a client interceptor to retrieve the metadata from a GRPC client request. */
public class GrpcCapturingClientInterceptor implements ClientInterceptor {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! I like this. I think we had this in our backlog a while back: #2743

Probably can mark this as closed once this PR is in.

@ldetmer ldetmer requested a review from lqiu96 September 30, 2024 20:01
* @return list of provided headers that will be sent with GRPC call with any duplicates removed
* see {@link #removeCredentialDuplicateHeaders()}
*/
public Map<String, String> getHeadersWithDuplicatesRemoved() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this only used in tests? If it is, we can make this package private and mark it as @VisibleForTesting? Or we don't have to expose another method, just make removeCredentialDuplicateHeaders package privare.

Copy link
Contributor

@lqiu96 lqiu96 left a comment

Choose a reason for hiding this comment

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

LGTM

* a GDC-H audience
*/
@VisibleForTesting
public static GdchCredentials getGdchCredentials(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know it is already marked as @VisibleForTesting, can we make it package private as well? As long as it is public, customers may still use it, either accidentally or intentionally.

@@ -1074,4 +1072,46 @@ public void testStreamWatchdogInterval_backportMethodsBehaveCorrectly() {
ct -> ct.getStreamWatchdogCheckIntervalDuration(),
ct -> ct.getStreamWatchdogCheckInterval());
}

@Test
public void testSetApiKey_createsApiCredentials() throws IOException {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: These test methods don't have to be public anymore after we migrated to junit 5.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah thanks! done

@ldetmer ldetmer removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Oct 2, 2024
@ldetmer ldetmer requested a review from blakeli0 October 2, 2024 13:11
Copy link

sonarcloud bot commented Oct 2, 2024

Copy link

sonarcloud bot commented Oct 2, 2024

Quality Gate Passed Quality Gate passed for 'java_showcase_integration_tests'

Issues
52 New issues
0 Accepted issues

Measures
0 Security Hotspots
84.2% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

@ldetmer ldetmer merged commit df08956 into main Oct 2, 2024
49 of 50 checks passed
@ldetmer ldetmer deleted the api-keys branch October 2, 2024 16:09
zhumin8 pushed a commit that referenced this pull request Oct 4, 2024
🤖 I have created a release *beep* *boop*
---


<details><summary>2.47.0</summary>

##
[2.47.0](v2.46.1...v2.47.0)
(2024-10-04)


### Features

* **gax:** add API key authentication to ClientSettings
([#3137](#3137))
([df08956](df08956))
* **gax:** append cred-type header for auth metrics
([#3186](#3186))
([ca3ec24](ca3ec24))


### Bug Fixes

* address incorrect universe domain validation when quota project id is
set
([#3257](#3257))
([6e70c37](6e70c37)),
closes
[#3256](#3256)
* Disable automatically retrieving Universe Domain from Metadata Server
([#3272](#3272))
([f4402bf](f4402bf))


### Dependencies

* update dependency com.fasterxml.jackson:jackson-bom to v2.18.0
([#3248](#3248))
([821e83d](821e83d))
* update dependency com.google.errorprone:error_prone_annotations to
v2.33.0
([#3265](#3265))
([94450a9](94450a9))
* update dependency com.google.errorprone:error_prone_annotations to
v2.33.0
([#3266](#3266))
([8235463](8235463))
* update dependency com.google.guava:guava to v33.3.1-jre
([#3228](#3228))
([4e76207](4e76207))
* update dependency net.bytebuddy:byte-buddy to v1.15.3
([#3246](#3246))
([2aad71d](2aad71d))
* update google api dependencies
([#3242](#3242))
([02aae9d](02aae9d))
* update google auth library dependencies to v1.28.0
([#3267](#3267))
([6d85864](6d85864))
* update googleapis/java-cloud-bom digest to 0cd97b7
([#3260](#3260))
([2d54a5d](2d54a5d))
* update grpc dependencies to v1.67.1
([#3258](#3258))
([e08906c](e08906c))
* update grpc dependencies to v1.67.1 in dependencies.properties
([#3279](#3279))
([5b46e70](5b46e70))
* update junit5 monorepo to v5.11.2
([#3276](#3276))
([6b10f94](6b10f94))
* update netty dependencies to v4.1.114.final
([#3263](#3263))
([8bd83d9](8bd83d9))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants