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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

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.

Tested using LanguageServiceSettings

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
@@ -175,9 +176,19 @@ public static ClientContext create(StubSettings settings) throws IOException {
// A valid EndpointContext should have been created in the StubSettings
EndpointContext endpointContext = settings.getEndpointContext();
String endpoint = endpointContext.resolvedEndpoint();
String apiKey = settings.getApiKey();
Credentials credentials = settings.getCredentialsProvider().getCredentials();
if (apiKey != null && credentials != null) {
Copy link
Contributor Author

@ldetmer ldetmer Sep 19, 2024

Choose a reason for hiding this comment

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

I added logic here to handle null check snd setting credentials (instead of in builder) as I thought it would be more discoverable/debuggable here since the rest of credential logic lives here

throw new IllegalArgumentException("The GDC-H API audience string is not a valid URI", ex);
}
credentials = ((GdchCredentials) credentials).createWithGdchAudience(gdchAudienceUri);
credentials = getGdchCredentials(settingsGdchApiAudience, endpoint, credentials);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

created helper method for readability, no change to logic

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant