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: support GDC-H Credentials #1642

Merged
merged 54 commits into from
Jun 28, 2023
Merged

feat: support GDC-H Credentials #1642

merged 54 commits into from
Jun 28, 2023

Conversation

diegomarquezp
Copy link
Contributor

This PR adds support for GDC-H credentials.
Mainly, it adds the option to have gdchApiAudience in ClientContext and StubSettings.
ClientContext.create(StubSettings) will verify that:

  • if gdchApiAudience is set, then only a GdchCredential returned from the CredentialProvider is accepted
  • gdchApiAudience is a valid URI

@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Apr 20, 2023
@diegomarquezp diegomarquezp changed the title feat: support GDC-H Credentials feat: [wip] support GDC-H Credentials Apr 20, 2023
@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 May 23, 2023
GdchCredentials fromClient =
(GdchCredentials) client.getSettings().getCredentialsProvider().getCredentials();

assertSame(credentials, fromClient);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought the credential would be different since it now has an additional field gdchApiAudience?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the provider is not modified when creating the ClientContext. In fact, ClientContext.create() retrieves the Credentials from the provider, then modifies them accordingly (e.g. re-create with gdchApiAudience or any other type of `Credentials) and stores them as an internal property.

I'm just describing what happens with ClientContext creation.
For example,

if (settings.getQuotaProjectId() != null) {
// If the quotaProjectId is set, wrap original credentials with correct quotaProjectId as
// QuotaProjectIdHidingCredentials.
// Ensure that a custom set quota project id takes priority over one detected by credentials.
// Avoid the backend receiving possibly conflict values of quotaProjectId
credentials = new QuotaProjectIdHidingCredentials(credentials);
}

Modifies the Credentials object and then a new ClientContext is created with such Credentials

return newBuilder()
.setBackgroundResources(backgroundResources.build())
.setExecutor(backgroundExecutor)
.setCredentials(credentials)

Should ClientContext.create() alter the Credentials provided by CredentialsProvider?

Copy link
Member

@TimurSadykov TimurSadykov Jun 1, 2023

Choose a reason for hiding this comment

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

While the logic above is correct, the test seems not validating what it declares (Blake's point from different angle). The test description WithAudience - is is not tested.

Instead, test validates that the original credential stay in credential provider as is.

Also, this is effectively a unit test, not integration, right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, this is effectively a unit test, not integration, right?

We want to test that the audience set through ClientSetting in a client library is being properly propagated to ClientContext and set to Credentials, which we cannot test through unit tests, only through showcase clients. So yeah this is not a true integration tests that interact with servers, more like a component test only verifying the client behaviors.
That being said, I agree with you that this test does not verify the audience, which we should.

@diegomarquezp diegomarquezp added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Jun 23, 2023
@diegomarquezp diegomarquezp removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Jun 28, 2023
showcase/pom.xml Outdated Show resolved Hide resolved
Copy link
Collaborator

@blakeli0 blakeli0 left a comment

Choose a reason for hiding this comment

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

LGTM with one minor comment. Feel free to merge it after the comment is resolved.

@sonarcloud
Copy link

sonarcloud bot commented Jun 28, 2023

[gapic-generator-java-root] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

90.0% 90.0% Coverage
0.0% 0.0% Duplication

@sonarcloud
Copy link

sonarcloud bot commented Jun 28, 2023

[java_showcase_integration_tests] SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

67.5% 67.5% Coverage
0.0% 0.0% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@sonarcloud
Copy link

sonarcloud bot commented Jun 28, 2023

[java_showcase_unit_tests] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

90.0% 90.0% Coverage
0.0% 0.0% Duplication

@diegomarquezp diegomarquezp merged commit 26da0d3 into main Jun 28, 2023
@diegomarquezp diegomarquezp deleted the gdc-h branch June 28, 2023 22:39
lqiu96 pushed a commit that referenced this pull request Jul 12, 2023
* chore: initial additions to handle GDC-H API audience

* chore: add unit tests for GDC-H

* chore: cleanup of logic

* chore: decompose tests into separate methods

* chore: fix clirr diff check

* chore: fmt:format

* chore: add support in `ClientSettings`

* chore: add showcase IT for GDCH credentials

* chore: comments

* chore: improve tests

* chore: add partial IT for testing context credential

* chore: recreate GdchCredentials with audience using convenience method

* chore: more readable api audience logic

* chore: no wildcard imports

* chore: javadoc for public methods

* chore: gdch test to use default null initialization

* chore: tear down for gdch IT

* chore: `assertThrows` for gdch ITs

* chore: mvn fmt:format

* test: remove context test

* docs: explain that audience will be overriden if set through client/stub settings

* test: test audience setting should modify initial credentials

* chore: clirr check

* chore: ignore gdch changes

* chore: format

* chore: default to endpoint if audience not provided

* test: refresh gdch creds to confirm audience works

* chore: fmt

* chore: fmt

* chore: better test names in ClientContextTest

* chore: better test names for showcase tests

* chore: simplify refresh verification logic

* chore: include outcome in gdch it test names

* chore: expand comments in GDCH ITs

* test: intercept mock transport to verify audience

* chore: fmt

* chore: move auth test-jar to shared dependencies

* chore: cleanup

* chore: use inferred version for auth library

* deps: update google-auth-java-library to 1.19.0

* choreL fmt ITGdch.java

* chore: import auth test-jar using common version variable

* chore: remove auth test-jar import from first-party-dependencies

* chore: add license headers to new files

* chore: revert google-auth-version to be obtained from main branch

* chore: correct showcase parent pom indentation

* chore: remove resource declaration for native test build
lqiu96 added a commit that referenced this pull request Jul 17, 2023
* fix: Use bindings for resolving multi pattern resources

* chore: Fix lint issues

* chore: Add unit tests for the behavior

* chore: Add comments for the tests

* chore: Remove unused comment

* feat: support GDC-H Credentials  (#1642)

* chore: initial additions to handle GDC-H API audience

* chore: add unit tests for GDC-H

* chore: cleanup of logic

* chore: decompose tests into separate methods

* chore: fix clirr diff check

* chore: fmt:format

* chore: add support in `ClientSettings`

* chore: add showcase IT for GDCH credentials

* chore: comments

* chore: improve tests

* chore: add partial IT for testing context credential

* chore: recreate GdchCredentials with audience using convenience method

* chore: more readable api audience logic

* chore: no wildcard imports

* chore: javadoc for public methods

* chore: gdch test to use default null initialization

* chore: tear down for gdch IT

* chore: `assertThrows` for gdch ITs

* chore: mvn fmt:format

* test: remove context test

* docs: explain that audience will be overriden if set through client/stub settings

* test: test audience setting should modify initial credentials

* chore: clirr check

* chore: ignore gdch changes

* chore: format

* chore: default to endpoint if audience not provided

* test: refresh gdch creds to confirm audience works

* chore: fmt

* chore: fmt

* chore: better test names in ClientContextTest

* chore: better test names for showcase tests

* chore: simplify refresh verification logic

* chore: include outcome in gdch it test names

* chore: expand comments in GDCH ITs

* test: intercept mock transport to verify audience

* chore: fmt

* chore: move auth test-jar to shared dependencies

* chore: cleanup

* chore: use inferred version for auth library

* deps: update google-auth-java-library to 1.19.0

* choreL fmt ITGdch.java

* chore: import auth test-jar using common version variable

* chore: remove auth test-jar import from first-party-dependencies

* chore: add license headers to new files

* chore: revert google-auth-version to be obtained from main branch

* chore: correct showcase parent pom indentation

* chore: remove resource declaration for native test build

* fix: [gapic-generator-java] handle response and metadata type ambiguity in LRO parsing (#1726)

* chore: Bump grpc-java version to 1.55.3 (#1829)

* chore: Bump gapic-showcase version to 0.28.2 (#1830)

* build(deps): Bump guava version to 32.1.1-jre (#1832)

* chore: Bump guava version to 32.1.1-jre

* chore: Add guava to gradle template

* chore: Add j2obc-annotations to shared-dependencies (#1834)

* ci: fix showcase-clirr check on release PRs (#1835)

Install sdk-platform-java before performing final clirr check, so version changes are available in the local repository

* chore(main): release 2.23.0 (#1806)

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>

* chore(main): release 2.23.1-SNAPSHOT (#1836)

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>

* chore: Implement gRPC and HttpJson showcase tests for IAM (#1789)

* chore: Add framework for iam showcase tests

* chore: Generate clients with IAM stubs

* chore: Add IAM showcase tests

* chore: Add samples

* chore: Exclude httpjson tests

* chore: Use @before to create the resource

* chore: Use constant for policy

* chore: Log resource name

* chore: Test use setPolicyRequest's resourceName

* chore: run mvn clean before showcase tests

* chore: Attempt again with cache deleted

* chore: Add logging for test

* chore: Sleep for 1s

* chore: Use resource from setPolicyRequest

* chore: Ignore failing HttpJson test for now

* chore: Un-ignore test

* chore: Fix lint issues

* chore: Test with rooms/ prefix

* chore: Use Identity client for Users

* chore: Create user resource to assign policy to

* chore: Use user's name as resource id

* chore: Change resource name before each test

* chore: Add iam-grpc in pom

* chore: Resolve sonar issues

* chore: Add comment for testIamPolicy

* chore: Address PR comments

* ci: showcase native check (#1833)

* ci: showcase native check

* fix: add explicit java version

* fix: adjust syntax

* fix: add resource-config entry for ITGdch

* fix: copy file to temp folder so it can be accessed by path

* chore: formatting

* fix: prevent shutdown warnings with client.awaitTermination

* ci: fix build file location for downstream test

* chore: use static imports for Truth assertions

* chore: Resolve merge conflicts

* chore: Use bindings for any matching resource patterns

* chore: Fix lint issues

* chore: Remove unused code

* chore: Fix lint issues

* chore: Add test for resourceName matching bindings

* chore: Fix lint issues

---------

Co-authored-by: Diego Alonso Marquez Palacios <diegomarquezp@google.com>
Co-authored-by: Emily Wang <emmwang@google.com>
Co-authored-by: Burke Davison <40617934+burkedavison@users.noreply.github.com>
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.

4 participants