Repository navigation
fix(gapic-generator): forward quota_project_id, scopes, credentials_file and mTLS in REST transport - #18892
Open
kmelnikov wants to merge 2 commits into
Open
fix(gapic-generator): forward quota_project_id, scopes, credentials_file and mTLS in REST transport#18892kmelnikov wants to merge 2 commits into
kmelnikov wants to merge 2 commits into
Conversation
…ile and mTLS in REST transport In generated REST transports: - Forward credentials_file, scopes, and quota_project_id from <Service>RestTransport.__init__ through _Base<Service>RestTransport.__init__ to <Service>Transport.__init__. - Apply default/custom scopes (via ga_credentials.with_scopes_if_required) and quota_project_id (via with_quota_project) to explicit credentials in <Service>Transport.__init__, matching gRPC transport behavior in google.api_core.grpc_helpers. - Store client_cert_source_for_mtls on <Service>RestTransport and forward it to operations_v1.OperationsRestTransport in operations_client. - Update generated unit test template and integration goldens.
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the GAPIC generator templates and golden files to correctly forward and apply scopes, quota project IDs, and credentials files in REST transports. It also introduces a new test suite to verify REST transport authentication. The code review identified a critical runtime issue in the base transport template where CredentialsWithQuotaProject is incorrectly accessed from google.api_core.credentials instead of google.auth.credentials, which would lead to an AttributeError.
…chema objects Render transport templates with a real API and Service instead of a hand-written stub, so the test does not break when templates read additional API attributes (for example `all_library_settings`).
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Generated REST transports (
<Service>RestTransport) acceptcredentials_file,scopes,quota_project_id, andclient_cert_source_for_mtlsin__init__, but previously dropped several of those arguments instead of forwarding them to the base transport or applying them consistently withGrpcTransport:credentials_file,scopes, andquota_project_idin REST transports:<Service>RestTransport.__init__and_Base<Service>RestTransport.__init__now passcredentials_file,scopes, andquota_project_idthroughsuper().__init__(...)to<Service>Transport.__init__(resolving theTODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc.inrest.py.j2), so Application Default Credentials (google.auth.default) and file-loaded credentials (google.auth.load_credentials_from_file) receivequota_project_idandscopesundertransport="rest"just liketransport="grpc".scopesandquota_project_idto explicitcredentialsinbase.py.j2: When explicitcredentialsare passed to<Service>Transport,ga_credentials.with_scopes_if_required(credentials, scopes=scopes, default_scopes=self.AUTH_SCOPES)andcredentials.with_quota_project(quota_project_id)(whenisinstance(credentials, ga_credentials.CredentialsWithQuotaProject)) are now applied in the base transport, matchinggoogle.api_core.grpc_helpers._create_composite_credentials.client_cert_source_for_mtlstoOperationsRestTransport:<Service>RestTransportnow storesself._client_cert_source_for_mtls = client_cert_source_for_mtlsand passes it tooperations_v1.OperationsRestTransport(...)when constructingoperations_client.packages/gapic-generator/tests/unit/generator/test_rest_transport_auth.py.test_%service.py.j2to include<Service>RestTransportintest_<service>_transport_auth_adcand addedtest_<service>_base_transport_with_credentials.packages/gapic-generator/tests/integration/goldens/.