diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index cb06536..9ee60f7 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,3 @@ docker: image: gcr.io/repo-automation-bots/owlbot-python:latest - digest: sha256:5ff7446edeaede81c3ed58b23a4e76a5403fba1350ce28478045657303b6479d + digest: sha256:aea14a583128771ae8aefa364e1652f3c56070168ef31beb203534222d842b8b diff --git a/.kokoro/samples/python3.6/periodic-head.cfg b/.kokoro/samples/python3.6/periodic-head.cfg index f9cfcd3..f71865f 100644 --- a/.kokoro/samples/python3.6/periodic-head.cfg +++ b/.kokoro/samples/python3.6/periodic-head.cfg @@ -7,5 +7,5 @@ env_vars: { env_vars: { key: "TRAMPOLINE_BUILD_FILE" - value: "github/python-pubsub/.kokoro/test-samples-against-head.sh" + value: "github/python-iap/.kokoro/test-samples-against-head.sh" } diff --git a/.kokoro/samples/python3.7/periodic-head.cfg b/.kokoro/samples/python3.7/periodic-head.cfg index f9cfcd3..f71865f 100644 --- a/.kokoro/samples/python3.7/periodic-head.cfg +++ b/.kokoro/samples/python3.7/periodic-head.cfg @@ -7,5 +7,5 @@ env_vars: { env_vars: { key: "TRAMPOLINE_BUILD_FILE" - value: "github/python-pubsub/.kokoro/test-samples-against-head.sh" + value: "github/python-iap/.kokoro/test-samples-against-head.sh" } diff --git a/.kokoro/samples/python3.8/periodic-head.cfg b/.kokoro/samples/python3.8/periodic-head.cfg index f9cfcd3..f71865f 100644 --- a/.kokoro/samples/python3.8/periodic-head.cfg +++ b/.kokoro/samples/python3.8/periodic-head.cfg @@ -7,5 +7,5 @@ env_vars: { env_vars: { key: "TRAMPOLINE_BUILD_FILE" - value: "github/python-pubsub/.kokoro/test-samples-against-head.sh" + value: "github/python-iap/.kokoro/test-samples-against-head.sh" } diff --git a/.kokoro/samples/python3.9/periodic-head.cfg b/.kokoro/samples/python3.9/periodic-head.cfg index f9cfcd3..f71865f 100644 --- a/.kokoro/samples/python3.9/periodic-head.cfg +++ b/.kokoro/samples/python3.9/periodic-head.cfg @@ -7,5 +7,5 @@ env_vars: { env_vars: { key: "TRAMPOLINE_BUILD_FILE" - value: "github/python-pubsub/.kokoro/test-samples-against-head.sh" + value: "github/python-iap/.kokoro/test-samples-against-head.sh" } diff --git a/CHANGELOG.md b/CHANGELOG.md index e94e858..c4e3553 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,22 @@ # Changelog +### [0.1.2](https://www.github.com/googleapis/python-iap/compare/v0.1.1...v0.1.2) (2021-07-29) + + +### Bug Fixes + +* enable self signed jwt for grpc ([#9](https://www.github.com/googleapis/python-iap/issues/9)) ([51304a3](https://www.github.com/googleapis/python-iap/commit/51304a327207a233e40308a8b49c9fdeda87c28b)) + + +### Documentation + +* add Samples section to CONTRIBUTING.rst ([#5](https://www.github.com/googleapis/python-iap/issues/5)) ([2ba31c5](https://www.github.com/googleapis/python-iap/commit/2ba31c5a2ea2e52c4a79410548a252bf8fc0522e)) + + +### Miscellaneous Chores + +* release as 0.1.2 ([#10](https://www.github.com/googleapis/python-iap/issues/10)) ([4499ba5](https://www.github.com/googleapis/python-iap/commit/4499ba5ccd90edc882fbda73e4d792074ff44e6d)) + ### [0.1.1](https://www.github.com/googleapis/python-iap/compare/v0.1.0...v0.1.1) (2021-07-21) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 11d53f4..076272d 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -177,6 +177,30 @@ Build the docs via: $ nox -s docs +************************* +Samples and code snippets +************************* + +Code samples and snippets live in the `samples/` catalogue. Feel free to +provide more examples, but make sure to write tests for those examples. +Each folder containing example code requires its own `noxfile.py` script +which automates testing. If you decide to create a new folder, you can +base it on the `samples/snippets` folder (providing `noxfile.py` and +the requirements files). + +The tests will run against a real Google Cloud Project, so you should +configure them just like the System Tests. + +- To run sample tests, you can execute:: + + # Run all tests in a folder + $ cd samples/snippets + $ nox -s py-3.8 + + # Run a single sample test + $ cd samples/snippets + $ nox -s py-3.8 -- -k + ******************************************** Note About ``README`` as it pertains to PyPI ******************************************** diff --git a/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/client.py b/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/client.py index 18de015..3fd8fc6 100644 --- a/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/client.py +++ b/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/client.py @@ -338,6 +338,10 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=( + Transport == type(self).get_transport_class("grpc") + or Transport == type(self).get_transport_class("grpc_asyncio") + ), ) def set_iam_policy( diff --git a/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/client.py b/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/client.py index 47b49d9..2e31a8a 100644 --- a/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/client.py +++ b/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/client.py @@ -340,6 +340,10 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=( + Transport == type(self).get_transport_class("grpc") + or Transport == type(self).get_transport_class("grpc_asyncio") + ), ) def list_brands( diff --git a/setup.py b/setup.py index e5eb469..a547649 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ name = "google-cloud-iap" description = "Identity-Aware Proxy API client library" -version = "0.1.1" +version = "0.1.2" release_status = "Development Status :: 4 - Beta" url = "https://github.com/googleapis/python-iap" dependencies = [ diff --git a/tests/unit/gapic/iap_v1/test_identity_aware_proxy_admin_service.py b/tests/unit/gapic/iap_v1/test_identity_aware_proxy_admin_service.py index 4c360c6..f34f677 100644 --- a/tests/unit/gapic/iap_v1/test_identity_aware_proxy_admin_service.py +++ b/tests/unit/gapic/iap_v1/test_identity_aware_proxy_admin_service.py @@ -137,21 +137,6 @@ def test_identity_aware_proxy_admin_service_client_from_service_account_info( assert client.transport._host == "iap.googleapis.com:443" -@pytest.mark.parametrize( - "client_class", - [IdentityAwareProxyAdminServiceClient, IdentityAwareProxyAdminServiceAsyncClient,], -) -def test_identity_aware_proxy_admin_service_client_service_account_always_use_jwt( - client_class, -): - with mock.patch.object( - service_account.Credentials, "with_always_use_jwt_access", create=True - ) as use_jwt: - creds = service_account.Credentials(None, None, None) - client = client_class(credentials=creds) - use_jwt.assert_not_called() - - @pytest.mark.parametrize( "transport_class,transport_name", [ @@ -159,7 +144,7 @@ def test_identity_aware_proxy_admin_service_client_service_account_always_use_jw (transports.IdentityAwareProxyAdminServiceGrpcAsyncIOTransport, "grpc_asyncio"), ], ) -def test_identity_aware_proxy_admin_service_client_service_account_always_use_jwt_true( +def test_identity_aware_proxy_admin_service_client_service_account_always_use_jwt( transport_class, transport_name ): with mock.patch.object( @@ -169,6 +154,13 @@ def test_identity_aware_proxy_admin_service_client_service_account_always_use_jw transport = transport_class(credentials=creds, always_use_jwt_access=True) use_jwt.assert_called_once_with(True) + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + @pytest.mark.parametrize( "client_class", @@ -260,6 +252,7 @@ def test_identity_aware_proxy_admin_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -276,6 +269,7 @@ def test_identity_aware_proxy_admin_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -292,6 +286,7 @@ def test_identity_aware_proxy_admin_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has @@ -320,6 +315,7 @@ def test_identity_aware_proxy_admin_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -396,6 +392,7 @@ def test_identity_aware_proxy_admin_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -429,6 +426,7 @@ def test_identity_aware_proxy_admin_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -450,6 +448,7 @@ def test_identity_aware_proxy_admin_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -484,6 +483,7 @@ def test_identity_aware_proxy_admin_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -518,6 +518,7 @@ def test_identity_aware_proxy_admin_service_client_client_options_credentials_fi client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -537,6 +538,7 @@ def test_identity_aware_proxy_admin_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) diff --git a/tests/unit/gapic/iap_v1/test_identity_aware_proxy_o_auth_service.py b/tests/unit/gapic/iap_v1/test_identity_aware_proxy_o_auth_service.py index db1a796..428e965 100644 --- a/tests/unit/gapic/iap_v1/test_identity_aware_proxy_o_auth_service.py +++ b/tests/unit/gapic/iap_v1/test_identity_aware_proxy_o_auth_service.py @@ -132,21 +132,6 @@ def test_identity_aware_proxy_o_auth_service_client_from_service_account_info( assert client.transport._host == "iap.googleapis.com:443" -@pytest.mark.parametrize( - "client_class", - [IdentityAwareProxyOAuthServiceClient, IdentityAwareProxyOAuthServiceAsyncClient,], -) -def test_identity_aware_proxy_o_auth_service_client_service_account_always_use_jwt( - client_class, -): - with mock.patch.object( - service_account.Credentials, "with_always_use_jwt_access", create=True - ) as use_jwt: - creds = service_account.Credentials(None, None, None) - client = client_class(credentials=creds) - use_jwt.assert_not_called() - - @pytest.mark.parametrize( "transport_class,transport_name", [ @@ -154,7 +139,7 @@ def test_identity_aware_proxy_o_auth_service_client_service_account_always_use_j (transports.IdentityAwareProxyOAuthServiceGrpcAsyncIOTransport, "grpc_asyncio"), ], ) -def test_identity_aware_proxy_o_auth_service_client_service_account_always_use_jwt_true( +def test_identity_aware_proxy_o_auth_service_client_service_account_always_use_jwt( transport_class, transport_name ): with mock.patch.object( @@ -164,6 +149,13 @@ def test_identity_aware_proxy_o_auth_service_client_service_account_always_use_j transport = transport_class(credentials=creds, always_use_jwt_access=True) use_jwt.assert_called_once_with(True) + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + @pytest.mark.parametrize( "client_class", @@ -255,6 +247,7 @@ def test_identity_aware_proxy_o_auth_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -271,6 +264,7 @@ def test_identity_aware_proxy_o_auth_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -287,6 +281,7 @@ def test_identity_aware_proxy_o_auth_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has @@ -315,6 +310,7 @@ def test_identity_aware_proxy_o_auth_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -391,6 +387,7 @@ def test_identity_aware_proxy_o_auth_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -424,6 +421,7 @@ def test_identity_aware_proxy_o_auth_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -445,6 +443,7 @@ def test_identity_aware_proxy_o_auth_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -479,6 +478,7 @@ def test_identity_aware_proxy_o_auth_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -513,6 +513,7 @@ def test_identity_aware_proxy_o_auth_service_client_client_options_credentials_f client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -532,6 +533,7 @@ def test_identity_aware_proxy_o_auth_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, )