From 59356fe3c4152de540dc539626ca82d0db922274 Mon Sep 17 00:00:00 2001 From: Nick Cain Date: Tue, 10 Aug 2021 18:47:25 +0000 Subject: [PATCH 1/3] fix: Remove Owlbot v1beta2 customization that passes default scopes as user scopes, so that the auth library does not use the self-signed JWT flow. --- owlbot.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/owlbot.py b/owlbot.py index 3072f992..09e2663d 100644 --- a/owlbot.py +++ b/owlbot.py @@ -36,15 +36,6 @@ "scripts/fixup_documentai_v*", # this library was always generated with the microgenerator ] - s.replace(library / "google/cloud/documentai_v1beta2/**/base.py", - """scopes_kwargs = \{"scopes": scopes, "default_scopes": cls\.AUTH_SCOPES\}""", - """# Documentai uses a regional host (us-documentai.googleapis.com) as the default - # so self-signed JWT cannot be used. - # Intentionally pass default scopes as user scopes so the auth library - # does not use the self-signed JWT flow. - # https://github.com/googleapis/python-documentai/issues/174 - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES, "default_scopes": cls.AUTH_SCOPES}""") - s.replace(library / "tests/**/documentai_v1beta2/*.py", """(@requires_google_auth_gte_1_25_0 def test_document_.*?_service_base_transport_with_credentials_file.*?)scopes=None,""", From 620ec12f7304ec88edee6d5ae7ad1bd088a2b492 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Thu, 12 Aug 2021 15:58:34 +0000 Subject: [PATCH 2/3] run owlbot locally --- .../document_understanding_service/client.py | 2 +- .../transports/base.py | 12 ++---------- .../transports/grpc.py | 4 ++-- .../transports/grpc_asyncio.py | 4 ++-- .../test_document_understanding_service.py | 16 ++++++++-------- 5 files changed, 15 insertions(+), 23 deletions(-) diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py index e9033e46..ac1bdd11 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py @@ -115,7 +115,7 @@ def _get_default_mtls_endpoint(api_endpoint): return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - DEFAULT_ENDPOINT = "us-documentai.googleapis.com" + DEFAULT_ENDPOINT = "documentai.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py index c29c565c..e016c306 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py @@ -55,7 +55,7 @@ class DocumentUnderstandingServiceTransport(abc.ABC): AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) - DEFAULT_HOST: str = "us-documentai.googleapis.com" + DEFAULT_HOST: str = "documentai.googleapis.com" def __init__( self, @@ -148,15 +148,7 @@ def _get_scopes_kwargs( packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0") ): - # Documentai uses a regional host (us-documentai.googleapis.com) as the default - # so self-signed JWT cannot be used. - # Intentionally pass default scopes as user scopes so the auth library - # does not use the self-signed JWT flow. - # https://github.com/googleapis/python-documentai/issues/174 - scopes_kwargs = { - "scopes": scopes or cls.AUTH_SCOPES, - "default_scopes": cls.AUTH_SCOPES, - } + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} else: scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py index 20b5889a..1cdc916c 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py @@ -51,7 +51,7 @@ class DocumentUnderstandingServiceGrpcTransport(DocumentUnderstandingServiceTran def __init__( self, *, - host: str = "us-documentai.googleapis.com", + host: str = "documentai.googleapis.com", credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, @@ -181,7 +181,7 @@ def __init__( @classmethod def create_channel( cls, - host: str = "us-documentai.googleapis.com", + host: str = "documentai.googleapis.com", credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Optional[Sequence[str]] = None, diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py index b8ebd07a..513a1d3e 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py @@ -56,7 +56,7 @@ class DocumentUnderstandingServiceGrpcAsyncIOTransport( @classmethod def create_channel( cls, - host: str = "us-documentai.googleapis.com", + host: str = "documentai.googleapis.com", credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, @@ -99,7 +99,7 @@ def create_channel( def __init__( self, *, - host: str = "us-documentai.googleapis.com", + host: str = "documentai.googleapis.com", credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, diff --git a/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py b/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py index 26697f9d..84996907 100644 --- a/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py +++ b/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py @@ -131,7 +131,7 @@ def test_document_understanding_service_client_from_service_account_info(client_ assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "us-documentai.googleapis.com:443" + assert client.transport._host == "documentai.googleapis.com:443" @pytest.mark.parametrize( @@ -177,7 +177,7 @@ def test_document_understanding_service_client_from_service_account_file(client_ assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "us-documentai.googleapis.com:443" + assert client.transport._host == "documentai.googleapis.com:443" def test_document_understanding_service_client_get_transport_class(): @@ -1175,13 +1175,13 @@ def test_document_understanding_service_transport_create_channel( transport_class(quota_project_id="octopus", scopes=["1", "2"]) create_channel.assert_called_with( - "us-documentai.googleapis.com:443", + "documentai.googleapis.com:443", credentials=creds, credentials_file=None, quota_project_id="octopus", default_scopes=("https://www.googleapis.com/auth/cloud-platform",), scopes=["1", "2"], - default_host="us-documentai.googleapis.com", + default_host="documentai.googleapis.com", ssl_credentials=None, options=[ ("grpc.max_send_message_length", -1), @@ -1241,20 +1241,20 @@ def test_document_understanding_service_host_no_port(): client = DocumentUnderstandingServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( - api_endpoint="us-documentai.googleapis.com" + api_endpoint="documentai.googleapis.com" ), ) - assert client.transport._host == "us-documentai.googleapis.com:443" + assert client.transport._host == "documentai.googleapis.com:443" def test_document_understanding_service_host_with_port(): client = DocumentUnderstandingServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( - api_endpoint="us-documentai.googleapis.com:8000" + api_endpoint="documentai.googleapis.com:8000" ), ) - assert client.transport._host == "us-documentai.googleapis.com:8000" + assert client.transport._host == "documentai.googleapis.com:8000" def test_document_understanding_service_grpc_transport_channel(): From 23a802f157eaa4a04fe07e29606e484261695eb4 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Wed, 1 Sep 2021 11:16:10 +0000 Subject: [PATCH 3/3] remove replacements for v1beta2 in owlbot.py --- noxfile.py | 12 +++++++++--- owlbot.py | 14 -------------- .../test_document_understanding_service.py | 4 ++-- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/noxfile.py b/noxfile.py index 94ee6a8f..93ea9b14 100644 --- a/noxfile.py +++ b/noxfile.py @@ -84,9 +84,15 @@ def default(session): constraints_path = str( CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" ) - session.install("asyncmock", "pytest-asyncio", "-c", constraints_path) - - session.install("mock", "pytest", "pytest-cov", "-c", constraints_path) + session.install( + "mock", + "asyncmock", + "pytest", + "pytest-cov", + "pytest-asyncio", + "-c", + constraints_path, + ) session.install("-e", ".", "-c", constraints_path) diff --git a/owlbot.py b/owlbot.py index 09e2663d..f04cac0b 100644 --- a/owlbot.py +++ b/owlbot.py @@ -30,25 +30,11 @@ for library in s.get_staging_dirs(default_version): excludes = [ "README.rst", - "nox.py", "docs/index.rst", "setup.py", "scripts/fixup_documentai_v*", # this library was always generated with the microgenerator ] - s.replace(library / "tests/**/documentai_v1beta2/*.py", - """(@requires_google_auth_gte_1_25_0 -def test_document_.*?_service_base_transport_with_credentials_file.*?)scopes=None,""", - """\g<1>scopes=("https://www.googleapis.com/auth/cloud-platform",),""", - flags=re.MULTILINE | re.DOTALL, - ) - - s.replace(library / "tests/**/documentai_v1beta2/*.py", - """(@requires_google_auth_gte_1_25_0 -def test_document_.*?_service_auth_adc.*?)scopes=None,""", - """\g<1>scopes=("https://www.googleapis.com/auth/cloud-platform",),""", - flags=re.MULTILINE | re.DOTALL, - ) s.move(library, excludes=excludes) s.remove_staging_dirs() diff --git a/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py b/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py index 84996907..d2edb50c 100644 --- a/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py +++ b/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py @@ -1045,7 +1045,7 @@ def test_document_understanding_service_base_transport_with_credentials_file(): ) load_creds.assert_called_once_with( "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, default_scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id="octopus", ) @@ -1089,7 +1089,7 @@ def test_document_understanding_service_auth_adc(): adc.return_value = (ga_credentials.AnonymousCredentials(), None) DocumentUnderstandingServiceClient() adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, default_scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id=None, )