From 8e6b0cca8709ae8c7f0c722c5ebf0707358d3359 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 12 Dec 2024 21:21:21 +0500 Subject: [PATCH] feat: [Many APIs] Add support for opt-in debug logging (#13346) BEGIN_COMMIT_OVERRIDE feat: Add support for opt-in debug logging fix: Fix typing issue with gRPC metadata when key ends in -bin chore: Update gapic-generator-python to v1.21.0 END_COMMIT_OVERRIDE - [ ] Regenerate this pull request now. fix: Fix typing issue with gRPC metadata when key ends in -bin chore: Update gapic-generator-python to v1.21.0 PiperOrigin-RevId: 705285820 Source-Link: https://github.com/googleapis/googleapis/commit/f9b8b9150f7fcd600b0acaeef91236b1843f5e49 Source-Link: https://github.com/googleapis/googleapis-gen/commit/ca1e0a1e472d6e6f5de883a5cb54724f112ce348 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLW9wdGltaXphdGlvbi8uT3dsQm90LnlhbWwiLCJoIjoiY2ExZTBhMWU0NzJkNmU2ZjVkZTg4M2E1Y2I1NDcyNGYxMTJjZTM0OCJ9 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLW9zLWNvbmZpZy8uT3dsQm90LnlhbWwiLCJoIjoiY2ExZTBhMWU0NzJkNmU2ZjVkZTg4M2E1Y2I1NDcyNGYxMTJjZTM0OCJ9 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLW9zLWxvZ2luLy5Pd2xCb3QueWFtbCIsImgiOiJjYTFlMGExZTQ3MmQ2ZTZmNWRlODgzYTVjYjU0NzI0ZjExMmNlMzQ4In0= Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXBoaXNoaW5nLXByb3RlY3Rpb24vLk93bEJvdC55YW1sIiwiaCI6ImNhMWUwYTFlNDcyZDZlNmY1ZGU4ODNhNWNiNTQ3MjRmMTEyY2UzNDgifQ== Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXBvbGljeS10cm91Ymxlc2hvb3Rlci8uT3dsQm90LnlhbWwiLCJoIjoiY2ExZTBhMWU0NzJkNmU2ZjVkZTg4M2E1Y2I1NDcyNGYxMTJjZTM0OCJ9 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXBvbGljeXNpbXVsYXRvci8uT3dsQm90LnlhbWwiLCJoIjoiY2ExZTBhMWU0NzJkNmU2ZjVkZTg4M2E1Y2I1NDcyNGYxMTJjZTM0OCJ9 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXBvbGljeXRyb3VibGVzaG9vdGVyLWlhbS8uT3dsQm90LnlhbWwiLCJoIjoiY2ExZTBhMWU0NzJkNmU2ZjVkZTg4M2E1Y2I1NDcyNGYxMTJjZTM0OCJ9 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXByaXZhdGUtY2EvLk93bEJvdC55YW1sIiwiaCI6ImNhMWUwYTFlNDcyZDZlNmY1ZGU4ODNhNWNiNTQ3MjRmMTEyY2UzNDgifQ== Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXByaXZhdGUtY2F0YWxvZy8uT3dsQm90LnlhbWwiLCJoIjoiY2ExZTBhMWU0NzJkNmU2ZjVkZTg4M2E1Y2I1NDcyNGYxMTJjZTM0OCJ9 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXByaXZpbGVnZWRhY2Nlc3NtYW5hZ2VyLy5Pd2xCb3QueWFtbCIsImgiOiJjYTFlMGExZTQ3MmQ2ZTZmNWRlODgzYTVjYjU0NzI0ZjExMmNlMzQ4In0= Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXB1YmxpYy1jYS8uT3dsQm90LnlhbWwiLCJoIjoiY2ExZTBhMWU0NzJkNmU2ZjVkZTg4M2E1Y2I1NDcyNGYxMTJjZTM0OCJ9 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXF1b3Rhcy8uT3dsQm90LnlhbWwiLCJoIjoiY2ExZTBhMWU0NzJkNmU2ZjVkZTg4M2E1Y2I1NDcyNGYxMTJjZTM0OCJ9 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXJhcGlkbWlncmF0aW9uYXNzZXNzbWVudC8uT3dsQm90LnlhbWwiLCJoIjoiY2ExZTBhMWU0NzJkNmU2ZjVkZTg4M2E1Y2I1NDcyNGYxMTJjZTM0OCJ9 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXJlY2FwdGNoYS1lbnRlcnByaXNlLy5Pd2xCb3QueWFtbCIsImgiOiJjYTFlMGExZTQ3MmQ2ZTZmNWRlODgzYTVjYjU0NzI0ZjExMmNlMzQ4In0= Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXJlY29tbWVuZGF0aW9ucy1haS8uT3dsQm90LnlhbWwiLCJoIjoiY2ExZTBhMWU0NzJkNmU2ZjVkZTg4M2E1Y2I1NDcyNGYxMTJjZTM0OCJ9 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXJlY29tbWVuZGVyLy5Pd2xCb3QueWFtbCIsImgiOiJjYTFlMGExZTQ3MmQ2ZTZmNWRlODgzYTVjYjU0NzI0ZjExMmNlMzQ4In0= Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXJlZGlzLWNsdXN0ZXIvLk93bEJvdC55YW1sIiwiaCI6ImNhMWUwYTFlNDcyZDZlNmY1ZGU4ODNhNWNiNTQ3MjRmMTEyY2UzNDgifQ== Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXJlZGlzLy5Pd2xCb3QueWFtbCIsImgiOiJjYTFlMGExZTQ3MmQ2ZTZmNWRlODgzYTVjYjU0NzI0ZjExMmNlMzQ4In0= Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXJlc291cmNlLW1hbmFnZXIvLk93bEJvdC55YW1sIiwiaCI6ImNhMWUwYTFlNDcyZDZlNmY1ZGU4ODNhNWNiNTQ3MjRmMTEyY2UzNDgifQ== Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXJlc291cmNlLXNldHRpbmdzLy5Pd2xCb3QueWFtbCIsImgiOiJjYTFlMGExZTQ3MmQ2ZTZmNWRlODgzYTVjYjU0NzI0ZjExMmNlMzQ4In0= --------- Co-authored-by: Owl Bot Co-authored-by: ohmayr --- .../cloud/optimization/gapic_version.py | 2 +- .../cloud/optimization_v1/gapic_version.py | 2 +- .../services/fleet_routing/async_client.py | 56 +- .../services/fleet_routing/client.py | 61 +- .../services/fleet_routing/transports/grpc.py | 100 +- .../fleet_routing/transports/grpc_asyncio.py | 97 +- .../services/fleet_routing/transports/rest.py | 203 +- ...metadata_google.cloud.optimization.v1.json | 10 +- .../optimization_v1/test_fleet_routing.py | 10 + .../google/cloud/osconfig/gapic_version.py | 2 +- .../google/cloud/osconfig_v1/gapic_version.py | 2 +- .../os_config_service/async_client.py | 128 +- .../services/os_config_service/client.py | 133 +- .../services/os_config_service/pagers.py | 48 +- .../os_config_service/transports/grpc.py | 114 +- .../transports/grpc_asyncio.py | 113 +- .../os_config_service/transports/rest.py | 764 +++++- .../os_config_zonal_service/async_client.py | 128 +- .../os_config_zonal_service/client.py | 133 +- .../os_config_zonal_service/pagers.py | 80 +- .../transports/grpc.py | 128 +- .../transports/grpc_asyncio.py | 125 +- .../transports/rest.py | 785 +++++- .../cloud/osconfig_v1alpha/gapic_version.py | 2 +- .../os_config_zonal_service/async_client.py | 144 +- .../os_config_zonal_service/client.py | 149 +- .../os_config_zonal_service/pagers.py | 96 +- .../transports/grpc.py | 132 +- .../transports/grpc_asyncio.py | 129 +- .../transports/rest.py | 913 ++++++- ...pet_metadata_google.cloud.osconfig.v1.json | 98 +- ...etadata_google.cloud.osconfig.v1alpha.json | 58 +- .../osconfig_v1/test_os_config_service.py | 58 + .../test_os_config_zonal_service.py | 60 + .../test_os_config_zonal_service.py | 70 + .../google/cloud/oslogin/gapic_version.py | 2 +- .../google/cloud/oslogin_v1/gapic_version.py | 2 +- .../services/os_login_service/async_client.py | 88 +- .../services/os_login_service/client.py | 93 +- .../os_login_service/transports/grpc.py | 104 +- .../transports/grpc_asyncio.py | 103 +- .../os_login_service/transports/rest.py | 412 ++- ...ppet_metadata_google.cloud.oslogin.v1.json | 30 +- .../gapic/oslogin_v1/test_os_login_service.py | 35 + .../cloud/phishingprotection/gapic_version.py | 2 +- .../gapic_version.py | 2 +- .../async_client.py | 40 +- .../client.py | 45 +- .../transports/grpc.py | 92 +- .../transports/grpc_asyncio.py | 91 +- .../transports/rest.py | 77 +- ...ogle.cloud.phishingprotection.v1beta1.json | 6 +- ...st_phishing_protection_service_v1_beta1.py | 5 + .../policytroubleshooter/gapic_version.py | 2 +- .../policytroubleshooter_v1/gapic_version.py | 2 +- .../services/iam_checker/async_client.py | 40 +- .../services/iam_checker/client.py | 45 +- .../services/iam_checker/transports/grpc.py | 92 +- .../iam_checker/transports/grpc_asyncio.py | 91 +- .../services/iam_checker/transports/rest.py | 76 +- ..._google.cloud.policytroubleshooter.v1.json | 6 +- .../test_iam_checker.py | 3 + .../cloud/policysimulator/gapic_version.py | 2 +- .../cloud/policysimulator_v1/gapic_version.py | 2 +- .../services/simulator/async_client.py | 72 +- .../services/simulator/client.py | 77 +- .../services/simulator/pagers.py | 16 +- .../services/simulator/transports/grpc.py | 104 +- .../simulator/transports/grpc_asyncio.py | 101 +- .../services/simulator/transports/rest.py | 328 ++- ...adata_google.cloud.policysimulator.v1.json | 14 +- .../policysimulator_v1/test_simulator.py | 19 + .../policytroubleshooter_iam/gapic_version.py | 2 +- .../gapic_version.py | 2 +- .../policy_troubleshooter/async_client.py | 40 +- .../services/policy_troubleshooter/client.py | 45 +- .../policy_troubleshooter/transports/grpc.py | 92 +- .../transports/grpc_asyncio.py | 91 +- .../policy_troubleshooter/transports/rest.py | 77 +- ...gle.cloud.policytroubleshooter.iam.v3.json | 6 +- .../test_policy_troubleshooter.py | 3 + .../cloud/security/privateca/gapic_version.py | 2 +- .../security/privateca_v1/gapic_version.py | 2 +- .../async_client.py | 336 ++- .../certificate_authority_service/client.py | 341 ++- .../certificate_authority_service/pagers.py | 80 +- .../transports/grpc.py | 188 +- .../transports/grpc_asyncio.py | 185 +- .../transports/rest.py | 2413 +++++++++++++++-- .../privateca_v1beta1/gapic_version.py | 2 +- .../async_client.py | 192 +- .../certificate_authority_service/client.py | 197 +- .../certificate_authority_service/pagers.py | 64 +- .../transports/grpc.py | 142 +- .../transports/grpc_asyncio.py | 139 +- .../transports/rest.py | 1306 ++++++++- ...ta_google.cloud.security.privateca.v1.json | 118 +- ...ogle.cloud.security.privateca.v1beta1.json | 82 +- .../test_certificate_authority_service.py | 163 ++ .../test_certificate_authority_service.py | 100 + .../cloud/privatecatalog/gapic_version.py | 2 +- .../privatecatalog_v1beta1/gapic_version.py | 2 +- .../services/private_catalog/async_client.py | 56 +- .../services/private_catalog/client.py | 61 +- .../services/private_catalog/pagers.py | 48 +- .../private_catalog/transports/grpc.py | 96 +- .../transports/grpc_asyncio.py | 95 +- .../private_catalog/transports/rest.py | 208 +- ...a_google.cloud.privatecatalog.v1beta1.json | 14 +- .../test_private_catalog.py | 12 + .../privilegedaccessmanager/gapic_version.py | 2 +- .../gapic_version.py | 2 +- .../privileged_access_manager/async_client.py | 184 +- .../privileged_access_manager/client.py | 189 +- .../privileged_access_manager/pagers.py | 64 +- .../transports/grpc.py | 132 +- .../transports/grpc_asyncio.py | 129 +- .../transports/rest.py | 1217 ++++++++- ...ogle.cloud.privilegedaccessmanager.v1.json | 58 +- .../test_privileged_access_manager.py | 74 + .../cloud/security/publicca/gapic_version.py | 2 +- .../security/publicca_v1/gapic_version.py | 2 +- .../async_client.py | 40 +- .../client.py | 45 +- .../transports/grpc.py | 94 +- .../transports/grpc_asyncio.py | 93 +- .../transports/rest.py | 74 +- .../publicca_v1beta1/gapic_version.py | 2 +- .../async_client.py | 40 +- .../client.py | 45 +- .../transports/grpc.py | 94 +- .../transports/grpc_asyncio.py | 93 +- .../transports/rest.py | 74 +- ...ata_google.cloud.security.publicca.v1.json | 6 +- ...oogle.cloud.security.publicca.v1beta1.json | 6 +- ...st_public_certificate_authority_service.py | 5 + ...st_public_certificate_authority_service.py | 5 + .../google/cloud/cloudquotas/gapic_version.py | 2 +- .../cloud/cloudquotas_v1/gapic_version.py | 2 +- .../services/cloud_quotas/async_client.py | 80 +- .../services/cloud_quotas/client.py | 85 +- .../services/cloud_quotas/pagers.py | 32 +- .../services/cloud_quotas/transports/grpc.py | 102 +- .../cloud_quotas/transports/grpc_asyncio.py | 101 +- .../services/cloud_quotas/transports/rest.py | 400 ++- ...et_metadata_google.api.cloudquotas.v1.json | 26 +- .../gapic/cloudquotas_v1/test_cloud_quotas.py | 30 + .../rapidmigrationassessment/gapic_version.py | 2 +- .../gapic_version.py | 2 +- .../async_client.py | 160 +- .../rapid_migration_assessment/client.py | 165 +- .../rapid_migration_assessment/pagers.py | 16 +- .../transports/grpc.py | 126 +- .../transports/grpc_asyncio.py | 123 +- .../transports/rest.py | 982 ++++++- ...gle.cloud.rapidmigrationassessment.v1.json | 42 +- .../test_rapid_migration_assessment.py | 62 + .../async_client.py | 208 +- .../recaptcha_enterprise_service/client.py | 213 +- .../recaptcha_enterprise_service/pagers.py | 96 +- .../transports/grpc.py | 138 +- .../transports/grpc_asyncio.py | 137 +- ...a_google.cloud.recaptchaenterprise.v1.json | 88 +- .../recommendationengine/gapic_version.py | 2 +- .../gapic_version.py | 2 +- .../services/catalog_service/async_client.py | 80 +- .../services/catalog_service/client.py | 85 +- .../services/catalog_service/pagers.py | 16 +- .../catalog_service/transports/grpc.py | 106 +- .../transports/grpc_asyncio.py | 103 +- .../catalog_service/transports/rest.py | 377 ++- .../async_client.py | 56 +- .../prediction_api_key_registry/client.py | 61 +- .../prediction_api_key_registry/pagers.py | 16 +- .../transports/grpc.py | 96 +- .../transports/grpc_asyncio.py | 95 +- .../transports/rest.py | 178 +- .../prediction_service/async_client.py | 40 +- .../services/prediction_service/client.py | 45 +- .../services/prediction_service/pagers.py | 16 +- .../prediction_service/transports/grpc.py | 92 +- .../transports/grpc_asyncio.py | 91 +- .../prediction_service/transports/rest.py | 76 +- .../user_event_service/async_client.py | 72 +- .../services/user_event_service/client.py | 77 +- .../services/user_event_service/pagers.py | 16 +- .../user_event_service/transports/grpc.py | 104 +- .../transports/grpc_asyncio.py | 101 +- .../user_event_service/transports/rest.py | 336 ++- ...le.cloud.recommendationengine.v1beta1.json | 62 +- .../test_catalog_service.py | 30 + .../test_prediction_api_key_registry.py | 15 + .../test_prediction_service.py | 5 + .../test_user_event_service.py | 25 + .../google/cloud/recommender/gapic_version.py | 2 +- .../cloud/recommender_v1/gapic_version.py | 2 +- .../services/recommender/async_client.py | 136 +- .../services/recommender/client.py | 141 +- .../services/recommender/pagers.py | 32 +- .../services/recommender/transports/grpc.py | 122 +- .../recommender/transports/grpc_asyncio.py | 121 +- .../services/recommender/transports/rest.py | 845 +++++- .../recommender_v1beta1/gapic_version.py | 2 +- .../services/recommender/async_client.py | 144 +- .../services/recommender/client.py | 149 +- .../services/recommender/pagers.py | 64 +- .../services/recommender/transports/grpc.py | 124 +- .../recommender/transports/grpc_asyncio.py | 123 +- .../services/recommender/transports/rest.py | 917 ++++++- ..._metadata_google.cloud.recommender.v1.json | 54 +- ...data_google.cloud.recommender.v1beta1.json | 58 +- .../gapic/recommender_v1/test_recommender.py | 64 + .../recommender_v1beta1/test_recommender.py | 66 + .../cloud/redis_cluster/gapic_version.py | 2 +- .../cloud/redis_cluster_v1/gapic_version.py | 2 +- .../cloud_redis_cluster/async_client.py | 128 +- .../services/cloud_redis_cluster/client.py | 133 +- .../services/cloud_redis_cluster/pagers.py | 16 +- .../cloud_redis_cluster/transports/grpc.py | 118 +- .../transports/grpc_asyncio.py | 115 +- .../cloud_redis_cluster/transports/rest.py | 735 ++++- .../redis_cluster_v1beta1/gapic_version.py | 2 +- .../cloud_redis_cluster/async_client.py | 128 +- .../services/cloud_redis_cluster/client.py | 133 +- .../services/cloud_redis_cluster/pagers.py | 16 +- .../cloud_redis_cluster/transports/grpc.py | 118 +- .../transports/grpc_asyncio.py | 115 +- .../cloud_redis_cluster/transports/rest.py | 735 ++++- ...etadata_google.cloud.redis.cluster.v1.json | 26 +- ...ta_google.cloud.redis.cluster.v1beta1.json | 26 +- .../test_cloud_redis_cluster.py | 42 + .../test_cloud_redis_cluster.py | 42 + .../google/cloud/redis/gapic_version.py | 2 +- .../google/cloud/redis_v1/gapic_version.py | 2 +- .../services/cloud_redis/async_client.py | 168 +- .../redis_v1/services/cloud_redis/client.py | 173 +- .../redis_v1/services/cloud_redis/pagers.py | 16 +- .../services/cloud_redis/transports/grpc.py | 128 +- .../cloud_redis/transports/grpc_asyncio.py | 125 +- .../services/cloud_redis/transports/rest.py | 1052 ++++++- .../cloud/redis_v1beta1/gapic_version.py | 2 +- .../services/cloud_redis/async_client.py | 120 +- .../services/cloud_redis/client.py | 125 +- .../services/cloud_redis/pagers.py | 16 +- .../services/cloud_redis/transports/grpc.py | 116 +- .../cloud_redis/transports/grpc_asyncio.py | 113 +- .../services/cloud_redis/transports/rest.py | 716 ++++- ...nippet_metadata_google.cloud.redis.v1.json | 46 +- ...t_metadata_google.cloud.redis.v1beta1.json | 46 +- .../unit/gapic/redis_v1/test_cloud_redis.py | 67 + .../gapic/redis_v1beta1/test_cloud_redis.py | 55 + .../cloud/resourcemanager/gapic_version.py | 2 +- .../cloud/resourcemanager_v3/gapic_version.py | 2 +- .../services/folders/async_client.py | 128 +- .../services/folders/client.py | 133 +- .../services/folders/pagers.py | 32 +- .../services/folders/transports/grpc.py | 118 +- .../folders/transports/grpc_asyncio.py | 115 +- .../services/folders/transports/rest.py | 776 +++++- .../services/organizations/async_client.py | 80 +- .../services/organizations/client.py | 85 +- .../services/organizations/pagers.py | 16 +- .../services/organizations/transports/grpc.py | 102 +- .../organizations/transports/grpc_asyncio.py | 101 +- .../services/organizations/transports/rest.py | 397 ++- .../services/projects/async_client.py | 128 +- .../services/projects/client.py | 133 +- .../services/projects/pagers.py | 32 +- .../services/projects/transports/grpc.py | 118 +- .../projects/transports/grpc_asyncio.py | 115 +- .../services/projects/transports/rest.py | 770 +++++- .../services/tag_bindings/async_client.py | 72 +- .../services/tag_bindings/client.py | 77 +- .../services/tag_bindings/pagers.py | 32 +- .../services/tag_bindings/transports/grpc.py | 104 +- .../tag_bindings/transports/grpc_asyncio.py | 101 +- .../services/tag_bindings/transports/rest.py | 333 ++- .../services/tag_holds/async_client.py | 64 +- .../services/tag_holds/client.py | 69 +- .../services/tag_holds/pagers.py | 16 +- .../services/tag_holds/transports/grpc.py | 102 +- .../tag_holds/transports/grpc_asyncio.py | 99 +- .../services/tag_holds/transports/rest.py | 259 +- .../services/tag_keys/async_client.py | 112 +- .../services/tag_keys/client.py | 117 +- .../services/tag_keys/pagers.py | 16 +- .../services/tag_keys/transports/grpc.py | 114 +- .../tag_keys/transports/grpc_asyncio.py | 111 +- .../services/tag_keys/transports/rest.py | 650 ++++- .../services/tag_values/async_client.py | 112 +- .../services/tag_values/client.py | 117 +- .../services/tag_values/pagers.py | 16 +- .../services/tag_values/transports/grpc.py | 114 +- .../tag_values/transports/grpc_asyncio.py | 111 +- .../services/tag_values/transports/rest.py | 650 ++++- ...adata_google.cloud.resourcemanager.v3.json | 210 +- .../gapic/resourcemanager_v3/test_folders.py | 56 + .../resourcemanager_v3/test_organizations.py | 26 + .../gapic/resourcemanager_v3/test_projects.py | 56 + .../resourcemanager_v3/test_tag_bindings.py | 22 + .../resourcemanager_v3/test_tag_holds.py | 17 + .../gapic/resourcemanager_v3/test_tag_keys.py | 47 + .../resourcemanager_v3/test_tag_values.py | 47 + .../cloud/resourcesettings/gapic_version.py | 2 +- .../resourcesettings_v1/gapic_version.py | 2 +- .../resource_settings_service/async_client.py | 56 +- .../resource_settings_service/client.py | 61 +- .../resource_settings_service/pagers.py | 16 +- .../transports/grpc.py | 96 +- .../transports/grpc_asyncio.py | 95 +- .../transports/rest.py | 204 +- ...data_google.cloud.resourcesettings.v1.json | 14 +- .../test_resource_settings_service.py | 14 + 313 files changed, 34461 insertions(+), 5542 deletions(-) diff --git a/packages/google-cloud-optimization/google/cloud/optimization/gapic_version.py b/packages/google-cloud-optimization/google/cloud/optimization/gapic_version.py index 402b34e179e9..558c8aab67c5 100644 --- a/packages/google-cloud-optimization/google/cloud/optimization/gapic_version.py +++ b/packages/google-cloud-optimization/google/cloud/optimization/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.9.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-optimization/google/cloud/optimization_v1/gapic_version.py b/packages/google-cloud-optimization/google/cloud/optimization_v1/gapic_version.py index 402b34e179e9..558c8aab67c5 100644 --- a/packages/google-cloud-optimization/google/cloud/optimization_v1/gapic_version.py +++ b/packages/google-cloud-optimization/google/cloud/optimization_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.9.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-optimization/google/cloud/optimization_v1/services/fleet_routing/async_client.py b/packages/google-cloud-optimization/google/cloud/optimization_v1/services/fleet_routing/async_client.py index eaf22cc84c9e..fd680c4fb252 100644 --- a/packages/google-cloud-optimization/google/cloud/optimization_v1/services/fleet_routing/async_client.py +++ b/packages/google-cloud-optimization/google/cloud/optimization_v1/services/fleet_routing/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -52,6 +53,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, FleetRoutingTransport from .transports.grpc_asyncio import FleetRoutingGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class FleetRoutingAsyncClient: """A service for optimizing vehicle tours. @@ -274,13 +284,35 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.optimization_v1.FleetRoutingAsyncClient`.", + extra={ + "serviceName": "google.cloud.optimization.v1.FleetRouting", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.optimization.v1.FleetRouting", + "credentialsType": None, + }, + ) + async def optimize_tours( self, request: Optional[Union[fleet_routing.OptimizeToursRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> fleet_routing.OptimizeToursResponse: r"""Sends an ``OptimizeToursRequest`` containing a ``ShipmentModel`` and returns an ``OptimizeToursResponse`` containing @@ -334,8 +366,10 @@ async def sample_optimize_tours(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.optimization_v1.types.OptimizeToursResponse: @@ -384,7 +418,7 @@ async def batch_optimize_tours( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Optimizes vehicle tours for one or more ``OptimizeToursRequest`` messages as a batch. @@ -445,8 +479,10 @@ async def sample_batch_optimize_tours(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -502,7 +538,7 @@ async def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -513,8 +549,10 @@ async def get_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. diff --git a/packages/google-cloud-optimization/google/cloud/optimization_v1/services/fleet_routing/client.py b/packages/google-cloud-optimization/google/cloud/optimization_v1/services/fleet_routing/client.py index 1e8b66a47f27..04f632a49918 100644 --- a/packages/google-cloud-optimization/google/cloud/optimization_v1/services/fleet_routing/client.py +++ b/packages/google-cloud-optimization/google/cloud/optimization_v1/services/fleet_routing/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -580,6 +590,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -642,13 +656,36 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.optimization_v1.FleetRoutingClient`.", + extra={ + "serviceName": "google.cloud.optimization.v1.FleetRouting", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.optimization.v1.FleetRouting", + "credentialsType": None, + }, + ) + def optimize_tours( self, request: Optional[Union[fleet_routing.OptimizeToursRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> fleet_routing.OptimizeToursResponse: r"""Sends an ``OptimizeToursRequest`` containing a ``ShipmentModel`` and returns an ``OptimizeToursResponse`` containing @@ -702,8 +739,10 @@ def sample_optimize_tours(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.optimization_v1.types.OptimizeToursResponse: @@ -750,7 +789,7 @@ def batch_optimize_tours( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Optimizes vehicle tours for one or more ``OptimizeToursRequest`` messages as a batch. @@ -811,8 +850,10 @@ def sample_batch_optimize_tours(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -879,7 +920,7 @@ def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -890,8 +931,10 @@ def get_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. diff --git a/packages/google-cloud-optimization/google/cloud/optimization_v1/services/fleet_routing/transports/grpc.py b/packages/google-cloud-optimization/google/cloud/optimization_v1/services/fleet_routing/transports/grpc.py index 07ce13a7de88..863261bc52a6 100644 --- a/packages/google-cloud-optimization/google/cloud/optimization_v1/services/fleet_routing/transports/grpc.py +++ b/packages/google-cloud-optimization/google/cloud/optimization_v1/services/fleet_routing/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -21,12 +24,90 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.optimization_v1.types import fleet_routing from .base import DEFAULT_CLIENT_INFO, FleetRoutingTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.optimization.v1.FleetRouting", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.optimization.v1.FleetRouting", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class FleetRoutingGrpcTransport(FleetRoutingTransport): """gRPC backend transport for FleetRouting. @@ -203,7 +284,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -267,7 +353,9 @@ def operations_client(self) -> operations_v1.OperationsClient: """ # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + self._operations_client = operations_v1.OperationsClient( + self._logged_channel + ) # Return the client from cache. return self._operations_client @@ -308,7 +396,7 @@ def optimize_tours( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "optimize_tours" not in self._stubs: - self._stubs["optimize_tours"] = self.grpc_channel.unary_unary( + self._stubs["optimize_tours"] = self._logged_channel.unary_unary( "/google.cloud.optimization.v1.FleetRouting/OptimizeTours", request_serializer=fleet_routing.OptimizeToursRequest.serialize, response_deserializer=fleet_routing.OptimizeToursResponse.deserialize, @@ -344,7 +432,7 @@ def batch_optimize_tours( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "batch_optimize_tours" not in self._stubs: - self._stubs["batch_optimize_tours"] = self.grpc_channel.unary_unary( + self._stubs["batch_optimize_tours"] = self._logged_channel.unary_unary( "/google.cloud.optimization.v1.FleetRouting/BatchOptimizeTours", request_serializer=fleet_routing.BatchOptimizeToursRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -352,7 +440,7 @@ def batch_optimize_tours( return self._stubs["batch_optimize_tours"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def get_operation( @@ -364,7 +452,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, diff --git a/packages/google-cloud-optimization/google/cloud/optimization_v1/services/fleet_routing/transports/grpc_asyncio.py b/packages/google-cloud-optimization/google/cloud/optimization_v1/services/fleet_routing/transports/grpc_asyncio.py index 2177d24ec96c..661a700f6eef 100644 --- a/packages/google-cloud-optimization/google/cloud/optimization_v1/services/fleet_routing/transports/grpc_asyncio.py +++ b/packages/google-cloud-optimization/google/cloud/optimization_v1/services/fleet_routing/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -23,14 +26,93 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.optimization_v1.types import fleet_routing from .base import DEFAULT_CLIENT_INFO, FleetRoutingTransport from .grpc import FleetRoutingGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.optimization.v1.FleetRouting", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.optimization.v1.FleetRouting", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class FleetRoutingGrpcAsyncIOTransport(FleetRoutingTransport): """gRPC AsyncIO backend transport for FleetRouting. @@ -250,10 +332,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -276,7 +361,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel + self._logged_channel ) # Return the client from cache. @@ -319,7 +404,7 @@ def optimize_tours( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "optimize_tours" not in self._stubs: - self._stubs["optimize_tours"] = self.grpc_channel.unary_unary( + self._stubs["optimize_tours"] = self._logged_channel.unary_unary( "/google.cloud.optimization.v1.FleetRouting/OptimizeTours", request_serializer=fleet_routing.OptimizeToursRequest.serialize, response_deserializer=fleet_routing.OptimizeToursResponse.deserialize, @@ -357,7 +442,7 @@ def batch_optimize_tours( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "batch_optimize_tours" not in self._stubs: - self._stubs["batch_optimize_tours"] = self.grpc_channel.unary_unary( + self._stubs["batch_optimize_tours"] = self._logged_channel.unary_unary( "/google.cloud.optimization.v1.FleetRouting/BatchOptimizeTours", request_serializer=fleet_routing.BatchOptimizeToursRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -408,7 +493,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: @@ -424,7 +509,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, diff --git a/packages/google-cloud-optimization/google/cloud/optimization_v1/services/fleet_routing/transports/rest.py b/packages/google-cloud-optimization/google/cloud/optimization_v1/services/fleet_routing/transports/rest.py index 1cf5825d1407..a90db1f29f4b 100644 --- a/packages/google-cloud-optimization/google/cloud/optimization_v1/services/fleet_routing/transports/rest.py +++ b/packages/google-cloud-optimization/google/cloud/optimization_v1/services/fleet_routing/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -38,6 +38,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -86,8 +94,10 @@ def post_optimize_tours(self, response): def pre_batch_optimize_tours( self, request: fleet_routing.BatchOptimizeToursRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[fleet_routing.BatchOptimizeToursRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + fleet_routing.BatchOptimizeToursRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for batch_optimize_tours Override in a subclass to manipulate the request or metadata @@ -109,8 +119,10 @@ def post_batch_optimize_tours( def pre_optimize_tours( self, request: fleet_routing.OptimizeToursRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[fleet_routing.OptimizeToursRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + fleet_routing.OptimizeToursRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for optimize_tours Override in a subclass to manipulate the request or metadata @@ -132,8 +144,10 @@ def post_optimize_tours( def pre_get_operation( self, request: operations_pb2.GetOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.GetOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.GetOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_operation Override in a subclass to manipulate the request or metadata @@ -335,7 +349,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the batch optimize tours method over HTTP. @@ -351,8 +365,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -365,6 +381,7 @@ def __call__( http_options = ( _BaseFleetRoutingRestTransport._BaseBatchOptimizeTours._get_http_options() ) + request, metadata = self._interceptor.pre_batch_optimize_tours( request, metadata ) @@ -381,6 +398,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.optimization_v1.FleetRoutingClient.BatchOptimizeTours", + extra={ + "serviceName": "google.cloud.optimization.v1.FleetRouting", + "rpcName": "BatchOptimizeTours", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = FleetRoutingRestTransport._BatchOptimizeTours._get_response( self._host, @@ -400,7 +444,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_batch_optimize_tours(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.optimization_v1.FleetRoutingClient.batch_optimize_tours", + extra={ + "serviceName": "google.cloud.optimization.v1.FleetRouting", + "rpcName": "BatchOptimizeTours", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _OptimizeTours( @@ -438,7 +504,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> fleet_routing.OptimizeToursResponse: r"""Call the optimize tours method over HTTP. @@ -451,8 +517,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.fleet_routing.OptimizeToursResponse: @@ -467,6 +535,7 @@ def __call__( http_options = ( _BaseFleetRoutingRestTransport._BaseOptimizeTours._get_http_options() ) + request, metadata = self._interceptor.pre_optimize_tours(request, metadata) transcoded_request = _BaseFleetRoutingRestTransport._BaseOptimizeTours._get_transcoded_request( http_options, request @@ -481,6 +550,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.optimization_v1.FleetRoutingClient.OptimizeTours", + extra={ + "serviceName": "google.cloud.optimization.v1.FleetRouting", + "rpcName": "OptimizeTours", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = FleetRoutingRestTransport._OptimizeTours._get_response( self._host, @@ -502,7 +598,31 @@ def __call__( pb_resp = fleet_routing.OptimizeToursResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_optimize_tours(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = fleet_routing.OptimizeToursResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.optimization_v1.FleetRoutingClient.optimize_tours", + extra={ + "serviceName": "google.cloud.optimization.v1.FleetRouting", + "rpcName": "OptimizeTours", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property @@ -561,7 +681,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the get operation method over HTTP. @@ -571,8 +691,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: operations_pb2.Operation: Response from GetOperation method. @@ -581,6 +703,7 @@ def __call__( http_options = ( _BaseFleetRoutingRestTransport._BaseGetOperation._get_http_options() ) + request, metadata = self._interceptor.pre_get_operation(request, metadata) transcoded_request = _BaseFleetRoutingRestTransport._BaseGetOperation._get_transcoded_request( http_options, request @@ -593,6 +716,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.optimization_v1.FleetRoutingClient.GetOperation", + extra={ + "serviceName": "google.cloud.optimization.v1.FleetRouting", + "rpcName": "GetOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = FleetRoutingRestTransport._GetOperation._get_response( self._host, @@ -612,6 +762,27 @@ def __call__( resp = operations_pb2.Operation() resp = json_format.Parse(content, resp) resp = self._interceptor.post_get_operation(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.optimization_v1.FleetRoutingAsyncClient.GetOperation", + extra={ + "serviceName": "google.cloud.optimization.v1.FleetRouting", + "rpcName": "GetOperation", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property diff --git a/packages/google-cloud-optimization/samples/generated_samples/snippet_metadata_google.cloud.optimization.v1.json b/packages/google-cloud-optimization/samples/generated_samples/snippet_metadata_google.cloud.optimization.v1.json index 9f867ccc68ed..0666a7af3b7c 100644 --- a/packages/google-cloud-optimization/samples/generated_samples/snippet_metadata_google.cloud.optimization.v1.json +++ b/packages/google-cloud-optimization/samples/generated_samples/snippet_metadata_google.cloud.optimization.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-optimization", - "version": "1.9.1" + "version": "0.1.0" }, "snippets": [ { @@ -43,7 +43,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -119,7 +119,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -196,7 +196,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.optimization_v1.types.OptimizeToursResponse", @@ -272,7 +272,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.optimization_v1.types.OptimizeToursResponse", diff --git a/packages/google-cloud-optimization/tests/unit/gapic/optimization_v1/test_fleet_routing.py b/packages/google-cloud-optimization/tests/unit/gapic/optimization_v1/test_fleet_routing.py index f575b9fab9cb..1f050ecf9ea6 100644 --- a/packages/google-cloud-optimization/tests/unit/gapic/optimization_v1/test_fleet_routing.py +++ b/packages/google-cloud-optimization/tests/unit/gapic/optimization_v1/test_fleet_routing.py @@ -1659,6 +1659,7 @@ def test_optimize_tours_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.optimize_tours(request) @@ -1784,6 +1785,7 @@ def test_batch_optimize_tours_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.batch_optimize_tours(request) @@ -2056,6 +2058,7 @@ def test_optimize_tours_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.optimize_tours(request) @@ -2092,6 +2095,7 @@ def test_optimize_tours_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.optimize_tours(request) # Establish that the response is the type that we expect. @@ -2133,6 +2137,7 @@ def test_optimize_tours_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = fleet_routing.OptimizeToursResponse.to_json( fleet_routing.OptimizeToursResponse() ) @@ -2179,6 +2184,7 @@ def test_batch_optimize_tours_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.batch_optimize_tours(request) @@ -2209,6 +2215,7 @@ def test_batch_optimize_tours_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.batch_optimize_tours(request) # Establish that the response is the type that we expect. @@ -2250,6 +2257,7 @@ def test_batch_optimize_tours_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -2296,6 +2304,7 @@ def test_get_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_operation(request) @@ -2326,6 +2335,7 @@ def test_get_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_operation(request) diff --git a/packages/google-cloud-os-config/google/cloud/osconfig/gapic_version.py b/packages/google-cloud-os-config/google/cloud/osconfig/gapic_version.py index ef9777764da2..558c8aab67c5 100644 --- a/packages/google-cloud-os-config/google/cloud/osconfig/gapic_version.py +++ b/packages/google-cloud-os-config/google/cloud/osconfig/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.18.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-os-config/google/cloud/osconfig_v1/gapic_version.py b/packages/google-cloud-os-config/google/cloud/osconfig_v1/gapic_version.py index ef9777764da2..558c8aab67c5 100644 --- a/packages/google-cloud-os-config/google/cloud/osconfig_v1/gapic_version.py +++ b/packages/google-cloud-os-config/google/cloud/osconfig_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.18.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/async_client.py b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/async_client.py index 04a0ae0e8e95..ed6c774fef65 100644 --- a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/async_client.py +++ b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -53,6 +54,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, OsConfigServiceTransport from .transports.grpc_asyncio import OsConfigServiceGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class OsConfigServiceAsyncClient: """OS Config API @@ -271,13 +281,35 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.osconfig_v1.OsConfigServiceAsyncClient`.", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "credentialsType": None, + }, + ) + async def execute_patch_job( self, request: Optional[Union[patch_jobs.ExecutePatchJobRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_jobs.PatchJob: r"""Patch VM instances by creating and running a patch job. @@ -316,8 +348,10 @@ async def sample_execute_patch_job(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.PatchJob: @@ -372,7 +406,7 @@ async def get_patch_job( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_jobs.PatchJob: r"""Get the patch job. This can be used to track the progress of an ongoing patch job or review the details @@ -418,8 +452,10 @@ async def sample_get_patch_job(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.PatchJob: @@ -487,7 +523,7 @@ async def cancel_patch_job( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_jobs.PatchJob: r"""Cancel a patch job. The patch job must be active. Canceled patch jobs cannot be restarted. @@ -524,8 +560,10 @@ async def sample_cancel_patch_job(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.PatchJob: @@ -580,7 +618,7 @@ async def list_patch_jobs( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListPatchJobsAsyncPager: r"""Get a list of patch jobs. @@ -623,8 +661,10 @@ async def sample_list_patch_jobs(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.services.os_config_service.pagers.ListPatchJobsAsyncPager: @@ -701,7 +741,7 @@ async def list_patch_job_instance_details( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListPatchJobInstanceDetailsAsyncPager: r"""Get a list of instance details for a given patch job. @@ -746,8 +786,10 @@ async def sample_list_patch_job_instance_details(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.services.os_config_service.pagers.ListPatchJobInstanceDetailsAsyncPager: @@ -826,7 +868,7 @@ async def create_patch_deployment( patch_deployment_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_deployments.PatchDeployment: r"""Create an OS Config patch deployment. @@ -892,8 +934,10 @@ async def sample_create_patch_deployment(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.PatchDeployment: @@ -964,7 +1008,7 @@ async def get_patch_deployment( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_deployments.PatchDeployment: r"""Get an OS Config patch deployment. @@ -1008,8 +1052,10 @@ async def sample_get_patch_deployment(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.PatchDeployment: @@ -1076,7 +1122,7 @@ async def list_patch_deployments( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListPatchDeploymentsAsyncPager: r"""Get a page of OS Config patch deployments. @@ -1121,8 +1167,10 @@ async def sample_list_patch_deployments(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.services.os_config_service.pagers.ListPatchDeploymentsAsyncPager: @@ -1199,7 +1247,7 @@ async def delete_patch_deployment( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Delete an OS Config patch deployment. @@ -1240,8 +1288,10 @@ async def sample_delete_patch_deployment(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ # Create or coerce a protobuf request object. # - Quick check: If we got a request object, we should *not* have @@ -1296,7 +1346,7 @@ async def update_patch_deployment( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_deployments.PatchDeployment: r"""Update an OS Config patch deployment. @@ -1347,8 +1397,10 @@ async def sample_update_patch_deployment(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.PatchDeployment: @@ -1419,7 +1471,7 @@ async def pause_patch_deployment( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_deployments.PatchDeployment: r"""Change state of patch deployment to "PAUSED". Patch deployment in paused state doesn't generate patch @@ -1465,8 +1517,10 @@ async def sample_pause_patch_deployment(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.PatchDeployment: @@ -1533,7 +1587,7 @@ async def resume_patch_deployment( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_deployments.PatchDeployment: r"""Change state of patch deployment back to "ACTIVE". Patch deployment in active state continues to generate @@ -1579,8 +1633,10 @@ async def sample_resume_patch_deployment(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.PatchDeployment: diff --git a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/client.py b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/client.py index f2e9cadb390c..370827d901c1 100644 --- a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/client.py +++ b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.protobuf import duration_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -626,6 +636,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -691,13 +705,36 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.osconfig_v1.OsConfigServiceClient`.", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "credentialsType": None, + }, + ) + def execute_patch_job( self, request: Optional[Union[patch_jobs.ExecutePatchJobRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_jobs.PatchJob: r"""Patch VM instances by creating and running a patch job. @@ -736,8 +773,10 @@ def sample_execute_patch_job(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.PatchJob: @@ -790,7 +829,7 @@ def get_patch_job( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_jobs.PatchJob: r"""Get the patch job. This can be used to track the progress of an ongoing patch job or review the details @@ -836,8 +875,10 @@ def sample_get_patch_job(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.PatchJob: @@ -902,7 +943,7 @@ def cancel_patch_job( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_jobs.PatchJob: r"""Cancel a patch job. The patch job must be active. Canceled patch jobs cannot be restarted. @@ -939,8 +980,10 @@ def sample_cancel_patch_job(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.PatchJob: @@ -993,7 +1036,7 @@ def list_patch_jobs( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListPatchJobsPager: r"""Get a list of patch jobs. @@ -1036,8 +1079,10 @@ def sample_list_patch_jobs(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.services.os_config_service.pagers.ListPatchJobsPager: @@ -1111,7 +1156,7 @@ def list_patch_job_instance_details( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListPatchJobInstanceDetailsPager: r"""Get a list of instance details for a given patch job. @@ -1156,8 +1201,10 @@ def sample_list_patch_job_instance_details(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.services.os_config_service.pagers.ListPatchJobInstanceDetailsPager: @@ -1235,7 +1282,7 @@ def create_patch_deployment( patch_deployment_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_deployments.PatchDeployment: r"""Create an OS Config patch deployment. @@ -1301,8 +1348,10 @@ def sample_create_patch_deployment(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.PatchDeployment: @@ -1370,7 +1419,7 @@ def get_patch_deployment( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_deployments.PatchDeployment: r"""Get an OS Config patch deployment. @@ -1414,8 +1463,10 @@ def sample_get_patch_deployment(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.PatchDeployment: @@ -1479,7 +1530,7 @@ def list_patch_deployments( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListPatchDeploymentsPager: r"""Get a page of OS Config patch deployments. @@ -1524,8 +1575,10 @@ def sample_list_patch_deployments(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.services.os_config_service.pagers.ListPatchDeploymentsPager: @@ -1599,7 +1652,7 @@ def delete_patch_deployment( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Delete an OS Config patch deployment. @@ -1640,8 +1693,10 @@ def sample_delete_patch_deployment(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ # Create or coerce a protobuf request object. # - Quick check: If we got a request object, we should *not* have @@ -1693,7 +1748,7 @@ def update_patch_deployment( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_deployments.PatchDeployment: r"""Update an OS Config patch deployment. @@ -1744,8 +1799,10 @@ def sample_update_patch_deployment(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.PatchDeployment: @@ -1813,7 +1870,7 @@ def pause_patch_deployment( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_deployments.PatchDeployment: r"""Change state of patch deployment to "PAUSED". Patch deployment in paused state doesn't generate patch @@ -1859,8 +1916,10 @@ def sample_pause_patch_deployment(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.PatchDeployment: @@ -1924,7 +1983,7 @@ def resume_patch_deployment( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_deployments.PatchDeployment: r"""Change state of patch deployment back to "ACTIVE". Patch deployment in active state continues to generate @@ -1970,8 +2029,10 @@ def sample_resume_patch_deployment(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.PatchDeployment: diff --git a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/pagers.py b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/pagers.py index 1002030830df..6ff130784421 100644 --- a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/pagers.py +++ b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -81,8 +81,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = patch_jobs.ListPatchJobsRequest(request) @@ -141,7 +143,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -155,8 +157,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = patch_jobs.ListPatchJobsRequest(request) @@ -219,7 +223,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -233,8 +237,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = patch_jobs.ListPatchJobInstanceDetailsRequest(request) @@ -295,7 +301,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -309,8 +315,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = patch_jobs.ListPatchJobInstanceDetailsRequest(request) @@ -375,7 +383,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -389,8 +397,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = patch_deployments.ListPatchDeploymentsRequest(request) @@ -451,7 +461,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -465,8 +475,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = patch_deployments.ListPatchDeploymentsRequest(request) diff --git a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/transports/grpc.py b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/transports/grpc.py index f39ce31eb33b..c9cff26dbe68 100644 --- a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/transports/grpc.py +++ b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -21,12 +24,90 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.protobuf import empty_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.osconfig_v1.types import patch_deployments, patch_jobs from .base import DEFAULT_CLIENT_INFO, OsConfigServiceTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class OsConfigServiceGrpcTransport(OsConfigServiceTransport): """gRPC backend transport for OsConfigService. @@ -184,7 +265,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -259,7 +345,7 @@ def execute_patch_job( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "execute_patch_job" not in self._stubs: - self._stubs["execute_patch_job"] = self.grpc_channel.unary_unary( + self._stubs["execute_patch_job"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/ExecutePatchJob", request_serializer=patch_jobs.ExecutePatchJobRequest.serialize, response_deserializer=patch_jobs.PatchJob.deserialize, @@ -287,7 +373,7 @@ def get_patch_job( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_patch_job" not in self._stubs: - self._stubs["get_patch_job"] = self.grpc_channel.unary_unary( + self._stubs["get_patch_job"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/GetPatchJob", request_serializer=patch_jobs.GetPatchJobRequest.serialize, response_deserializer=patch_jobs.PatchJob.deserialize, @@ -314,7 +400,7 @@ def cancel_patch_job( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "cancel_patch_job" not in self._stubs: - self._stubs["cancel_patch_job"] = self.grpc_channel.unary_unary( + self._stubs["cancel_patch_job"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/CancelPatchJob", request_serializer=patch_jobs.CancelPatchJobRequest.serialize, response_deserializer=patch_jobs.PatchJob.deserialize, @@ -340,7 +426,7 @@ def list_patch_jobs( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_patch_jobs" not in self._stubs: - self._stubs["list_patch_jobs"] = self.grpc_channel.unary_unary( + self._stubs["list_patch_jobs"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/ListPatchJobs", request_serializer=patch_jobs.ListPatchJobsRequest.serialize, response_deserializer=patch_jobs.ListPatchJobsResponse.deserialize, @@ -372,7 +458,7 @@ def list_patch_job_instance_details( if "list_patch_job_instance_details" not in self._stubs: self._stubs[ "list_patch_job_instance_details" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/ListPatchJobInstanceDetails", request_serializer=patch_jobs.ListPatchJobInstanceDetailsRequest.serialize, response_deserializer=patch_jobs.ListPatchJobInstanceDetailsResponse.deserialize, @@ -401,7 +487,7 @@ def create_patch_deployment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_patch_deployment" not in self._stubs: - self._stubs["create_patch_deployment"] = self.grpc_channel.unary_unary( + self._stubs["create_patch_deployment"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/CreatePatchDeployment", request_serializer=patch_deployments.CreatePatchDeploymentRequest.serialize, response_deserializer=patch_deployments.PatchDeployment.deserialize, @@ -429,7 +515,7 @@ def get_patch_deployment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_patch_deployment" not in self._stubs: - self._stubs["get_patch_deployment"] = self.grpc_channel.unary_unary( + self._stubs["get_patch_deployment"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/GetPatchDeployment", request_serializer=patch_deployments.GetPatchDeploymentRequest.serialize, response_deserializer=patch_deployments.PatchDeployment.deserialize, @@ -458,7 +544,7 @@ def list_patch_deployments( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_patch_deployments" not in self._stubs: - self._stubs["list_patch_deployments"] = self.grpc_channel.unary_unary( + self._stubs["list_patch_deployments"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/ListPatchDeployments", request_serializer=patch_deployments.ListPatchDeploymentsRequest.serialize, response_deserializer=patch_deployments.ListPatchDeploymentsResponse.deserialize, @@ -484,7 +570,7 @@ def delete_patch_deployment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_patch_deployment" not in self._stubs: - self._stubs["delete_patch_deployment"] = self.grpc_channel.unary_unary( + self._stubs["delete_patch_deployment"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/DeletePatchDeployment", request_serializer=patch_deployments.DeletePatchDeploymentRequest.serialize, response_deserializer=empty_pb2.Empty.FromString, @@ -513,7 +599,7 @@ def update_patch_deployment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_patch_deployment" not in self._stubs: - self._stubs["update_patch_deployment"] = self.grpc_channel.unary_unary( + self._stubs["update_patch_deployment"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/UpdatePatchDeployment", request_serializer=patch_deployments.UpdatePatchDeploymentRequest.serialize, response_deserializer=patch_deployments.PatchDeployment.deserialize, @@ -544,7 +630,7 @@ def pause_patch_deployment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "pause_patch_deployment" not in self._stubs: - self._stubs["pause_patch_deployment"] = self.grpc_channel.unary_unary( + self._stubs["pause_patch_deployment"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/PausePatchDeployment", request_serializer=patch_deployments.PausePatchDeploymentRequest.serialize, response_deserializer=patch_deployments.PatchDeployment.deserialize, @@ -575,7 +661,7 @@ def resume_patch_deployment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "resume_patch_deployment" not in self._stubs: - self._stubs["resume_patch_deployment"] = self.grpc_channel.unary_unary( + self._stubs["resume_patch_deployment"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/ResumePatchDeployment", request_serializer=patch_deployments.ResumePatchDeploymentRequest.serialize, response_deserializer=patch_deployments.PatchDeployment.deserialize, @@ -583,7 +669,7 @@ def resume_patch_deployment( return self._stubs["resume_patch_deployment"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/transports/grpc_asyncio.py b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/transports/grpc_asyncio.py index e2a801da1e5d..afc8a3403d2d 100644 --- a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -23,14 +26,93 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.protobuf import empty_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.osconfig_v1.types import patch_deployments, patch_jobs from .base import DEFAULT_CLIENT_INFO, OsConfigServiceTransport from .grpc import OsConfigServiceGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class OsConfigServiceGrpcAsyncIOTransport(OsConfigServiceTransport): """gRPC AsyncIO backend transport for OsConfigService. @@ -231,10 +313,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -267,7 +352,7 @@ def execute_patch_job( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "execute_patch_job" not in self._stubs: - self._stubs["execute_patch_job"] = self.grpc_channel.unary_unary( + self._stubs["execute_patch_job"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/ExecutePatchJob", request_serializer=patch_jobs.ExecutePatchJobRequest.serialize, response_deserializer=patch_jobs.PatchJob.deserialize, @@ -295,7 +380,7 @@ def get_patch_job( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_patch_job" not in self._stubs: - self._stubs["get_patch_job"] = self.grpc_channel.unary_unary( + self._stubs["get_patch_job"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/GetPatchJob", request_serializer=patch_jobs.GetPatchJobRequest.serialize, response_deserializer=patch_jobs.PatchJob.deserialize, @@ -322,7 +407,7 @@ def cancel_patch_job( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "cancel_patch_job" not in self._stubs: - self._stubs["cancel_patch_job"] = self.grpc_channel.unary_unary( + self._stubs["cancel_patch_job"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/CancelPatchJob", request_serializer=patch_jobs.CancelPatchJobRequest.serialize, response_deserializer=patch_jobs.PatchJob.deserialize, @@ -350,7 +435,7 @@ def list_patch_jobs( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_patch_jobs" not in self._stubs: - self._stubs["list_patch_jobs"] = self.grpc_channel.unary_unary( + self._stubs["list_patch_jobs"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/ListPatchJobs", request_serializer=patch_jobs.ListPatchJobsRequest.serialize, response_deserializer=patch_jobs.ListPatchJobsResponse.deserialize, @@ -382,7 +467,7 @@ def list_patch_job_instance_details( if "list_patch_job_instance_details" not in self._stubs: self._stubs[ "list_patch_job_instance_details" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/ListPatchJobInstanceDetails", request_serializer=patch_jobs.ListPatchJobInstanceDetailsRequest.serialize, response_deserializer=patch_jobs.ListPatchJobInstanceDetailsResponse.deserialize, @@ -411,7 +496,7 @@ def create_patch_deployment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_patch_deployment" not in self._stubs: - self._stubs["create_patch_deployment"] = self.grpc_channel.unary_unary( + self._stubs["create_patch_deployment"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/CreatePatchDeployment", request_serializer=patch_deployments.CreatePatchDeploymentRequest.serialize, response_deserializer=patch_deployments.PatchDeployment.deserialize, @@ -440,7 +525,7 @@ def get_patch_deployment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_patch_deployment" not in self._stubs: - self._stubs["get_patch_deployment"] = self.grpc_channel.unary_unary( + self._stubs["get_patch_deployment"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/GetPatchDeployment", request_serializer=patch_deployments.GetPatchDeploymentRequest.serialize, response_deserializer=patch_deployments.PatchDeployment.deserialize, @@ -469,7 +554,7 @@ def list_patch_deployments( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_patch_deployments" not in self._stubs: - self._stubs["list_patch_deployments"] = self.grpc_channel.unary_unary( + self._stubs["list_patch_deployments"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/ListPatchDeployments", request_serializer=patch_deployments.ListPatchDeploymentsRequest.serialize, response_deserializer=patch_deployments.ListPatchDeploymentsResponse.deserialize, @@ -497,7 +582,7 @@ def delete_patch_deployment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_patch_deployment" not in self._stubs: - self._stubs["delete_patch_deployment"] = self.grpc_channel.unary_unary( + self._stubs["delete_patch_deployment"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/DeletePatchDeployment", request_serializer=patch_deployments.DeletePatchDeploymentRequest.serialize, response_deserializer=empty_pb2.Empty.FromString, @@ -526,7 +611,7 @@ def update_patch_deployment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_patch_deployment" not in self._stubs: - self._stubs["update_patch_deployment"] = self.grpc_channel.unary_unary( + self._stubs["update_patch_deployment"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/UpdatePatchDeployment", request_serializer=patch_deployments.UpdatePatchDeploymentRequest.serialize, response_deserializer=patch_deployments.PatchDeployment.deserialize, @@ -557,7 +642,7 @@ def pause_patch_deployment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "pause_patch_deployment" not in self._stubs: - self._stubs["pause_patch_deployment"] = self.grpc_channel.unary_unary( + self._stubs["pause_patch_deployment"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/PausePatchDeployment", request_serializer=patch_deployments.PausePatchDeploymentRequest.serialize, response_deserializer=patch_deployments.PatchDeployment.deserialize, @@ -588,7 +673,7 @@ def resume_patch_deployment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "resume_patch_deployment" not in self._stubs: - self._stubs["resume_patch_deployment"] = self.grpc_channel.unary_unary( + self._stubs["resume_patch_deployment"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigService/ResumePatchDeployment", request_serializer=patch_deployments.ResumePatchDeploymentRequest.serialize, response_deserializer=patch_deployments.PatchDeployment.deserialize, @@ -666,7 +751,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/transports/rest.py b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/transports/rest.py index 04244dd2a285..ef56b649cbaa 100644 --- a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/transports/rest.py +++ b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_service/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -38,6 +38,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -162,8 +170,10 @@ def post_update_patch_deployment(self, response): def pre_cancel_patch_job( self, request: patch_jobs.CancelPatchJobRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[patch_jobs.CancelPatchJobRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + patch_jobs.CancelPatchJobRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for cancel_patch_job Override in a subclass to manipulate the request or metadata @@ -185,9 +195,10 @@ def post_cancel_patch_job( def pre_create_patch_deployment( self, request: patch_deployments.CreatePatchDeploymentRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - patch_deployments.CreatePatchDeploymentRequest, Sequence[Tuple[str, str]] + patch_deployments.CreatePatchDeploymentRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for create_patch_deployment @@ -210,9 +221,10 @@ def post_create_patch_deployment( def pre_delete_patch_deployment( self, request: patch_deployments.DeletePatchDeploymentRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - patch_deployments.DeletePatchDeploymentRequest, Sequence[Tuple[str, str]] + patch_deployments.DeletePatchDeploymentRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for delete_patch_deployment @@ -224,8 +236,10 @@ def pre_delete_patch_deployment( def pre_execute_patch_job( self, request: patch_jobs.ExecutePatchJobRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[patch_jobs.ExecutePatchJobRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + patch_jobs.ExecutePatchJobRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for execute_patch_job Override in a subclass to manipulate the request or metadata @@ -247,8 +261,11 @@ def post_execute_patch_job( def pre_get_patch_deployment( self, request: patch_deployments.GetPatchDeploymentRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[patch_deployments.GetPatchDeploymentRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + patch_deployments.GetPatchDeploymentRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for get_patch_deployment Override in a subclass to manipulate the request or metadata @@ -270,8 +287,8 @@ def post_get_patch_deployment( def pre_get_patch_job( self, request: patch_jobs.GetPatchJobRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[patch_jobs.GetPatchJobRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[patch_jobs.GetPatchJobRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for get_patch_job Override in a subclass to manipulate the request or metadata @@ -291,9 +308,10 @@ def post_get_patch_job(self, response: patch_jobs.PatchJob) -> patch_jobs.PatchJ def pre_list_patch_deployments( self, request: patch_deployments.ListPatchDeploymentsRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - patch_deployments.ListPatchDeploymentsRequest, Sequence[Tuple[str, str]] + patch_deployments.ListPatchDeploymentsRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for list_patch_deployments @@ -316,9 +334,10 @@ def post_list_patch_deployments( def pre_list_patch_job_instance_details( self, request: patch_jobs.ListPatchJobInstanceDetailsRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - patch_jobs.ListPatchJobInstanceDetailsRequest, Sequence[Tuple[str, str]] + patch_jobs.ListPatchJobInstanceDetailsRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for list_patch_job_instance_details @@ -341,8 +360,10 @@ def post_list_patch_job_instance_details( def pre_list_patch_jobs( self, request: patch_jobs.ListPatchJobsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[patch_jobs.ListPatchJobsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + patch_jobs.ListPatchJobsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_patch_jobs Override in a subclass to manipulate the request or metadata @@ -364,9 +385,10 @@ def post_list_patch_jobs( def pre_pause_patch_deployment( self, request: patch_deployments.PausePatchDeploymentRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - patch_deployments.PausePatchDeploymentRequest, Sequence[Tuple[str, str]] + patch_deployments.PausePatchDeploymentRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for pause_patch_deployment @@ -389,9 +411,10 @@ def post_pause_patch_deployment( def pre_resume_patch_deployment( self, request: patch_deployments.ResumePatchDeploymentRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - patch_deployments.ResumePatchDeploymentRequest, Sequence[Tuple[str, str]] + patch_deployments.ResumePatchDeploymentRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for resume_patch_deployment @@ -414,9 +437,10 @@ def post_resume_patch_deployment( def pre_update_patch_deployment( self, request: patch_deployments.UpdatePatchDeploymentRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - patch_deployments.UpdatePatchDeploymentRequest, Sequence[Tuple[str, str]] + patch_deployments.UpdatePatchDeploymentRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for update_patch_deployment @@ -562,7 +586,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_jobs.PatchJob: r"""Call the cancel patch job method over HTTP. @@ -572,8 +596,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.patch_jobs.PatchJob: @@ -593,6 +619,7 @@ def __call__( http_options = ( _BaseOsConfigServiceRestTransport._BaseCancelPatchJob._get_http_options() ) + request, metadata = self._interceptor.pre_cancel_patch_job( request, metadata ) @@ -609,6 +636,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigServiceClient.CancelPatchJob", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "CancelPatchJob", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigServiceRestTransport._CancelPatchJob._get_response( self._host, @@ -630,7 +684,29 @@ def __call__( pb_resp = patch_jobs.PatchJob.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_cancel_patch_job(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = patch_jobs.PatchJob.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigServiceClient.cancel_patch_job", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "CancelPatchJob", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _CreatePatchDeployment( @@ -669,7 +745,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_deployments.PatchDeployment: r"""Call the create patch deployment method over HTTP. @@ -680,8 +756,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.patch_deployments.PatchDeployment: @@ -697,6 +775,7 @@ def __call__( http_options = ( _BaseOsConfigServiceRestTransport._BaseCreatePatchDeployment._get_http_options() ) + request, metadata = self._interceptor.pre_create_patch_deployment( request, metadata ) @@ -713,6 +792,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigServiceClient.CreatePatchDeployment", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "CreatePatchDeployment", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( OsConfigServiceRestTransport._CreatePatchDeployment._get_response( @@ -736,7 +842,31 @@ def __call__( pb_resp = patch_deployments.PatchDeployment.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_patch_deployment(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = patch_deployments.PatchDeployment.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigServiceClient.create_patch_deployment", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "CreatePatchDeployment", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DeletePatchDeployment( @@ -774,7 +904,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): r"""Call the delete patch deployment method over HTTP. @@ -785,13 +915,16 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ http_options = ( _BaseOsConfigServiceRestTransport._BaseDeletePatchDeployment._get_http_options() ) + request, metadata = self._interceptor.pre_delete_patch_deployment( request, metadata ) @@ -804,6 +937,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigServiceClient.DeletePatchDeployment", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "DeletePatchDeployment", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( OsConfigServiceRestTransport._DeletePatchDeployment._get_response( @@ -856,7 +1016,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_jobs.PatchJob: r"""Call the execute patch job method over HTTP. @@ -868,8 +1028,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.patch_jobs.PatchJob: @@ -889,6 +1051,7 @@ def __call__( http_options = ( _BaseOsConfigServiceRestTransport._BaseExecutePatchJob._get_http_options() ) + request, metadata = self._interceptor.pre_execute_patch_job( request, metadata ) @@ -905,6 +1068,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigServiceClient.ExecutePatchJob", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "ExecutePatchJob", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigServiceRestTransport._ExecutePatchJob._get_response( self._host, @@ -926,7 +1116,29 @@ def __call__( pb_resp = patch_jobs.PatchJob.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_execute_patch_job(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = patch_jobs.PatchJob.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigServiceClient.execute_patch_job", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "ExecutePatchJob", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetPatchDeployment( @@ -964,7 +1176,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_deployments.PatchDeployment: r"""Call the get patch deployment method over HTTP. @@ -975,8 +1187,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.patch_deployments.PatchDeployment: @@ -992,6 +1206,7 @@ def __call__( http_options = ( _BaseOsConfigServiceRestTransport._BaseGetPatchDeployment._get_http_options() ) + request, metadata = self._interceptor.pre_get_patch_deployment( request, metadata ) @@ -1004,6 +1219,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigServiceClient.GetPatchDeployment", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "GetPatchDeployment", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigServiceRestTransport._GetPatchDeployment._get_response( self._host, @@ -1024,7 +1266,31 @@ def __call__( pb_resp = patch_deployments.PatchDeployment.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_patch_deployment(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = patch_deployments.PatchDeployment.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigServiceClient.get_patch_deployment", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "GetPatchDeployment", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetPatchJob( @@ -1061,7 +1327,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_jobs.PatchJob: r"""Call the get patch job method over HTTP. @@ -1072,8 +1338,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.patch_jobs.PatchJob: @@ -1093,6 +1361,7 @@ def __call__( http_options = ( _BaseOsConfigServiceRestTransport._BaseGetPatchJob._get_http_options() ) + request, metadata = self._interceptor.pre_get_patch_job(request, metadata) transcoded_request = _BaseOsConfigServiceRestTransport._BaseGetPatchJob._get_transcoded_request( http_options, request @@ -1103,6 +1372,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigServiceClient.GetPatchJob", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "GetPatchJob", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigServiceRestTransport._GetPatchJob._get_response( self._host, @@ -1123,7 +1419,29 @@ def __call__( pb_resp = patch_jobs.PatchJob.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_patch_job(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = patch_jobs.PatchJob.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigServiceClient.get_patch_job", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "GetPatchJob", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListPatchDeployments( @@ -1161,7 +1479,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_deployments.ListPatchDeploymentsResponse: r"""Call the list patch deployments method over HTTP. @@ -1172,8 +1490,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.patch_deployments.ListPatchDeploymentsResponse: @@ -1185,6 +1505,7 @@ def __call__( http_options = ( _BaseOsConfigServiceRestTransport._BaseListPatchDeployments._get_http_options() ) + request, metadata = self._interceptor.pre_list_patch_deployments( request, metadata ) @@ -1197,6 +1518,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigServiceClient.ListPatchDeployments", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "ListPatchDeployments", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigServiceRestTransport._ListPatchDeployments._get_response( self._host, @@ -1217,7 +1565,31 @@ def __call__( pb_resp = patch_deployments.ListPatchDeploymentsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_patch_deployments(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + patch_deployments.ListPatchDeploymentsResponse.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigServiceClient.list_patch_deployments", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "ListPatchDeployments", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListPatchJobInstanceDetails( @@ -1255,7 +1627,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_jobs.ListPatchJobInstanceDetailsResponse: r"""Call the list patch job instance details method over HTTP. @@ -1267,8 +1639,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.patch_jobs.ListPatchJobInstanceDetailsResponse: @@ -1280,6 +1654,7 @@ def __call__( http_options = ( _BaseOsConfigServiceRestTransport._BaseListPatchJobInstanceDetails._get_http_options() ) + request, metadata = self._interceptor.pre_list_patch_job_instance_details( request, metadata ) @@ -1292,6 +1667,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigServiceClient.ListPatchJobInstanceDetails", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "ListPatchJobInstanceDetails", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( OsConfigServiceRestTransport._ListPatchJobInstanceDetails._get_response( @@ -1314,7 +1716,31 @@ def __call__( pb_resp = patch_jobs.ListPatchJobInstanceDetailsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_patch_job_instance_details(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + patch_jobs.ListPatchJobInstanceDetailsResponse.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigServiceClient.list_patch_job_instance_details", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "ListPatchJobInstanceDetails", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListPatchJobs( @@ -1351,7 +1777,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_jobs.ListPatchJobsResponse: r"""Call the list patch jobs method over HTTP. @@ -1362,8 +1788,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.patch_jobs.ListPatchJobsResponse: @@ -1375,6 +1803,7 @@ def __call__( http_options = ( _BaseOsConfigServiceRestTransport._BaseListPatchJobs._get_http_options() ) + request, metadata = self._interceptor.pre_list_patch_jobs(request, metadata) transcoded_request = _BaseOsConfigServiceRestTransport._BaseListPatchJobs._get_transcoded_request( http_options, request @@ -1385,6 +1814,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigServiceClient.ListPatchJobs", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "ListPatchJobs", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigServiceRestTransport._ListPatchJobs._get_response( self._host, @@ -1405,7 +1861,31 @@ def __call__( pb_resp = patch_jobs.ListPatchJobsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_patch_jobs(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = patch_jobs.ListPatchJobsResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigServiceClient.list_patch_jobs", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "ListPatchJobs", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _PausePatchDeployment( @@ -1444,7 +1924,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_deployments.PatchDeployment: r"""Call the pause patch deployment method over HTTP. @@ -1455,8 +1935,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.patch_deployments.PatchDeployment: @@ -1472,6 +1954,7 @@ def __call__( http_options = ( _BaseOsConfigServiceRestTransport._BasePausePatchDeployment._get_http_options() ) + request, metadata = self._interceptor.pre_pause_patch_deployment( request, metadata ) @@ -1488,6 +1971,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigServiceClient.PausePatchDeployment", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "PausePatchDeployment", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigServiceRestTransport._PausePatchDeployment._get_response( self._host, @@ -1509,7 +2019,31 @@ def __call__( pb_resp = patch_deployments.PatchDeployment.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_pause_patch_deployment(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = patch_deployments.PatchDeployment.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigServiceClient.pause_patch_deployment", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "PausePatchDeployment", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ResumePatchDeployment( @@ -1548,7 +2082,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_deployments.PatchDeployment: r"""Call the resume patch deployment method over HTTP. @@ -1559,8 +2093,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.patch_deployments.PatchDeployment: @@ -1576,6 +2112,7 @@ def __call__( http_options = ( _BaseOsConfigServiceRestTransport._BaseResumePatchDeployment._get_http_options() ) + request, metadata = self._interceptor.pre_resume_patch_deployment( request, metadata ) @@ -1592,6 +2129,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigServiceClient.ResumePatchDeployment", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "ResumePatchDeployment", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( OsConfigServiceRestTransport._ResumePatchDeployment._get_response( @@ -1615,7 +2179,31 @@ def __call__( pb_resp = patch_deployments.PatchDeployment.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_resume_patch_deployment(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = patch_deployments.PatchDeployment.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigServiceClient.resume_patch_deployment", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "ResumePatchDeployment", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdatePatchDeployment( @@ -1654,7 +2242,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> patch_deployments.PatchDeployment: r"""Call the update patch deployment method over HTTP. @@ -1665,8 +2253,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.patch_deployments.PatchDeployment: @@ -1682,6 +2272,7 @@ def __call__( http_options = ( _BaseOsConfigServiceRestTransport._BaseUpdatePatchDeployment._get_http_options() ) + request, metadata = self._interceptor.pre_update_patch_deployment( request, metadata ) @@ -1698,6 +2289,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigServiceClient.UpdatePatchDeployment", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "UpdatePatchDeployment", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( OsConfigServiceRestTransport._UpdatePatchDeployment._get_response( @@ -1721,7 +2339,31 @@ def __call__( pb_resp = patch_deployments.PatchDeployment.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_patch_deployment(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = patch_deployments.PatchDeployment.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigServiceClient.update_patch_deployment", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigService", + "rpcName": "UpdatePatchDeployment", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property diff --git a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/async_client.py b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/async_client.py index 28af081169b2..5b17e35f2000 100644 --- a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/async_client.py +++ b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -61,6 +62,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, OsConfigZonalServiceTransport from .transports.grpc_asyncio import OsConfigZonalServiceGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class OsConfigZonalServiceAsyncClient: """Zonal OS Config API @@ -301,6 +311,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.osconfig_v1.OsConfigZonalServiceAsyncClient`.", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "credentialsType": None, + }, + ) + async def create_os_policy_assignment( self, request: Optional[ @@ -312,7 +344,7 @@ async def create_os_policy_assignment( os_policy_assignment_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Create an OS policy assignment. @@ -402,8 +434,10 @@ async def sample_create_os_policy_assignment(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -495,7 +529,7 @@ async def update_os_policy_assignment( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Update an existing OS policy assignment. @@ -568,8 +602,10 @@ async def sample_update_os_policy_assignment(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -658,7 +694,7 @@ async def get_os_policy_assignment( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> os_policy_assignments.OSPolicyAssignment: r"""Retrieve an existing OS policy assignment. @@ -708,8 +744,10 @@ async def sample_get_os_policy_assignment(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.OSPolicyAssignment: @@ -782,7 +820,7 @@ async def list_os_policy_assignments( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListOSPolicyAssignmentsAsyncPager: r"""List the OS policy assignments under the parent resource. @@ -828,8 +866,10 @@ async def sample_list_os_policy_assignments(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentsAsyncPager: @@ -908,7 +948,7 @@ async def list_os_policy_assignment_revisions( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListOSPolicyAssignmentRevisionsAsyncPager: r"""List the OS policy assignment revisions for a given OS policy assignment. @@ -954,8 +994,10 @@ async def sample_list_os_policy_assignment_revisions(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentRevisionsAsyncPager: @@ -1036,7 +1078,7 @@ async def delete_os_policy_assignment( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Delete the OS policy assignment. @@ -1096,8 +1138,10 @@ async def sample_delete_os_policy_assignment(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1180,7 +1224,7 @@ async def get_os_policy_assignment_report( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> os_policy_assignment_reports.OSPolicyAssignmentReport: r"""Get the OS policy asssignment report for the specified Compute Engine VM instance. @@ -1235,8 +1279,10 @@ async def sample_get_os_policy_assignment_report(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.OSPolicyAssignmentReport: @@ -1305,7 +1351,7 @@ async def list_os_policy_assignment_reports( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListOSPolicyAssignmentReportsAsyncPager: r"""List OS policy asssignment reports for all Compute Engine VM instances in the specified zone. @@ -1375,8 +1421,10 @@ async def sample_list_os_policy_assignment_reports(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentReportsAsyncPager: @@ -1457,7 +1505,7 @@ async def get_inventory( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> inventory.Inventory: r"""Get inventory data for the specified VM instance. If the VM has no associated inventory, the message ``NOT_FOUND`` is returned. @@ -1509,8 +1557,10 @@ async def sample_get_inventory(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.Inventory: @@ -1579,7 +1629,7 @@ async def list_inventories( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListInventoriesAsyncPager: r"""List inventory data for all VM instances in the specified zone. @@ -1631,8 +1681,10 @@ async def sample_list_inventories(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.services.os_config_zonal_service.pagers.ListInventoriesAsyncPager: @@ -1711,7 +1763,7 @@ async def get_vulnerability_report( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> vulnerability.VulnerabilityReport: r"""Gets the vulnerability report for the specified VM instance. Only VMs with inventory data have @@ -1765,8 +1817,10 @@ async def sample_get_vulnerability_report(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.VulnerabilityReport: @@ -1833,7 +1887,7 @@ async def list_vulnerability_reports( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListVulnerabilityReportsAsyncPager: r"""List vulnerability reports for all VM instances in the specified zone. @@ -1885,8 +1939,10 @@ async def sample_list_vulnerability_reports(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.services.os_config_zonal_service.pagers.ListVulnerabilityReportsAsyncPager: diff --git a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/client.py b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/client.py index ce15fa6caeab..19af033a39d0 100644 --- a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/client.py +++ b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.protobuf import empty_pb2 # type: ignore @@ -713,6 +723,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -779,6 +793,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.osconfig_v1.OsConfigZonalServiceClient`.", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "credentialsType": None, + }, + ) + def create_os_policy_assignment( self, request: Optional[ @@ -790,7 +827,7 @@ def create_os_policy_assignment( os_policy_assignment_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Create an OS policy assignment. @@ -880,8 +917,10 @@ def sample_create_os_policy_assignment(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -972,7 +1011,7 @@ def update_os_policy_assignment( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Update an existing OS policy assignment. @@ -1045,8 +1084,10 @@ def sample_update_os_policy_assignment(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1134,7 +1175,7 @@ def get_os_policy_assignment( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> os_policy_assignments.OSPolicyAssignment: r"""Retrieve an existing OS policy assignment. @@ -1184,8 +1225,10 @@ def sample_get_os_policy_assignment(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.OSPolicyAssignment: @@ -1255,7 +1298,7 @@ def list_os_policy_assignments( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListOSPolicyAssignmentsPager: r"""List the OS policy assignments under the parent resource. @@ -1301,8 +1344,10 @@ def sample_list_os_policy_assignments(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentsPager: @@ -1380,7 +1425,7 @@ def list_os_policy_assignment_revisions( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListOSPolicyAssignmentRevisionsPager: r"""List the OS policy assignment revisions for a given OS policy assignment. @@ -1426,8 +1471,10 @@ def sample_list_os_policy_assignment_revisions(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentRevisionsPager: @@ -1507,7 +1554,7 @@ def delete_os_policy_assignment( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Delete the OS policy assignment. @@ -1567,8 +1614,10 @@ def sample_delete_os_policy_assignment(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1650,7 +1699,7 @@ def get_os_policy_assignment_report( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> os_policy_assignment_reports.OSPolicyAssignmentReport: r"""Get the OS policy asssignment report for the specified Compute Engine VM instance. @@ -1705,8 +1754,10 @@ def sample_get_os_policy_assignment_report(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.OSPolicyAssignmentReport: @@ -1774,7 +1825,7 @@ def list_os_policy_assignment_reports( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListOSPolicyAssignmentReportsPager: r"""List OS policy asssignment reports for all Compute Engine VM instances in the specified zone. @@ -1844,8 +1895,10 @@ def sample_list_os_policy_assignment_reports(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentReportsPager: @@ -1925,7 +1978,7 @@ def get_inventory( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> inventory.Inventory: r"""Get inventory data for the specified VM instance. If the VM has no associated inventory, the message ``NOT_FOUND`` is returned. @@ -1977,8 +2030,10 @@ def sample_get_inventory(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.Inventory: @@ -2044,7 +2099,7 @@ def list_inventories( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListInventoriesPager: r"""List inventory data for all VM instances in the specified zone. @@ -2096,8 +2151,10 @@ def sample_list_inventories(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.services.os_config_zonal_service.pagers.ListInventoriesPager: @@ -2173,7 +2230,7 @@ def get_vulnerability_report( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> vulnerability.VulnerabilityReport: r"""Gets the vulnerability report for the specified VM instance. Only VMs with inventory data have @@ -2227,8 +2284,10 @@ def sample_get_vulnerability_report(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.types.VulnerabilityReport: @@ -2292,7 +2351,7 @@ def list_vulnerability_reports( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListVulnerabilityReportsPager: r"""List vulnerability reports for all VM instances in the specified zone. @@ -2344,8 +2403,10 @@ def sample_list_vulnerability_reports(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1.services.os_config_zonal_service.pagers.ListVulnerabilityReportsPager: diff --git a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/pagers.py b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/pagers.py index 7353ffa03b22..8eff9e2c2653 100644 --- a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/pagers.py +++ b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/pagers.py @@ -72,7 +72,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -86,8 +86,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = os_policy_assignments.ListOSPolicyAssignmentsRequest(request) @@ -148,7 +150,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -162,8 +164,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = os_policy_assignments.ListOSPolicyAssignmentsRequest(request) @@ -230,7 +234,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -244,8 +248,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = os_policy_assignments.ListOSPolicyAssignmentRevisionsRequest( @@ -311,7 +317,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -325,8 +331,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = os_policy_assignments.ListOSPolicyAssignmentRevisionsRequest( @@ -395,7 +403,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -409,8 +417,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = ( @@ -480,7 +490,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -494,8 +504,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = ( @@ -566,7 +578,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -580,8 +592,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = inventory.ListInventoriesRequest(request) @@ -640,7 +654,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -654,8 +668,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = inventory.ListInventoriesRequest(request) @@ -718,7 +734,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -732,8 +748,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = vulnerability.ListVulnerabilityReportsRequest(request) @@ -794,7 +812,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -808,8 +826,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = vulnerability.ListVulnerabilityReportsRequest(request) diff --git a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/grpc.py b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/grpc.py index b7e66e6c4240..63e1099a1b6b 100644 --- a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/grpc.py +++ b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -21,7 +24,10 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.osconfig_v1.types import ( inventory, @@ -32,6 +38,81 @@ from .base import DEFAULT_CLIENT_INFO, OsConfigZonalServiceTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class OsConfigZonalServiceGrpcTransport(OsConfigZonalServiceTransport): """gRPC backend transport for OsConfigZonalService. @@ -190,7 +271,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -254,7 +340,9 @@ def operations_client(self) -> operations_v1.OperationsClient: """ # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + self._operations_client = operations_v1.OperationsClient( + self._logged_channel + ) # Return the client from cache. return self._operations_client @@ -291,7 +379,9 @@ def create_os_policy_assignment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_os_policy_assignment" not in self._stubs: - self._stubs["create_os_policy_assignment"] = self.grpc_channel.unary_unary( + self._stubs[ + "create_os_policy_assignment" + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/CreateOSPolicyAssignment", request_serializer=os_policy_assignments.CreateOSPolicyAssignmentRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -329,7 +419,9 @@ def update_os_policy_assignment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_os_policy_assignment" not in self._stubs: - self._stubs["update_os_policy_assignment"] = self.grpc_channel.unary_unary( + self._stubs[ + "update_os_policy_assignment" + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/UpdateOSPolicyAssignment", request_serializer=os_policy_assignments.UpdateOSPolicyAssignmentRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -362,7 +454,7 @@ def get_os_policy_assignment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_os_policy_assignment" not in self._stubs: - self._stubs["get_os_policy_assignment"] = self.grpc_channel.unary_unary( + self._stubs["get_os_policy_assignment"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/GetOSPolicyAssignment", request_serializer=os_policy_assignments.GetOSPolicyAssignmentRequest.serialize, response_deserializer=os_policy_assignments.OSPolicyAssignment.deserialize, @@ -394,7 +486,9 @@ def list_os_policy_assignments( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_os_policy_assignments" not in self._stubs: - self._stubs["list_os_policy_assignments"] = self.grpc_channel.unary_unary( + self._stubs[ + "list_os_policy_assignments" + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/ListOSPolicyAssignments", request_serializer=os_policy_assignments.ListOSPolicyAssignmentsRequest.serialize, response_deserializer=os_policy_assignments.ListOSPolicyAssignmentsResponse.deserialize, @@ -427,7 +521,7 @@ def list_os_policy_assignment_revisions( if "list_os_policy_assignment_revisions" not in self._stubs: self._stubs[ "list_os_policy_assignment_revisions" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/ListOSPolicyAssignmentRevisions", request_serializer=os_policy_assignments.ListOSPolicyAssignmentRevisionsRequest.serialize, response_deserializer=os_policy_assignments.ListOSPolicyAssignmentRevisionsResponse.deserialize, @@ -468,7 +562,9 @@ def delete_os_policy_assignment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_os_policy_assignment" not in self._stubs: - self._stubs["delete_os_policy_assignment"] = self.grpc_channel.unary_unary( + self._stubs[ + "delete_os_policy_assignment" + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/DeleteOSPolicyAssignment", request_serializer=os_policy_assignments.DeleteOSPolicyAssignmentRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -501,7 +597,7 @@ def get_os_policy_assignment_report( if "get_os_policy_assignment_report" not in self._stubs: self._stubs[ "get_os_policy_assignment_report" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/GetOSPolicyAssignmentReport", request_serializer=os_policy_assignment_reports.GetOSPolicyAssignmentReportRequest.serialize, response_deserializer=os_policy_assignment_reports.OSPolicyAssignmentReport.deserialize, @@ -534,7 +630,7 @@ def list_os_policy_assignment_reports( if "list_os_policy_assignment_reports" not in self._stubs: self._stubs[ "list_os_policy_assignment_reports" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/ListOSPolicyAssignmentReports", request_serializer=os_policy_assignment_reports.ListOSPolicyAssignmentReportsRequest.serialize, response_deserializer=os_policy_assignment_reports.ListOSPolicyAssignmentReportsResponse.deserialize, @@ -561,7 +657,7 @@ def get_inventory( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_inventory" not in self._stubs: - self._stubs["get_inventory"] = self.grpc_channel.unary_unary( + self._stubs["get_inventory"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/GetInventory", request_serializer=inventory.GetInventoryRequest.serialize, response_deserializer=inventory.Inventory.deserialize, @@ -590,7 +686,7 @@ def list_inventories( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_inventories" not in self._stubs: - self._stubs["list_inventories"] = self.grpc_channel.unary_unary( + self._stubs["list_inventories"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/ListInventories", request_serializer=inventory.ListInventoriesRequest.serialize, response_deserializer=inventory.ListInventoriesResponse.deserialize, @@ -620,7 +716,7 @@ def get_vulnerability_report( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_vulnerability_report" not in self._stubs: - self._stubs["get_vulnerability_report"] = self.grpc_channel.unary_unary( + self._stubs["get_vulnerability_report"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/GetVulnerabilityReport", request_serializer=vulnerability.GetVulnerabilityReportRequest.serialize, response_deserializer=vulnerability.VulnerabilityReport.deserialize, @@ -650,7 +746,9 @@ def list_vulnerability_reports( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_vulnerability_reports" not in self._stubs: - self._stubs["list_vulnerability_reports"] = self.grpc_channel.unary_unary( + self._stubs[ + "list_vulnerability_reports" + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/ListVulnerabilityReports", request_serializer=vulnerability.ListVulnerabilityReportsRequest.serialize, response_deserializer=vulnerability.ListVulnerabilityReportsResponse.deserialize, @@ -658,7 +756,7 @@ def list_vulnerability_reports( return self._stubs["list_vulnerability_reports"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/grpc_asyncio.py b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/grpc_asyncio.py index 2d443f7081e0..14cc19b13295 100644 --- a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -23,8 +26,11 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.osconfig_v1.types import ( inventory, @@ -36,6 +42,82 @@ from .base import DEFAULT_CLIENT_INFO, OsConfigZonalServiceTransport from .grpc import OsConfigZonalServiceGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class OsConfigZonalServiceGrpcAsyncIOTransport(OsConfigZonalServiceTransport): """gRPC AsyncIO backend transport for OsConfigZonalService. @@ -237,10 +319,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -263,7 +348,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel + self._logged_channel ) # Return the client from cache. @@ -301,7 +386,9 @@ def create_os_policy_assignment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_os_policy_assignment" not in self._stubs: - self._stubs["create_os_policy_assignment"] = self.grpc_channel.unary_unary( + self._stubs[ + "create_os_policy_assignment" + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/CreateOSPolicyAssignment", request_serializer=os_policy_assignments.CreateOSPolicyAssignmentRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -339,7 +426,9 @@ def update_os_policy_assignment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_os_policy_assignment" not in self._stubs: - self._stubs["update_os_policy_assignment"] = self.grpc_channel.unary_unary( + self._stubs[ + "update_os_policy_assignment" + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/UpdateOSPolicyAssignment", request_serializer=os_policy_assignments.UpdateOSPolicyAssignmentRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -372,7 +461,7 @@ def get_os_policy_assignment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_os_policy_assignment" not in self._stubs: - self._stubs["get_os_policy_assignment"] = self.grpc_channel.unary_unary( + self._stubs["get_os_policy_assignment"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/GetOSPolicyAssignment", request_serializer=os_policy_assignments.GetOSPolicyAssignmentRequest.serialize, response_deserializer=os_policy_assignments.OSPolicyAssignment.deserialize, @@ -404,7 +493,9 @@ def list_os_policy_assignments( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_os_policy_assignments" not in self._stubs: - self._stubs["list_os_policy_assignments"] = self.grpc_channel.unary_unary( + self._stubs[ + "list_os_policy_assignments" + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/ListOSPolicyAssignments", request_serializer=os_policy_assignments.ListOSPolicyAssignmentsRequest.serialize, response_deserializer=os_policy_assignments.ListOSPolicyAssignmentsResponse.deserialize, @@ -437,7 +528,7 @@ def list_os_policy_assignment_revisions( if "list_os_policy_assignment_revisions" not in self._stubs: self._stubs[ "list_os_policy_assignment_revisions" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/ListOSPolicyAssignmentRevisions", request_serializer=os_policy_assignments.ListOSPolicyAssignmentRevisionsRequest.serialize, response_deserializer=os_policy_assignments.ListOSPolicyAssignmentRevisionsResponse.deserialize, @@ -478,7 +569,9 @@ def delete_os_policy_assignment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_os_policy_assignment" not in self._stubs: - self._stubs["delete_os_policy_assignment"] = self.grpc_channel.unary_unary( + self._stubs[ + "delete_os_policy_assignment" + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/DeleteOSPolicyAssignment", request_serializer=os_policy_assignments.DeleteOSPolicyAssignmentRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -511,7 +604,7 @@ def get_os_policy_assignment_report( if "get_os_policy_assignment_report" not in self._stubs: self._stubs[ "get_os_policy_assignment_report" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/GetOSPolicyAssignmentReport", request_serializer=os_policy_assignment_reports.GetOSPolicyAssignmentReportRequest.serialize, response_deserializer=os_policy_assignment_reports.OSPolicyAssignmentReport.deserialize, @@ -544,7 +637,7 @@ def list_os_policy_assignment_reports( if "list_os_policy_assignment_reports" not in self._stubs: self._stubs[ "list_os_policy_assignment_reports" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/ListOSPolicyAssignmentReports", request_serializer=os_policy_assignment_reports.ListOSPolicyAssignmentReportsRequest.serialize, response_deserializer=os_policy_assignment_reports.ListOSPolicyAssignmentReportsResponse.deserialize, @@ -571,7 +664,7 @@ def get_inventory( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_inventory" not in self._stubs: - self._stubs["get_inventory"] = self.grpc_channel.unary_unary( + self._stubs["get_inventory"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/GetInventory", request_serializer=inventory.GetInventoryRequest.serialize, response_deserializer=inventory.Inventory.deserialize, @@ -600,7 +693,7 @@ def list_inventories( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_inventories" not in self._stubs: - self._stubs["list_inventories"] = self.grpc_channel.unary_unary( + self._stubs["list_inventories"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/ListInventories", request_serializer=inventory.ListInventoriesRequest.serialize, response_deserializer=inventory.ListInventoriesResponse.deserialize, @@ -631,7 +724,7 @@ def get_vulnerability_report( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_vulnerability_report" not in self._stubs: - self._stubs["get_vulnerability_report"] = self.grpc_channel.unary_unary( + self._stubs["get_vulnerability_report"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/GetVulnerabilityReport", request_serializer=vulnerability.GetVulnerabilityReportRequest.serialize, response_deserializer=vulnerability.VulnerabilityReport.deserialize, @@ -661,7 +754,9 @@ def list_vulnerability_reports( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_vulnerability_reports" not in self._stubs: - self._stubs["list_vulnerability_reports"] = self.grpc_channel.unary_unary( + self._stubs[ + "list_vulnerability_reports" + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1.OsConfigZonalService/ListVulnerabilityReports", request_serializer=vulnerability.ListVulnerabilityReportsRequest.serialize, response_deserializer=vulnerability.ListVulnerabilityReportsResponse.deserialize, @@ -739,7 +834,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/rest.py b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/rest.py index 5d165139669e..a95840be7ab8 100644 --- a/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/rest.py +++ b/packages/google-cloud-os-config/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -43,6 +43,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -171,9 +179,10 @@ def post_update_os_policy_assignment(self, response): def pre_create_os_policy_assignment( self, request: os_policy_assignments.CreateOSPolicyAssignmentRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - os_policy_assignments.CreateOSPolicyAssignmentRequest, Sequence[Tuple[str, str]] + os_policy_assignments.CreateOSPolicyAssignmentRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for create_os_policy_assignment @@ -196,9 +205,10 @@ def post_create_os_policy_assignment( def pre_delete_os_policy_assignment( self, request: os_policy_assignments.DeleteOSPolicyAssignmentRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - os_policy_assignments.DeleteOSPolicyAssignmentRequest, Sequence[Tuple[str, str]] + os_policy_assignments.DeleteOSPolicyAssignmentRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for delete_os_policy_assignment @@ -221,8 +231,8 @@ def post_delete_os_policy_assignment( def pre_get_inventory( self, request: inventory.GetInventoryRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[inventory.GetInventoryRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[inventory.GetInventoryRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for get_inventory Override in a subclass to manipulate the request or metadata @@ -242,9 +252,10 @@ def post_get_inventory(self, response: inventory.Inventory) -> inventory.Invento def pre_get_os_policy_assignment( self, request: os_policy_assignments.GetOSPolicyAssignmentRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - os_policy_assignments.GetOSPolicyAssignmentRequest, Sequence[Tuple[str, str]] + os_policy_assignments.GetOSPolicyAssignmentRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for get_os_policy_assignment @@ -267,10 +278,10 @@ def post_get_os_policy_assignment( def pre_get_os_policy_assignment_report( self, request: os_policy_assignment_reports.GetOSPolicyAssignmentReportRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ os_policy_assignment_reports.GetOSPolicyAssignmentReportRequest, - Sequence[Tuple[str, str]], + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for get_os_policy_assignment_report @@ -293,8 +304,11 @@ def post_get_os_policy_assignment_report( def pre_get_vulnerability_report( self, request: vulnerability.GetVulnerabilityReportRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[vulnerability.GetVulnerabilityReportRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + vulnerability.GetVulnerabilityReportRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for get_vulnerability_report Override in a subclass to manipulate the request or metadata @@ -316,8 +330,10 @@ def post_get_vulnerability_report( def pre_list_inventories( self, request: inventory.ListInventoriesRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[inventory.ListInventoriesRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + inventory.ListInventoriesRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_inventories Override in a subclass to manipulate the request or metadata @@ -339,10 +355,10 @@ def post_list_inventories( def pre_list_os_policy_assignment_reports( self, request: os_policy_assignment_reports.ListOSPolicyAssignmentReportsRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ os_policy_assignment_reports.ListOSPolicyAssignmentReportsRequest, - Sequence[Tuple[str, str]], + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for list_os_policy_assignment_reports @@ -366,10 +382,10 @@ def post_list_os_policy_assignment_reports( def pre_list_os_policy_assignment_revisions( self, request: os_policy_assignments.ListOSPolicyAssignmentRevisionsRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ os_policy_assignments.ListOSPolicyAssignmentRevisionsRequest, - Sequence[Tuple[str, str]], + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for list_os_policy_assignment_revisions @@ -392,9 +408,10 @@ def post_list_os_policy_assignment_revisions( def pre_list_os_policy_assignments( self, request: os_policy_assignments.ListOSPolicyAssignmentsRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - os_policy_assignments.ListOSPolicyAssignmentsRequest, Sequence[Tuple[str, str]] + os_policy_assignments.ListOSPolicyAssignmentsRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for list_os_policy_assignments @@ -417,9 +434,10 @@ def post_list_os_policy_assignments( def pre_list_vulnerability_reports( self, request: vulnerability.ListVulnerabilityReportsRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - vulnerability.ListVulnerabilityReportsRequest, Sequence[Tuple[str, str]] + vulnerability.ListVulnerabilityReportsRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for list_vulnerability_reports @@ -442,9 +460,10 @@ def post_list_vulnerability_reports( def pre_update_os_policy_assignment( self, request: os_policy_assignments.UpdateOSPolicyAssignmentRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - os_policy_assignments.UpdateOSPolicyAssignmentRequest, Sequence[Tuple[str, str]] + os_policy_assignments.UpdateOSPolicyAssignmentRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for update_os_policy_assignment @@ -633,7 +652,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the create os policy assignment method over HTTP. @@ -645,8 +664,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -659,6 +680,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseCreateOSPolicyAssignment._get_http_options() ) + request, metadata = self._interceptor.pre_create_os_policy_assignment( request, metadata ) @@ -675,6 +697,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigZonalServiceClient.CreateOSPolicyAssignment", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "CreateOSPolicyAssignment", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigZonalServiceRestTransport._CreateOSPolicyAssignment._get_response( self._host, @@ -694,7 +743,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_os_policy_assignment(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigZonalServiceClient.create_os_policy_assignment", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "CreateOSPolicyAssignment", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DeleteOSPolicyAssignment( @@ -732,7 +803,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the delete os policy assignment method over HTTP. @@ -744,8 +815,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -758,6 +831,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseDeleteOSPolicyAssignment._get_http_options() ) + request, metadata = self._interceptor.pre_delete_os_policy_assignment( request, metadata ) @@ -770,6 +844,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigZonalServiceClient.DeleteOSPolicyAssignment", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "DeleteOSPolicyAssignment", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigZonalServiceRestTransport._DeleteOSPolicyAssignment._get_response( self._host, @@ -788,7 +889,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_delete_os_policy_assignment(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigZonalServiceClient.delete_os_policy_assignment", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "DeleteOSPolicyAssignment", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetInventory( @@ -826,7 +949,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> inventory.Inventory: r"""Call the get inventory method over HTTP. @@ -837,8 +960,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.inventory.Inventory: @@ -858,6 +983,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseGetInventory._get_http_options() ) + request, metadata = self._interceptor.pre_get_inventory(request, metadata) transcoded_request = _BaseOsConfigZonalServiceRestTransport._BaseGetInventory._get_transcoded_request( http_options, request @@ -868,6 +994,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigZonalServiceClient.GetInventory", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "GetInventory", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigZonalServiceRestTransport._GetInventory._get_response( self._host, @@ -888,7 +1041,29 @@ def __call__( pb_resp = inventory.Inventory.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_inventory(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = inventory.Inventory.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigZonalServiceClient.get_inventory", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "GetInventory", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetOSPolicyAssignment( @@ -926,7 +1101,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> os_policy_assignments.OSPolicyAssignment: r"""Call the get os policy assignment method over HTTP. @@ -937,8 +1112,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.os_policy_assignments.OSPolicyAssignment: @@ -960,6 +1137,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseGetOSPolicyAssignment._get_http_options() ) + request, metadata = self._interceptor.pre_get_os_policy_assignment( request, metadata ) @@ -972,6 +1150,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigZonalServiceClient.GetOSPolicyAssignment", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "GetOSPolicyAssignment", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( OsConfigZonalServiceRestTransport._GetOSPolicyAssignment._get_response( @@ -994,7 +1199,31 @@ def __call__( pb_resp = os_policy_assignments.OSPolicyAssignment.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_os_policy_assignment(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = os_policy_assignments.OSPolicyAssignment.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigZonalServiceClient.get_os_policy_assignment", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "GetOSPolicyAssignment", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetOSPolicyAssignmentReport( @@ -1032,7 +1261,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> os_policy_assignment_reports.OSPolicyAssignmentReport: r"""Call the get os policy assignment report method over HTTP. @@ -1044,8 +1273,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.os_policy_assignment_reports.OSPolicyAssignmentReport: @@ -1057,6 +1288,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseGetOSPolicyAssignmentReport._get_http_options() ) + request, metadata = self._interceptor.pre_get_os_policy_assignment_report( request, metadata ) @@ -1069,6 +1301,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigZonalServiceClient.GetOSPolicyAssignmentReport", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "GetOSPolicyAssignmentReport", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigZonalServiceRestTransport._GetOSPolicyAssignmentReport._get_response( self._host, @@ -1089,7 +1348,33 @@ def __call__( pb_resp = os_policy_assignment_reports.OSPolicyAssignmentReport.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_os_policy_assignment_report(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + os_policy_assignment_reports.OSPolicyAssignmentReport.to_json( + response + ) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigZonalServiceClient.get_os_policy_assignment_report", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "GetOSPolicyAssignmentReport", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetVulnerabilityReport( @@ -1127,7 +1412,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> vulnerability.VulnerabilityReport: r"""Call the get vulnerability report method over HTTP. @@ -1139,8 +1424,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.vulnerability.VulnerabilityReport: @@ -1156,6 +1443,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseGetVulnerabilityReport._get_http_options() ) + request, metadata = self._interceptor.pre_get_vulnerability_report( request, metadata ) @@ -1168,6 +1456,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigZonalServiceClient.GetVulnerabilityReport", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "GetVulnerabilityReport", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( OsConfigZonalServiceRestTransport._GetVulnerabilityReport._get_response( @@ -1190,7 +1505,31 @@ def __call__( pb_resp = vulnerability.VulnerabilityReport.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_vulnerability_report(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = vulnerability.VulnerabilityReport.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigZonalServiceClient.get_vulnerability_report", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "GetVulnerabilityReport", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListInventories( @@ -1228,7 +1567,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> inventory.ListInventoriesResponse: r"""Call the list inventories method over HTTP. @@ -1240,8 +1579,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.inventory.ListInventoriesResponse: @@ -1254,6 +1595,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseListInventories._get_http_options() ) + request, metadata = self._interceptor.pre_list_inventories( request, metadata ) @@ -1266,6 +1608,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigZonalServiceClient.ListInventories", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "ListInventories", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigZonalServiceRestTransport._ListInventories._get_response( self._host, @@ -1286,7 +1655,31 @@ def __call__( pb_resp = inventory.ListInventoriesResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_inventories(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = inventory.ListInventoriesResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigZonalServiceClient.list_inventories", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "ListInventories", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListOSPolicyAssignmentReports( @@ -1326,7 +1719,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> os_policy_assignment_reports.ListOSPolicyAssignmentReportsResponse: r"""Call the list os policy assignment reports method over HTTP. @@ -1338,8 +1731,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.os_policy_assignment_reports.ListOSPolicyAssignmentReportsResponse: @@ -1352,6 +1747,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseListOSPolicyAssignmentReports._get_http_options() ) + request, metadata = self._interceptor.pre_list_os_policy_assignment_reports( request, metadata ) @@ -1364,6 +1760,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigZonalServiceClient.ListOSPolicyAssignmentReports", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "ListOSPolicyAssignmentReports", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigZonalServiceRestTransport._ListOSPolicyAssignmentReports._get_response( self._host, @@ -1388,7 +1811,31 @@ def __call__( ) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_os_policy_assignment_reports(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = os_policy_assignment_reports.ListOSPolicyAssignmentReportsResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigZonalServiceClient.list_os_policy_assignment_reports", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "ListOSPolicyAssignmentReports", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListOSPolicyAssignmentRevisions( @@ -1428,7 +1875,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> os_policy_assignments.ListOSPolicyAssignmentRevisionsResponse: r"""Call the list os policy assignment revisions method over HTTP. @@ -1440,8 +1887,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.os_policy_assignments.ListOSPolicyAssignmentRevisionsResponse: @@ -1453,6 +1902,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseListOSPolicyAssignmentRevisions._get_http_options() ) + ( request, metadata, @@ -1468,6 +1918,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigZonalServiceClient.ListOSPolicyAssignmentRevisions", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "ListOSPolicyAssignmentRevisions", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigZonalServiceRestTransport._ListOSPolicyAssignmentRevisions._get_response( self._host, @@ -1490,7 +1967,31 @@ def __call__( ) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_os_policy_assignment_revisions(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = os_policy_assignments.ListOSPolicyAssignmentRevisionsResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigZonalServiceClient.list_os_policy_assignment_revisions", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "ListOSPolicyAssignmentRevisions", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListOSPolicyAssignments( @@ -1528,7 +2029,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> os_policy_assignments.ListOSPolicyAssignmentsResponse: r"""Call the list os policy assignments method over HTTP. @@ -1540,8 +2041,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.os_policy_assignments.ListOSPolicyAssignmentsResponse: @@ -1553,6 +2056,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseListOSPolicyAssignments._get_http_options() ) + request, metadata = self._interceptor.pre_list_os_policy_assignments( request, metadata ) @@ -1565,6 +2069,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigZonalServiceClient.ListOSPolicyAssignments", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "ListOSPolicyAssignments", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigZonalServiceRestTransport._ListOSPolicyAssignments._get_response( self._host, @@ -1585,7 +2116,33 @@ def __call__( pb_resp = os_policy_assignments.ListOSPolicyAssignmentsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_os_policy_assignments(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + os_policy_assignments.ListOSPolicyAssignmentsResponse.to_json( + response + ) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigZonalServiceClient.list_os_policy_assignments", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "ListOSPolicyAssignments", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListVulnerabilityReports( @@ -1623,7 +2180,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> vulnerability.ListVulnerabilityReportsResponse: r"""Call the list vulnerability reports method over HTTP. @@ -1636,8 +2193,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.vulnerability.ListVulnerabilityReportsResponse: @@ -1650,6 +2209,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseListVulnerabilityReports._get_http_options() ) + request, metadata = self._interceptor.pre_list_vulnerability_reports( request, metadata ) @@ -1662,6 +2222,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigZonalServiceClient.ListVulnerabilityReports", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "ListVulnerabilityReports", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigZonalServiceRestTransport._ListVulnerabilityReports._get_response( self._host, @@ -1682,7 +2269,31 @@ def __call__( pb_resp = vulnerability.ListVulnerabilityReportsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_vulnerability_reports(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + vulnerability.ListVulnerabilityReportsResponse.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigZonalServiceClient.list_vulnerability_reports", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "ListVulnerabilityReports", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateOSPolicyAssignment( @@ -1721,7 +2332,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the update os policy assignment method over HTTP. @@ -1733,8 +2344,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1747,6 +2360,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseUpdateOSPolicyAssignment._get_http_options() ) + request, metadata = self._interceptor.pre_update_os_policy_assignment( request, metadata ) @@ -1763,6 +2377,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1.OsConfigZonalServiceClient.UpdateOSPolicyAssignment", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "UpdateOSPolicyAssignment", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigZonalServiceRestTransport._UpdateOSPolicyAssignment._get_response( self._host, @@ -1782,7 +2423,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_os_policy_assignment(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1.OsConfigZonalServiceClient.update_os_policy_assignment", + extra={ + "serviceName": "google.cloud.osconfig.v1.OsConfigZonalService", + "rpcName": "UpdateOSPolicyAssignment", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property diff --git a/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/gapic_version.py b/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/gapic_version.py index ef9777764da2..558c8aab67c5 100644 --- a/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/gapic_version.py +++ b/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.18.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/async_client.py b/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/async_client.py index 83c038226273..3e893872761f 100644 --- a/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/async_client.py +++ b/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -64,6 +65,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, OsConfigZonalServiceTransport from .transports.grpc_asyncio import OsConfigZonalServiceGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class OsConfigZonalServiceAsyncClient: """Zonal OS Config API @@ -310,6 +320,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.osconfig_v1alpha.OsConfigZonalServiceAsyncClient`.", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "credentialsType": None, + }, + ) + async def create_os_policy_assignment( self, request: Optional[ @@ -321,7 +353,7 @@ async def create_os_policy_assignment( os_policy_assignment_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Create an OS policy assignment. @@ -411,8 +443,10 @@ async def sample_create_os_policy_assignment(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -504,7 +538,7 @@ async def update_os_policy_assignment( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Update an existing OS policy assignment. @@ -577,8 +611,10 @@ async def sample_update_os_policy_assignment(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -667,7 +703,7 @@ async def get_os_policy_assignment( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> os_policy_assignments.OSPolicyAssignment: r"""Retrieve an existing OS policy assignment. @@ -717,8 +753,10 @@ async def sample_get_os_policy_assignment(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1alpha.types.OSPolicyAssignment: @@ -791,7 +829,7 @@ async def list_os_policy_assignments( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListOSPolicyAssignmentsAsyncPager: r"""List the OS policy assignments under the parent resource. @@ -837,8 +875,10 @@ async def sample_list_os_policy_assignments(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentsAsyncPager: @@ -917,7 +957,7 @@ async def list_os_policy_assignment_revisions( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListOSPolicyAssignmentRevisionsAsyncPager: r"""List the OS policy assignment revisions for a given OS policy assignment. @@ -963,8 +1003,10 @@ async def sample_list_os_policy_assignment_revisions(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentRevisionsAsyncPager: @@ -1045,7 +1087,7 @@ async def delete_os_policy_assignment( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Delete the OS policy assignment. @@ -1105,8 +1147,10 @@ async def sample_delete_os_policy_assignment(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1192,7 +1236,7 @@ async def get_instance_os_policies_compliance( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> instance_os_policies_compliance.InstanceOSPoliciesCompliance: r"""Get OS policies compliance data for the specified Compute Engine VM instance. @@ -1246,8 +1290,10 @@ async def sample_get_instance_os_policies_compliance(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1alpha.types.InstanceOSPoliciesCompliance: @@ -1338,7 +1384,7 @@ async def list_instance_os_policies_compliances( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListInstanceOSPoliciesCompliancesAsyncPager: r"""List OS policies compliance data for all Compute Engine VM instances in the specified zone. @@ -1389,8 +1435,10 @@ async def sample_list_instance_os_policies_compliances(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListInstanceOSPoliciesCompliancesAsyncPager: @@ -1479,7 +1527,7 @@ async def get_os_policy_assignment_report( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> os_policy_assignment_reports.OSPolicyAssignmentReport: r"""Get the OS policy asssignment report for the specified Compute Engine VM instance. @@ -1534,8 +1582,10 @@ async def sample_get_os_policy_assignment_report(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1alpha.types.OSPolicyAssignmentReport: @@ -1604,7 +1654,7 @@ async def list_os_policy_assignment_reports( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListOSPolicyAssignmentReportsAsyncPager: r"""List OS policy asssignment reports for all Compute Engine VM instances in the specified zone. @@ -1674,8 +1724,10 @@ async def sample_list_os_policy_assignment_reports(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentReportsAsyncPager: @@ -1756,7 +1808,7 @@ async def get_inventory( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> inventory.Inventory: r"""Get inventory data for the specified VM instance. If the VM has no associated inventory, the message ``NOT_FOUND`` is returned. @@ -1808,8 +1860,10 @@ async def sample_get_inventory(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1alpha.types.Inventory: @@ -1878,7 +1932,7 @@ async def list_inventories( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListInventoriesAsyncPager: r"""List inventory data for all VM instances in the specified zone. @@ -1930,8 +1984,10 @@ async def sample_list_inventories(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListInventoriesAsyncPager: @@ -2010,7 +2066,7 @@ async def get_vulnerability_report( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> vulnerability.VulnerabilityReport: r"""Gets the vulnerability report for the specified VM instance. Only VMs with inventory data have @@ -2064,8 +2120,10 @@ async def sample_get_vulnerability_report(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1alpha.types.VulnerabilityReport: @@ -2132,7 +2190,7 @@ async def list_vulnerability_reports( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListVulnerabilityReportsAsyncPager: r"""List vulnerability reports for all VM instances in the specified zone. @@ -2184,8 +2242,10 @@ async def sample_list_vulnerability_reports(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListVulnerabilityReportsAsyncPager: diff --git a/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/client.py b/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/client.py index dc9bacd2a138..003cbc70c0a8 100644 --- a/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/client.py +++ b/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.protobuf import empty_pb2 # type: ignore @@ -737,6 +747,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -803,6 +817,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient`.", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "credentialsType": None, + }, + ) + def create_os_policy_assignment( self, request: Optional[ @@ -814,7 +851,7 @@ def create_os_policy_assignment( os_policy_assignment_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Create an OS policy assignment. @@ -904,8 +941,10 @@ def sample_create_os_policy_assignment(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -996,7 +1035,7 @@ def update_os_policy_assignment( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Update an existing OS policy assignment. @@ -1069,8 +1108,10 @@ def sample_update_os_policy_assignment(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1158,7 +1199,7 @@ def get_os_policy_assignment( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> os_policy_assignments.OSPolicyAssignment: r"""Retrieve an existing OS policy assignment. @@ -1208,8 +1249,10 @@ def sample_get_os_policy_assignment(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1alpha.types.OSPolicyAssignment: @@ -1279,7 +1322,7 @@ def list_os_policy_assignments( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListOSPolicyAssignmentsPager: r"""List the OS policy assignments under the parent resource. @@ -1325,8 +1368,10 @@ def sample_list_os_policy_assignments(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentsPager: @@ -1404,7 +1449,7 @@ def list_os_policy_assignment_revisions( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListOSPolicyAssignmentRevisionsPager: r"""List the OS policy assignment revisions for a given OS policy assignment. @@ -1450,8 +1495,10 @@ def sample_list_os_policy_assignment_revisions(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentRevisionsPager: @@ -1531,7 +1578,7 @@ def delete_os_policy_assignment( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Delete the OS policy assignment. @@ -1591,8 +1638,10 @@ def sample_delete_os_policy_assignment(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1677,7 +1726,7 @@ def get_instance_os_policies_compliance( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> instance_os_policies_compliance.InstanceOSPoliciesCompliance: r"""Get OS policies compliance data for the specified Compute Engine VM instance. @@ -1731,8 +1780,10 @@ def sample_get_instance_os_policies_compliance(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1alpha.types.InstanceOSPoliciesCompliance: @@ -1822,7 +1873,7 @@ def list_instance_os_policies_compliances( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListInstanceOSPoliciesCompliancesPager: r"""List OS policies compliance data for all Compute Engine VM instances in the specified zone. @@ -1873,8 +1924,10 @@ def sample_list_instance_os_policies_compliances(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListInstanceOSPoliciesCompliancesPager: @@ -1962,7 +2015,7 @@ def get_os_policy_assignment_report( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> os_policy_assignment_reports.OSPolicyAssignmentReport: r"""Get the OS policy asssignment report for the specified Compute Engine VM instance. @@ -2017,8 +2070,10 @@ def sample_get_os_policy_assignment_report(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1alpha.types.OSPolicyAssignmentReport: @@ -2086,7 +2141,7 @@ def list_os_policy_assignment_reports( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListOSPolicyAssignmentReportsPager: r"""List OS policy asssignment reports for all Compute Engine VM instances in the specified zone. @@ -2156,8 +2211,10 @@ def sample_list_os_policy_assignment_reports(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentReportsPager: @@ -2237,7 +2294,7 @@ def get_inventory( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> inventory.Inventory: r"""Get inventory data for the specified VM instance. If the VM has no associated inventory, the message ``NOT_FOUND`` is returned. @@ -2289,8 +2346,10 @@ def sample_get_inventory(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1alpha.types.Inventory: @@ -2356,7 +2415,7 @@ def list_inventories( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListInventoriesPager: r"""List inventory data for all VM instances in the specified zone. @@ -2408,8 +2467,10 @@ def sample_list_inventories(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListInventoriesPager: @@ -2485,7 +2546,7 @@ def get_vulnerability_report( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> vulnerability.VulnerabilityReport: r"""Gets the vulnerability report for the specified VM instance. Only VMs with inventory data have @@ -2539,8 +2600,10 @@ def sample_get_vulnerability_report(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1alpha.types.VulnerabilityReport: @@ -2604,7 +2667,7 @@ def list_vulnerability_reports( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListVulnerabilityReportsPager: r"""List vulnerability reports for all VM instances in the specified zone. @@ -2656,8 +2719,10 @@ def sample_list_vulnerability_reports(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListVulnerabilityReportsPager: diff --git a/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/pagers.py b/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/pagers.py index 41a4b247a35f..3cce3cd38749 100644 --- a/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/pagers.py +++ b/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/pagers.py @@ -73,7 +73,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -87,8 +87,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = os_policy_assignments.ListOSPolicyAssignmentsRequest(request) @@ -149,7 +151,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -163,8 +165,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = os_policy_assignments.ListOSPolicyAssignmentsRequest(request) @@ -231,7 +235,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -245,8 +249,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = os_policy_assignments.ListOSPolicyAssignmentRevisionsRequest( @@ -312,7 +318,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -326,8 +332,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = os_policy_assignments.ListOSPolicyAssignmentRevisionsRequest( @@ -397,7 +405,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -411,8 +419,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = ( @@ -486,7 +496,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -500,8 +510,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = ( @@ -576,7 +588,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -590,8 +602,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = ( @@ -661,7 +675,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -675,8 +689,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = ( @@ -747,7 +763,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -761,8 +777,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = inventory.ListInventoriesRequest(request) @@ -821,7 +839,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -835,8 +853,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = inventory.ListInventoriesRequest(request) @@ -899,7 +919,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -913,8 +933,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = vulnerability.ListVulnerabilityReportsRequest(request) @@ -975,7 +997,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -989,8 +1011,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = vulnerability.ListVulnerabilityReportsRequest(request) diff --git a/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/grpc.py b/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/grpc.py index e76fe82fc2bc..9d28ab5a30b1 100644 --- a/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/grpc.py +++ b/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -21,7 +24,10 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.osconfig_v1alpha.types import ( instance_os_policies_compliance, @@ -33,6 +39,81 @@ from .base import DEFAULT_CLIENT_INFO, OsConfigZonalServiceTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class OsConfigZonalServiceGrpcTransport(OsConfigZonalServiceTransport): """gRPC backend transport for OsConfigZonalService. @@ -191,7 +272,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -255,7 +341,9 @@ def operations_client(self) -> operations_v1.OperationsClient: """ # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + self._operations_client = operations_v1.OperationsClient( + self._logged_channel + ) # Return the client from cache. return self._operations_client @@ -292,7 +380,9 @@ def create_os_policy_assignment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_os_policy_assignment" not in self._stubs: - self._stubs["create_os_policy_assignment"] = self.grpc_channel.unary_unary( + self._stubs[ + "create_os_policy_assignment" + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/CreateOSPolicyAssignment", request_serializer=os_policy_assignments.CreateOSPolicyAssignmentRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -330,7 +420,9 @@ def update_os_policy_assignment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_os_policy_assignment" not in self._stubs: - self._stubs["update_os_policy_assignment"] = self.grpc_channel.unary_unary( + self._stubs[ + "update_os_policy_assignment" + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/UpdateOSPolicyAssignment", request_serializer=os_policy_assignments.UpdateOSPolicyAssignmentRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -363,7 +455,7 @@ def get_os_policy_assignment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_os_policy_assignment" not in self._stubs: - self._stubs["get_os_policy_assignment"] = self.grpc_channel.unary_unary( + self._stubs["get_os_policy_assignment"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/GetOSPolicyAssignment", request_serializer=os_policy_assignments.GetOSPolicyAssignmentRequest.serialize, response_deserializer=os_policy_assignments.OSPolicyAssignment.deserialize, @@ -395,7 +487,9 @@ def list_os_policy_assignments( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_os_policy_assignments" not in self._stubs: - self._stubs["list_os_policy_assignments"] = self.grpc_channel.unary_unary( + self._stubs[ + "list_os_policy_assignments" + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/ListOSPolicyAssignments", request_serializer=os_policy_assignments.ListOSPolicyAssignmentsRequest.serialize, response_deserializer=os_policy_assignments.ListOSPolicyAssignmentsResponse.deserialize, @@ -428,7 +522,7 @@ def list_os_policy_assignment_revisions( if "list_os_policy_assignment_revisions" not in self._stubs: self._stubs[ "list_os_policy_assignment_revisions" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/ListOSPolicyAssignmentRevisions", request_serializer=os_policy_assignments.ListOSPolicyAssignmentRevisionsRequest.serialize, response_deserializer=os_policy_assignments.ListOSPolicyAssignmentRevisionsResponse.deserialize, @@ -469,7 +563,9 @@ def delete_os_policy_assignment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_os_policy_assignment" not in self._stubs: - self._stubs["delete_os_policy_assignment"] = self.grpc_channel.unary_unary( + self._stubs[ + "delete_os_policy_assignment" + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/DeleteOSPolicyAssignment", request_serializer=os_policy_assignments.DeleteOSPolicyAssignmentRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -502,7 +598,7 @@ def get_instance_os_policies_compliance( if "get_instance_os_policies_compliance" not in self._stubs: self._stubs[ "get_instance_os_policies_compliance" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/GetInstanceOSPoliciesCompliance", request_serializer=instance_os_policies_compliance.GetInstanceOSPoliciesComplianceRequest.serialize, response_deserializer=instance_os_policies_compliance.InstanceOSPoliciesCompliance.deserialize, @@ -535,7 +631,7 @@ def list_instance_os_policies_compliances( if "list_instance_os_policies_compliances" not in self._stubs: self._stubs[ "list_instance_os_policies_compliances" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/ListInstanceOSPoliciesCompliances", request_serializer=instance_os_policies_compliance.ListInstanceOSPoliciesCompliancesRequest.serialize, response_deserializer=instance_os_policies_compliance.ListInstanceOSPoliciesCompliancesResponse.deserialize, @@ -568,7 +664,7 @@ def get_os_policy_assignment_report( if "get_os_policy_assignment_report" not in self._stubs: self._stubs[ "get_os_policy_assignment_report" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/GetOSPolicyAssignmentReport", request_serializer=os_policy_assignment_reports.GetOSPolicyAssignmentReportRequest.serialize, response_deserializer=os_policy_assignment_reports.OSPolicyAssignmentReport.deserialize, @@ -601,7 +697,7 @@ def list_os_policy_assignment_reports( if "list_os_policy_assignment_reports" not in self._stubs: self._stubs[ "list_os_policy_assignment_reports" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/ListOSPolicyAssignmentReports", request_serializer=os_policy_assignment_reports.ListOSPolicyAssignmentReportsRequest.serialize, response_deserializer=os_policy_assignment_reports.ListOSPolicyAssignmentReportsResponse.deserialize, @@ -628,7 +724,7 @@ def get_inventory( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_inventory" not in self._stubs: - self._stubs["get_inventory"] = self.grpc_channel.unary_unary( + self._stubs["get_inventory"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/GetInventory", request_serializer=inventory.GetInventoryRequest.serialize, response_deserializer=inventory.Inventory.deserialize, @@ -657,7 +753,7 @@ def list_inventories( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_inventories" not in self._stubs: - self._stubs["list_inventories"] = self.grpc_channel.unary_unary( + self._stubs["list_inventories"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/ListInventories", request_serializer=inventory.ListInventoriesRequest.serialize, response_deserializer=inventory.ListInventoriesResponse.deserialize, @@ -687,7 +783,7 @@ def get_vulnerability_report( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_vulnerability_report" not in self._stubs: - self._stubs["get_vulnerability_report"] = self.grpc_channel.unary_unary( + self._stubs["get_vulnerability_report"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/GetVulnerabilityReport", request_serializer=vulnerability.GetVulnerabilityReportRequest.serialize, response_deserializer=vulnerability.VulnerabilityReport.deserialize, @@ -717,7 +813,9 @@ def list_vulnerability_reports( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_vulnerability_reports" not in self._stubs: - self._stubs["list_vulnerability_reports"] = self.grpc_channel.unary_unary( + self._stubs[ + "list_vulnerability_reports" + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/ListVulnerabilityReports", request_serializer=vulnerability.ListVulnerabilityReportsRequest.serialize, response_deserializer=vulnerability.ListVulnerabilityReportsResponse.deserialize, @@ -725,7 +823,7 @@ def list_vulnerability_reports( return self._stubs["list_vulnerability_reports"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/grpc_asyncio.py b/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/grpc_asyncio.py index 01204ee9b885..342250fd1b84 100644 --- a/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -23,8 +26,11 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.osconfig_v1alpha.types import ( instance_os_policies_compliance, @@ -37,6 +43,82 @@ from .base import DEFAULT_CLIENT_INFO, OsConfigZonalServiceTransport from .grpc import OsConfigZonalServiceGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class OsConfigZonalServiceGrpcAsyncIOTransport(OsConfigZonalServiceTransport): """gRPC AsyncIO backend transport for OsConfigZonalService. @@ -238,10 +320,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -264,7 +349,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel + self._logged_channel ) # Return the client from cache. @@ -302,7 +387,9 @@ def create_os_policy_assignment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_os_policy_assignment" not in self._stubs: - self._stubs["create_os_policy_assignment"] = self.grpc_channel.unary_unary( + self._stubs[ + "create_os_policy_assignment" + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/CreateOSPolicyAssignment", request_serializer=os_policy_assignments.CreateOSPolicyAssignmentRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -340,7 +427,9 @@ def update_os_policy_assignment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_os_policy_assignment" not in self._stubs: - self._stubs["update_os_policy_assignment"] = self.grpc_channel.unary_unary( + self._stubs[ + "update_os_policy_assignment" + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/UpdateOSPolicyAssignment", request_serializer=os_policy_assignments.UpdateOSPolicyAssignmentRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -373,7 +462,7 @@ def get_os_policy_assignment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_os_policy_assignment" not in self._stubs: - self._stubs["get_os_policy_assignment"] = self.grpc_channel.unary_unary( + self._stubs["get_os_policy_assignment"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/GetOSPolicyAssignment", request_serializer=os_policy_assignments.GetOSPolicyAssignmentRequest.serialize, response_deserializer=os_policy_assignments.OSPolicyAssignment.deserialize, @@ -405,7 +494,9 @@ def list_os_policy_assignments( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_os_policy_assignments" not in self._stubs: - self._stubs["list_os_policy_assignments"] = self.grpc_channel.unary_unary( + self._stubs[ + "list_os_policy_assignments" + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/ListOSPolicyAssignments", request_serializer=os_policy_assignments.ListOSPolicyAssignmentsRequest.serialize, response_deserializer=os_policy_assignments.ListOSPolicyAssignmentsResponse.deserialize, @@ -438,7 +529,7 @@ def list_os_policy_assignment_revisions( if "list_os_policy_assignment_revisions" not in self._stubs: self._stubs[ "list_os_policy_assignment_revisions" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/ListOSPolicyAssignmentRevisions", request_serializer=os_policy_assignments.ListOSPolicyAssignmentRevisionsRequest.serialize, response_deserializer=os_policy_assignments.ListOSPolicyAssignmentRevisionsResponse.deserialize, @@ -479,7 +570,9 @@ def delete_os_policy_assignment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_os_policy_assignment" not in self._stubs: - self._stubs["delete_os_policy_assignment"] = self.grpc_channel.unary_unary( + self._stubs[ + "delete_os_policy_assignment" + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/DeleteOSPolicyAssignment", request_serializer=os_policy_assignments.DeleteOSPolicyAssignmentRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -512,7 +605,7 @@ def get_instance_os_policies_compliance( if "get_instance_os_policies_compliance" not in self._stubs: self._stubs[ "get_instance_os_policies_compliance" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/GetInstanceOSPoliciesCompliance", request_serializer=instance_os_policies_compliance.GetInstanceOSPoliciesComplianceRequest.serialize, response_deserializer=instance_os_policies_compliance.InstanceOSPoliciesCompliance.deserialize, @@ -547,7 +640,7 @@ def list_instance_os_policies_compliances( if "list_instance_os_policies_compliances" not in self._stubs: self._stubs[ "list_instance_os_policies_compliances" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/ListInstanceOSPoliciesCompliances", request_serializer=instance_os_policies_compliance.ListInstanceOSPoliciesCompliancesRequest.serialize, response_deserializer=instance_os_policies_compliance.ListInstanceOSPoliciesCompliancesResponse.deserialize, @@ -580,7 +673,7 @@ def get_os_policy_assignment_report( if "get_os_policy_assignment_report" not in self._stubs: self._stubs[ "get_os_policy_assignment_report" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/GetOSPolicyAssignmentReport", request_serializer=os_policy_assignment_reports.GetOSPolicyAssignmentReportRequest.serialize, response_deserializer=os_policy_assignment_reports.OSPolicyAssignmentReport.deserialize, @@ -613,7 +706,7 @@ def list_os_policy_assignment_reports( if "list_os_policy_assignment_reports" not in self._stubs: self._stubs[ "list_os_policy_assignment_reports" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/ListOSPolicyAssignmentReports", request_serializer=os_policy_assignment_reports.ListOSPolicyAssignmentReportsRequest.serialize, response_deserializer=os_policy_assignment_reports.ListOSPolicyAssignmentReportsResponse.deserialize, @@ -640,7 +733,7 @@ def get_inventory( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_inventory" not in self._stubs: - self._stubs["get_inventory"] = self.grpc_channel.unary_unary( + self._stubs["get_inventory"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/GetInventory", request_serializer=inventory.GetInventoryRequest.serialize, response_deserializer=inventory.Inventory.deserialize, @@ -669,7 +762,7 @@ def list_inventories( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_inventories" not in self._stubs: - self._stubs["list_inventories"] = self.grpc_channel.unary_unary( + self._stubs["list_inventories"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/ListInventories", request_serializer=inventory.ListInventoriesRequest.serialize, response_deserializer=inventory.ListInventoriesResponse.deserialize, @@ -700,7 +793,7 @@ def get_vulnerability_report( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_vulnerability_report" not in self._stubs: - self._stubs["get_vulnerability_report"] = self.grpc_channel.unary_unary( + self._stubs["get_vulnerability_report"] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/GetVulnerabilityReport", request_serializer=vulnerability.GetVulnerabilityReportRequest.serialize, response_deserializer=vulnerability.VulnerabilityReport.deserialize, @@ -730,7 +823,9 @@ def list_vulnerability_reports( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_vulnerability_reports" not in self._stubs: - self._stubs["list_vulnerability_reports"] = self.grpc_channel.unary_unary( + self._stubs[ + "list_vulnerability_reports" + ] = self._logged_channel.unary_unary( "/google.cloud.osconfig.v1alpha.OsConfigZonalService/ListVulnerabilityReports", request_serializer=vulnerability.ListVulnerabilityReportsRequest.serialize, response_deserializer=vulnerability.ListVulnerabilityReportsResponse.deserialize, @@ -818,7 +913,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/rest.py b/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/rest.py index 2985b984d4d2..920c5843c069 100644 --- a/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/rest.py +++ b/packages/google-cloud-os-config/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -44,6 +44,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -188,9 +196,10 @@ def post_update_os_policy_assignment(self, response): def pre_create_os_policy_assignment( self, request: os_policy_assignments.CreateOSPolicyAssignmentRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - os_policy_assignments.CreateOSPolicyAssignmentRequest, Sequence[Tuple[str, str]] + os_policy_assignments.CreateOSPolicyAssignmentRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for create_os_policy_assignment @@ -213,9 +222,10 @@ def post_create_os_policy_assignment( def pre_delete_os_policy_assignment( self, request: os_policy_assignments.DeleteOSPolicyAssignmentRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - os_policy_assignments.DeleteOSPolicyAssignmentRequest, Sequence[Tuple[str, str]] + os_policy_assignments.DeleteOSPolicyAssignmentRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for delete_os_policy_assignment @@ -238,10 +248,10 @@ def post_delete_os_policy_assignment( def pre_get_instance_os_policies_compliance( self, request: instance_os_policies_compliance.GetInstanceOSPoliciesComplianceRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ instance_os_policies_compliance.GetInstanceOSPoliciesComplianceRequest, - Sequence[Tuple[str, str]], + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for get_instance_os_policies_compliance @@ -264,8 +274,8 @@ def post_get_instance_os_policies_compliance( def pre_get_inventory( self, request: inventory.GetInventoryRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[inventory.GetInventoryRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[inventory.GetInventoryRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for get_inventory Override in a subclass to manipulate the request or metadata @@ -285,9 +295,10 @@ def post_get_inventory(self, response: inventory.Inventory) -> inventory.Invento def pre_get_os_policy_assignment( self, request: os_policy_assignments.GetOSPolicyAssignmentRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - os_policy_assignments.GetOSPolicyAssignmentRequest, Sequence[Tuple[str, str]] + os_policy_assignments.GetOSPolicyAssignmentRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for get_os_policy_assignment @@ -310,10 +321,10 @@ def post_get_os_policy_assignment( def pre_get_os_policy_assignment_report( self, request: os_policy_assignment_reports.GetOSPolicyAssignmentReportRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ os_policy_assignment_reports.GetOSPolicyAssignmentReportRequest, - Sequence[Tuple[str, str]], + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for get_os_policy_assignment_report @@ -336,8 +347,11 @@ def post_get_os_policy_assignment_report( def pre_get_vulnerability_report( self, request: vulnerability.GetVulnerabilityReportRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[vulnerability.GetVulnerabilityReportRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + vulnerability.GetVulnerabilityReportRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for get_vulnerability_report Override in a subclass to manipulate the request or metadata @@ -359,10 +373,10 @@ def post_get_vulnerability_report( def pre_list_instance_os_policies_compliances( self, request: instance_os_policies_compliance.ListInstanceOSPoliciesCompliancesRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ instance_os_policies_compliance.ListInstanceOSPoliciesCompliancesRequest, - Sequence[Tuple[str, str]], + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for list_instance_os_policies_compliances @@ -386,8 +400,10 @@ def post_list_instance_os_policies_compliances( def pre_list_inventories( self, request: inventory.ListInventoriesRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[inventory.ListInventoriesRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + inventory.ListInventoriesRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_inventories Override in a subclass to manipulate the request or metadata @@ -409,10 +425,10 @@ def post_list_inventories( def pre_list_os_policy_assignment_reports( self, request: os_policy_assignment_reports.ListOSPolicyAssignmentReportsRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ os_policy_assignment_reports.ListOSPolicyAssignmentReportsRequest, - Sequence[Tuple[str, str]], + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for list_os_policy_assignment_reports @@ -436,10 +452,10 @@ def post_list_os_policy_assignment_reports( def pre_list_os_policy_assignment_revisions( self, request: os_policy_assignments.ListOSPolicyAssignmentRevisionsRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ os_policy_assignments.ListOSPolicyAssignmentRevisionsRequest, - Sequence[Tuple[str, str]], + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for list_os_policy_assignment_revisions @@ -462,9 +478,10 @@ def post_list_os_policy_assignment_revisions( def pre_list_os_policy_assignments( self, request: os_policy_assignments.ListOSPolicyAssignmentsRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - os_policy_assignments.ListOSPolicyAssignmentsRequest, Sequence[Tuple[str, str]] + os_policy_assignments.ListOSPolicyAssignmentsRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for list_os_policy_assignments @@ -487,9 +504,10 @@ def post_list_os_policy_assignments( def pre_list_vulnerability_reports( self, request: vulnerability.ListVulnerabilityReportsRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - vulnerability.ListVulnerabilityReportsRequest, Sequence[Tuple[str, str]] + vulnerability.ListVulnerabilityReportsRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for list_vulnerability_reports @@ -512,9 +530,10 @@ def post_list_vulnerability_reports( def pre_update_os_policy_assignment( self, request: os_policy_assignments.UpdateOSPolicyAssignmentRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - os_policy_assignments.UpdateOSPolicyAssignmentRequest, Sequence[Tuple[str, str]] + os_policy_assignments.UpdateOSPolicyAssignmentRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for update_os_policy_assignment @@ -703,7 +722,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the create os policy assignment method over HTTP. @@ -715,8 +734,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -729,6 +750,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseCreateOSPolicyAssignment._get_http_options() ) + request, metadata = self._interceptor.pre_create_os_policy_assignment( request, metadata ) @@ -745,6 +767,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.CreateOSPolicyAssignment", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "CreateOSPolicyAssignment", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigZonalServiceRestTransport._CreateOSPolicyAssignment._get_response( self._host, @@ -764,7 +813,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_os_policy_assignment(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.create_os_policy_assignment", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "CreateOSPolicyAssignment", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DeleteOSPolicyAssignment( @@ -802,7 +873,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the delete os policy assignment method over HTTP. @@ -814,8 +885,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -828,6 +901,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseDeleteOSPolicyAssignment._get_http_options() ) + request, metadata = self._interceptor.pre_delete_os_policy_assignment( request, metadata ) @@ -840,6 +914,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.DeleteOSPolicyAssignment", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "DeleteOSPolicyAssignment", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigZonalServiceRestTransport._DeleteOSPolicyAssignment._get_response( self._host, @@ -858,7 +959,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_delete_os_policy_assignment(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.delete_os_policy_assignment", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "DeleteOSPolicyAssignment", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetInstanceOSPoliciesCompliance( @@ -898,7 +1021,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> instance_os_policies_compliance.InstanceOSPoliciesCompliance: r"""Call the get instance os policies compliance method over HTTP. @@ -911,8 +1034,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.instance_os_policies_compliance.InstanceOSPoliciesCompliance: @@ -937,6 +1062,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseGetInstanceOSPoliciesCompliance._get_http_options() ) + ( request, metadata, @@ -952,6 +1078,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.GetInstanceOSPoliciesCompliance", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "GetInstanceOSPoliciesCompliance", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigZonalServiceRestTransport._GetInstanceOSPoliciesCompliance._get_response( self._host, @@ -974,7 +1127,31 @@ def __call__( ) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_instance_os_policies_compliance(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = instance_os_policies_compliance.InstanceOSPoliciesCompliance.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.get_instance_os_policies_compliance", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "GetInstanceOSPoliciesCompliance", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetInventory( @@ -1012,7 +1189,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> inventory.Inventory: r"""Call the get inventory method over HTTP. @@ -1023,8 +1200,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.inventory.Inventory: @@ -1044,6 +1223,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseGetInventory._get_http_options() ) + request, metadata = self._interceptor.pre_get_inventory(request, metadata) transcoded_request = _BaseOsConfigZonalServiceRestTransport._BaseGetInventory._get_transcoded_request( http_options, request @@ -1054,6 +1234,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.GetInventory", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "GetInventory", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigZonalServiceRestTransport._GetInventory._get_response( self._host, @@ -1074,7 +1281,29 @@ def __call__( pb_resp = inventory.Inventory.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_inventory(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = inventory.Inventory.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.get_inventory", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "GetInventory", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetOSPolicyAssignment( @@ -1112,7 +1341,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> os_policy_assignments.OSPolicyAssignment: r"""Call the get os policy assignment method over HTTP. @@ -1123,8 +1352,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.os_policy_assignments.OSPolicyAssignment: @@ -1146,6 +1377,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseGetOSPolicyAssignment._get_http_options() ) + request, metadata = self._interceptor.pre_get_os_policy_assignment( request, metadata ) @@ -1158,6 +1390,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.GetOSPolicyAssignment", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "GetOSPolicyAssignment", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( OsConfigZonalServiceRestTransport._GetOSPolicyAssignment._get_response( @@ -1180,7 +1439,31 @@ def __call__( pb_resp = os_policy_assignments.OSPolicyAssignment.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_os_policy_assignment(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = os_policy_assignments.OSPolicyAssignment.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.get_os_policy_assignment", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "GetOSPolicyAssignment", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetOSPolicyAssignmentReport( @@ -1218,7 +1501,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> os_policy_assignment_reports.OSPolicyAssignmentReport: r"""Call the get os policy assignment report method over HTTP. @@ -1230,8 +1513,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.os_policy_assignment_reports.OSPolicyAssignmentReport: @@ -1243,6 +1528,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseGetOSPolicyAssignmentReport._get_http_options() ) + request, metadata = self._interceptor.pre_get_os_policy_assignment_report( request, metadata ) @@ -1255,6 +1541,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.GetOSPolicyAssignmentReport", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "GetOSPolicyAssignmentReport", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigZonalServiceRestTransport._GetOSPolicyAssignmentReport._get_response( self._host, @@ -1275,7 +1588,33 @@ def __call__( pb_resp = os_policy_assignment_reports.OSPolicyAssignmentReport.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_os_policy_assignment_report(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + os_policy_assignment_reports.OSPolicyAssignmentReport.to_json( + response + ) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.get_os_policy_assignment_report", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "GetOSPolicyAssignmentReport", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetVulnerabilityReport( @@ -1313,7 +1652,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> vulnerability.VulnerabilityReport: r"""Call the get vulnerability report method over HTTP. @@ -1325,8 +1664,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.vulnerability.VulnerabilityReport: @@ -1342,6 +1683,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseGetVulnerabilityReport._get_http_options() ) + request, metadata = self._interceptor.pre_get_vulnerability_report( request, metadata ) @@ -1354,6 +1696,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.GetVulnerabilityReport", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "GetVulnerabilityReport", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( OsConfigZonalServiceRestTransport._GetVulnerabilityReport._get_response( @@ -1376,7 +1745,31 @@ def __call__( pb_resp = vulnerability.VulnerabilityReport.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_vulnerability_report(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = vulnerability.VulnerabilityReport.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.get_vulnerability_report", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "GetVulnerabilityReport", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListInstanceOSPoliciesCompliances( @@ -1416,7 +1809,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> instance_os_policies_compliance.ListInstanceOSPoliciesCompliancesResponse: r"""Call the list instance os policies compliances method over HTTP. @@ -1429,8 +1822,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.instance_os_policies_compliance.ListInstanceOSPoliciesCompliancesResponse: @@ -1443,6 +1838,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseListInstanceOSPoliciesCompliances._get_http_options() ) + ( request, metadata, @@ -1458,6 +1854,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.ListInstanceOSPoliciesCompliances", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "ListInstanceOSPoliciesCompliances", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigZonalServiceRestTransport._ListInstanceOSPoliciesCompliances._get_response( self._host, @@ -1482,7 +1905,31 @@ def __call__( ) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_instance_os_policies_compliances(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = instance_os_policies_compliance.ListInstanceOSPoliciesCompliancesResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.list_instance_os_policies_compliances", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "ListInstanceOSPoliciesCompliances", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListInventories( @@ -1520,7 +1967,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> inventory.ListInventoriesResponse: r"""Call the list inventories method over HTTP. @@ -1532,8 +1979,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.inventory.ListInventoriesResponse: @@ -1546,6 +1995,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseListInventories._get_http_options() ) + request, metadata = self._interceptor.pre_list_inventories( request, metadata ) @@ -1558,6 +2008,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.ListInventories", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "ListInventories", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigZonalServiceRestTransport._ListInventories._get_response( self._host, @@ -1578,7 +2055,31 @@ def __call__( pb_resp = inventory.ListInventoriesResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_inventories(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = inventory.ListInventoriesResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.list_inventories", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "ListInventories", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListOSPolicyAssignmentReports( @@ -1618,7 +2119,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> os_policy_assignment_reports.ListOSPolicyAssignmentReportsResponse: r"""Call the list os policy assignment reports method over HTTP. @@ -1630,8 +2131,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.os_policy_assignment_reports.ListOSPolicyAssignmentReportsResponse: @@ -1644,6 +2147,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseListOSPolicyAssignmentReports._get_http_options() ) + request, metadata = self._interceptor.pre_list_os_policy_assignment_reports( request, metadata ) @@ -1656,6 +2160,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.ListOSPolicyAssignmentReports", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "ListOSPolicyAssignmentReports", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigZonalServiceRestTransport._ListOSPolicyAssignmentReports._get_response( self._host, @@ -1680,7 +2211,31 @@ def __call__( ) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_os_policy_assignment_reports(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = os_policy_assignment_reports.ListOSPolicyAssignmentReportsResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.list_os_policy_assignment_reports", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "ListOSPolicyAssignmentReports", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListOSPolicyAssignmentRevisions( @@ -1720,7 +2275,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> os_policy_assignments.ListOSPolicyAssignmentRevisionsResponse: r"""Call the list os policy assignment revisions method over HTTP. @@ -1732,8 +2287,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.os_policy_assignments.ListOSPolicyAssignmentRevisionsResponse: @@ -1745,6 +2302,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseListOSPolicyAssignmentRevisions._get_http_options() ) + ( request, metadata, @@ -1760,6 +2318,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.ListOSPolicyAssignmentRevisions", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "ListOSPolicyAssignmentRevisions", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigZonalServiceRestTransport._ListOSPolicyAssignmentRevisions._get_response( self._host, @@ -1782,7 +2367,31 @@ def __call__( ) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_os_policy_assignment_revisions(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = os_policy_assignments.ListOSPolicyAssignmentRevisionsResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.list_os_policy_assignment_revisions", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "ListOSPolicyAssignmentRevisions", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListOSPolicyAssignments( @@ -1820,7 +2429,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> os_policy_assignments.ListOSPolicyAssignmentsResponse: r"""Call the list os policy assignments method over HTTP. @@ -1832,8 +2441,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.os_policy_assignments.ListOSPolicyAssignmentsResponse: @@ -1845,6 +2456,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseListOSPolicyAssignments._get_http_options() ) + request, metadata = self._interceptor.pre_list_os_policy_assignments( request, metadata ) @@ -1857,6 +2469,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.ListOSPolicyAssignments", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "ListOSPolicyAssignments", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigZonalServiceRestTransport._ListOSPolicyAssignments._get_response( self._host, @@ -1877,7 +2516,33 @@ def __call__( pb_resp = os_policy_assignments.ListOSPolicyAssignmentsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_os_policy_assignments(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + os_policy_assignments.ListOSPolicyAssignmentsResponse.to_json( + response + ) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.list_os_policy_assignments", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "ListOSPolicyAssignments", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListVulnerabilityReports( @@ -1915,7 +2580,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> vulnerability.ListVulnerabilityReportsResponse: r"""Call the list vulnerability reports method over HTTP. @@ -1928,8 +2593,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.vulnerability.ListVulnerabilityReportsResponse: @@ -1942,6 +2609,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseListVulnerabilityReports._get_http_options() ) + request, metadata = self._interceptor.pre_list_vulnerability_reports( request, metadata ) @@ -1954,6 +2622,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.ListVulnerabilityReports", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "ListVulnerabilityReports", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigZonalServiceRestTransport._ListVulnerabilityReports._get_response( self._host, @@ -1974,7 +2669,31 @@ def __call__( pb_resp = vulnerability.ListVulnerabilityReportsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_vulnerability_reports(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + vulnerability.ListVulnerabilityReportsResponse.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.list_vulnerability_reports", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "ListVulnerabilityReports", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateOSPolicyAssignment( @@ -2013,7 +2732,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the update os policy assignment method over HTTP. @@ -2025,8 +2744,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -2039,6 +2760,7 @@ def __call__( http_options = ( _BaseOsConfigZonalServiceRestTransport._BaseUpdateOSPolicyAssignment._get_http_options() ) + request, metadata = self._interceptor.pre_update_os_policy_assignment( request, metadata ) @@ -2055,6 +2777,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.UpdateOSPolicyAssignment", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "UpdateOSPolicyAssignment", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsConfigZonalServiceRestTransport._UpdateOSPolicyAssignment._get_response( self._host, @@ -2074,7 +2823,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_os_policy_assignment(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.osconfig_v1alpha.OsConfigZonalServiceClient.update_os_policy_assignment", + extra={ + "serviceName": "google.cloud.osconfig.v1alpha.OsConfigZonalService", + "rpcName": "UpdateOSPolicyAssignment", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property diff --git a/packages/google-cloud-os-config/samples/generated_samples/snippet_metadata_google.cloud.osconfig.v1.json b/packages/google-cloud-os-config/samples/generated_samples/snippet_metadata_google.cloud.osconfig.v1.json index f8be9de4a395..c2cae7c3fa77 100644 --- a/packages/google-cloud-os-config/samples/generated_samples/snippet_metadata_google.cloud.osconfig.v1.json +++ b/packages/google-cloud-os-config/samples/generated_samples/snippet_metadata_google.cloud.osconfig.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-os-config", - "version": "1.18.1" + "version": "0.1.0" }, "snippets": [ { @@ -43,7 +43,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.PatchJob", @@ -119,7 +119,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.PatchJob", @@ -208,7 +208,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.PatchDeployment", @@ -296,7 +296,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.PatchDeployment", @@ -377,7 +377,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "shortName": "delete_patch_deployment" @@ -454,7 +454,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "shortName": "delete_patch_deployment" @@ -528,7 +528,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.PatchJob", @@ -604,7 +604,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.PatchJob", @@ -685,7 +685,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.PatchDeployment", @@ -765,7 +765,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.PatchDeployment", @@ -846,7 +846,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.PatchJob", @@ -926,7 +926,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.PatchJob", @@ -1007,7 +1007,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.services.os_config_service.pagers.ListPatchDeploymentsAsyncPager", @@ -1087,7 +1087,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.services.os_config_service.pagers.ListPatchDeploymentsPager", @@ -1168,7 +1168,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.services.os_config_service.pagers.ListPatchJobInstanceDetailsAsyncPager", @@ -1248,7 +1248,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.services.os_config_service.pagers.ListPatchJobInstanceDetailsPager", @@ -1329,7 +1329,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.services.os_config_service.pagers.ListPatchJobsAsyncPager", @@ -1409,7 +1409,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.services.os_config_service.pagers.ListPatchJobsPager", @@ -1490,7 +1490,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.PatchDeployment", @@ -1570,7 +1570,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.PatchDeployment", @@ -1651,7 +1651,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.PatchDeployment", @@ -1731,7 +1731,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.PatchDeployment", @@ -1816,7 +1816,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.PatchDeployment", @@ -1900,7 +1900,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.PatchDeployment", @@ -1989,7 +1989,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -2077,7 +2077,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -2158,7 +2158,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -2238,7 +2238,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -2319,7 +2319,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.Inventory", @@ -2399,7 +2399,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.Inventory", @@ -2480,7 +2480,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.OSPolicyAssignmentReport", @@ -2560,7 +2560,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.OSPolicyAssignmentReport", @@ -2641,7 +2641,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.OSPolicyAssignment", @@ -2721,7 +2721,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.OSPolicyAssignment", @@ -2802,7 +2802,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.VulnerabilityReport", @@ -2882,7 +2882,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.types.VulnerabilityReport", @@ -2963,7 +2963,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.services.os_config_zonal_service.pagers.ListInventoriesAsyncPager", @@ -3043,7 +3043,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.services.os_config_zonal_service.pagers.ListInventoriesPager", @@ -3124,7 +3124,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentReportsAsyncPager", @@ -3204,7 +3204,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentReportsPager", @@ -3285,7 +3285,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentRevisionsAsyncPager", @@ -3365,7 +3365,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentRevisionsPager", @@ -3446,7 +3446,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentsAsyncPager", @@ -3526,7 +3526,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentsPager", @@ -3607,7 +3607,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.services.os_config_zonal_service.pagers.ListVulnerabilityReportsAsyncPager", @@ -3687,7 +3687,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1.services.os_config_zonal_service.pagers.ListVulnerabilityReportsPager", @@ -3772,7 +3772,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -3856,7 +3856,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", diff --git a/packages/google-cloud-os-config/samples/generated_samples/snippet_metadata_google.cloud.osconfig.v1alpha.json b/packages/google-cloud-os-config/samples/generated_samples/snippet_metadata_google.cloud.osconfig.v1alpha.json index 30756b79695a..f8c8df434837 100644 --- a/packages/google-cloud-os-config/samples/generated_samples/snippet_metadata_google.cloud.osconfig.v1alpha.json +++ b/packages/google-cloud-os-config/samples/generated_samples/snippet_metadata_google.cloud.osconfig.v1alpha.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-os-config", - "version": "1.18.1" + "version": "0.1.0" }, "snippets": [ { @@ -55,7 +55,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -143,7 +143,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -224,7 +224,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -304,7 +304,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -385,7 +385,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1alpha.types.InstanceOSPoliciesCompliance", @@ -465,7 +465,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1alpha.types.InstanceOSPoliciesCompliance", @@ -546,7 +546,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1alpha.types.Inventory", @@ -626,7 +626,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1alpha.types.Inventory", @@ -707,7 +707,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1alpha.types.OSPolicyAssignmentReport", @@ -787,7 +787,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1alpha.types.OSPolicyAssignmentReport", @@ -868,7 +868,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1alpha.types.OSPolicyAssignment", @@ -948,7 +948,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1alpha.types.OSPolicyAssignment", @@ -1029,7 +1029,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1alpha.types.VulnerabilityReport", @@ -1109,7 +1109,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1alpha.types.VulnerabilityReport", @@ -1190,7 +1190,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListInstanceOSPoliciesCompliancesAsyncPager", @@ -1270,7 +1270,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListInstanceOSPoliciesCompliancesPager", @@ -1351,7 +1351,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListInventoriesAsyncPager", @@ -1431,7 +1431,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListInventoriesPager", @@ -1512,7 +1512,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentReportsAsyncPager", @@ -1592,7 +1592,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentReportsPager", @@ -1673,7 +1673,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentRevisionsAsyncPager", @@ -1753,7 +1753,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentRevisionsPager", @@ -1834,7 +1834,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentsAsyncPager", @@ -1914,7 +1914,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListOSPolicyAssignmentsPager", @@ -1995,7 +1995,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListVulnerabilityReportsAsyncPager", @@ -2075,7 +2075,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.osconfig_v1alpha.services.os_config_zonal_service.pagers.ListVulnerabilityReportsPager", @@ -2160,7 +2160,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -2244,7 +2244,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", diff --git a/packages/google-cloud-os-config/tests/unit/gapic/osconfig_v1/test_os_config_service.py b/packages/google-cloud-os-config/tests/unit/gapic/osconfig_v1/test_os_config_service.py index d4c9a433c90a..8886f601a114 100644 --- a/packages/google-cloud-os-config/tests/unit/gapic/osconfig_v1/test_os_config_service.py +++ b/packages/google-cloud-os-config/tests/unit/gapic/osconfig_v1/test_os_config_service.py @@ -5830,6 +5830,7 @@ def test_execute_patch_job_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.execute_patch_job(request) @@ -5955,6 +5956,7 @@ def test_get_patch_job_rest_required_fields(request_type=patch_jobs.GetPatchJobR response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_patch_job(request) @@ -6000,6 +6002,7 @@ def test_get_patch_job_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_patch_job(**mock_args) @@ -6132,6 +6135,7 @@ def test_cancel_patch_job_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.cancel_patch_job(request) @@ -6259,6 +6263,7 @@ def test_list_patch_jobs_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_patch_jobs(request) @@ -6313,6 +6318,7 @@ def test_list_patch_jobs_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_patch_jobs(**mock_args) @@ -6518,6 +6524,7 @@ def test_list_patch_job_instance_details_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_patch_job_instance_details(request) @@ -6574,6 +6581,7 @@ def test_list_patch_job_instance_details_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_patch_job_instance_details(**mock_args) @@ -6785,6 +6793,7 @@ def test_create_patch_deployment_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_patch_deployment(request) @@ -6847,6 +6856,7 @@ def test_create_patch_deployment_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_patch_deployment(**mock_args) @@ -6983,6 +6993,7 @@ def test_get_patch_deployment_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_patch_deployment(request) @@ -7028,6 +7039,7 @@ def test_get_patch_deployment_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_patch_deployment(**mock_args) @@ -7172,6 +7184,7 @@ def test_list_patch_deployments_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_patch_deployments(request) @@ -7225,6 +7238,7 @@ def test_list_patch_deployments_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_patch_deployments(**mock_args) @@ -7420,6 +7434,7 @@ def test_delete_patch_deployment_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_patch_deployment(request) @@ -7463,6 +7478,7 @@ def test_delete_patch_deployment_rest_flattened(): json_return_value = "" response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_patch_deployment(**mock_args) @@ -7596,6 +7612,7 @@ def test_update_patch_deployment_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_patch_deployment(request) @@ -7644,6 +7661,7 @@ def test_update_patch_deployment_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_patch_deployment(**mock_args) @@ -7782,6 +7800,7 @@ def test_pause_patch_deployment_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.pause_patch_deployment(request) @@ -7827,6 +7846,7 @@ def test_pause_patch_deployment_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.pause_patch_deployment(**mock_args) @@ -7963,6 +7983,7 @@ def test_resume_patch_deployment_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.resume_patch_deployment(request) @@ -8008,6 +8029,7 @@ def test_resume_patch_deployment_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.resume_patch_deployment(**mock_args) @@ -8824,6 +8846,7 @@ def test_execute_patch_job_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.execute_patch_job(request) @@ -8866,6 +8889,7 @@ def test_execute_patch_job_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.execute_patch_job(request) # Establish that the response is the type that we expect. @@ -8913,6 +8937,7 @@ def test_execute_patch_job_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = patch_jobs.PatchJob.to_json(patch_jobs.PatchJob()) req.return_value.content = return_value @@ -8955,6 +8980,7 @@ def test_get_patch_job_rest_bad_request(request_type=patch_jobs.GetPatchJobReque response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_patch_job(request) @@ -8997,6 +9023,7 @@ def test_get_patch_job_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_patch_job(request) # Establish that the response is the type that we expect. @@ -9042,6 +9069,7 @@ def test_get_patch_job_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = patch_jobs.PatchJob.to_json(patch_jobs.PatchJob()) req.return_value.content = return_value @@ -9086,6 +9114,7 @@ def test_cancel_patch_job_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.cancel_patch_job(request) @@ -9128,6 +9157,7 @@ def test_cancel_patch_job_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.cancel_patch_job(request) # Establish that the response is the type that we expect. @@ -9175,6 +9205,7 @@ def test_cancel_patch_job_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = patch_jobs.PatchJob.to_json(patch_jobs.PatchJob()) req.return_value.content = return_value @@ -9217,6 +9248,7 @@ def test_list_patch_jobs_rest_bad_request(request_type=patch_jobs.ListPatchJobsR response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_patch_jobs(request) @@ -9252,6 +9284,7 @@ def test_list_patch_jobs_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_patch_jobs(request) # Establish that the response is the type that we expect. @@ -9292,6 +9325,7 @@ def test_list_patch_jobs_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = patch_jobs.ListPatchJobsResponse.to_json( patch_jobs.ListPatchJobsResponse() ) @@ -9338,6 +9372,7 @@ def test_list_patch_job_instance_details_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_patch_job_instance_details(request) @@ -9373,6 +9408,7 @@ def test_list_patch_job_instance_details_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_patch_job_instance_details(request) # Establish that the response is the type that we expect. @@ -9414,6 +9450,7 @@ def test_list_patch_job_instance_details_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = patch_jobs.ListPatchJobInstanceDetailsResponse.to_json( patch_jobs.ListPatchJobInstanceDetailsResponse() ) @@ -9460,6 +9497,7 @@ def test_create_patch_deployment_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_patch_deployment(request) @@ -9660,6 +9698,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_patch_deployment(request) # Establish that the response is the type that we expect. @@ -9702,6 +9741,7 @@ def test_create_patch_deployment_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = patch_deployments.PatchDeployment.to_json( patch_deployments.PatchDeployment() ) @@ -9748,6 +9788,7 @@ def test_get_patch_deployment_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_patch_deployment(request) @@ -9785,6 +9826,7 @@ def test_get_patch_deployment_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_patch_deployment(request) # Establish that the response is the type that we expect. @@ -9827,6 +9869,7 @@ def test_get_patch_deployment_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = patch_deployments.PatchDeployment.to_json( patch_deployments.PatchDeployment() ) @@ -9873,6 +9916,7 @@ def test_list_patch_deployments_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_patch_deployments(request) @@ -9908,6 +9952,7 @@ def test_list_patch_deployments_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_patch_deployments(request) # Establish that the response is the type that we expect. @@ -9948,6 +9993,7 @@ def test_list_patch_deployments_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = patch_deployments.ListPatchDeploymentsResponse.to_json( patch_deployments.ListPatchDeploymentsResponse() ) @@ -9994,6 +10040,7 @@ def test_delete_patch_deployment_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_patch_deployment(request) @@ -10024,6 +10071,7 @@ def test_delete_patch_deployment_rest_call_success(request_type): json_return_value = "" response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_patch_deployment(request) # Establish that the response is the type that we expect. @@ -10060,6 +10108,7 @@ def test_delete_patch_deployment_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} request = patch_deployments.DeletePatchDeploymentRequest() metadata = [ @@ -10102,6 +10151,7 @@ def test_update_patch_deployment_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_patch_deployment(request) @@ -10304,6 +10354,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_patch_deployment(request) # Establish that the response is the type that we expect. @@ -10346,6 +10397,7 @@ def test_update_patch_deployment_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = patch_deployments.PatchDeployment.to_json( patch_deployments.PatchDeployment() ) @@ -10392,6 +10444,7 @@ def test_pause_patch_deployment_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.pause_patch_deployment(request) @@ -10429,6 +10482,7 @@ def test_pause_patch_deployment_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.pause_patch_deployment(request) # Establish that the response is the type that we expect. @@ -10471,6 +10525,7 @@ def test_pause_patch_deployment_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = patch_deployments.PatchDeployment.to_json( patch_deployments.PatchDeployment() ) @@ -10517,6 +10572,7 @@ def test_resume_patch_deployment_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.resume_patch_deployment(request) @@ -10554,6 +10610,7 @@ def test_resume_patch_deployment_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.resume_patch_deployment(request) # Establish that the response is the type that we expect. @@ -10596,6 +10653,7 @@ def test_resume_patch_deployment_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = patch_deployments.PatchDeployment.to_json( patch_deployments.PatchDeployment() ) diff --git a/packages/google-cloud-os-config/tests/unit/gapic/osconfig_v1/test_os_config_zonal_service.py b/packages/google-cloud-os-config/tests/unit/gapic/osconfig_v1/test_os_config_zonal_service.py index bfedb455d101..204dba80482c 100644 --- a/packages/google-cloud-os-config/tests/unit/gapic/osconfig_v1/test_os_config_zonal_service.py +++ b/packages/google-cloud-os-config/tests/unit/gapic/osconfig_v1/test_os_config_zonal_service.py @@ -6502,6 +6502,7 @@ def test_create_os_policy_assignment_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_os_policy_assignment(request) @@ -6564,6 +6565,7 @@ def test_create_os_policy_assignment_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_os_policy_assignment(**mock_args) @@ -6703,6 +6705,7 @@ def test_update_os_policy_assignment_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_os_policy_assignment(request) @@ -6753,6 +6756,7 @@ def test_update_os_policy_assignment_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_os_policy_assignment(**mock_args) @@ -6892,6 +6896,7 @@ def test_get_os_policy_assignment_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_os_policy_assignment(request) @@ -6939,6 +6944,7 @@ def test_get_os_policy_assignment_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_os_policy_assignment(**mock_args) @@ -7084,6 +7090,7 @@ def test_list_os_policy_assignments_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_os_policy_assignments(request) @@ -7139,6 +7146,7 @@ def test_list_os_policy_assignments_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_os_policy_assignments(**mock_args) @@ -7352,6 +7360,7 @@ def test_list_os_policy_assignment_revisions_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_os_policy_assignment_revisions(request) @@ -7411,6 +7420,7 @@ def test_list_os_policy_assignment_revisions_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_os_policy_assignment_revisions(**mock_args) @@ -7620,6 +7630,7 @@ def test_delete_os_policy_assignment_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_os_policy_assignment(request) @@ -7665,6 +7676,7 @@ def test_delete_os_policy_assignment_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_os_policy_assignment(**mock_args) @@ -7803,6 +7815,7 @@ def test_get_os_policy_assignment_report_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_os_policy_assignment_report(request) @@ -7854,6 +7867,7 @@ def test_get_os_policy_assignment_report_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_os_policy_assignment_report(**mock_args) @@ -8002,6 +8016,7 @@ def test_list_os_policy_assignment_reports_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_os_policy_assignment_reports(request) @@ -8066,6 +8081,7 @@ def test_list_os_policy_assignment_reports_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_os_policy_assignment_reports(**mock_args) @@ -8272,6 +8288,7 @@ def test_get_inventory_rest_required_fields(request_type=inventory.GetInventoryR response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_inventory(request) @@ -8319,6 +8336,7 @@ def test_get_inventory_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_inventory(**mock_args) @@ -8461,6 +8479,7 @@ def test_list_inventories_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_inventories(request) @@ -8518,6 +8537,7 @@ def test_list_inventories_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_inventories(**mock_args) @@ -8717,6 +8737,7 @@ def test_get_vulnerability_report_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_vulnerability_report(request) @@ -8764,6 +8785,7 @@ def test_get_vulnerability_report_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_vulnerability_report(**mock_args) @@ -8910,6 +8932,7 @@ def test_list_vulnerability_reports_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_vulnerability_reports(request) @@ -8966,6 +8989,7 @@ def test_list_vulnerability_reports_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_vulnerability_reports(**mock_args) @@ -9837,6 +9861,7 @@ def test_create_os_policy_assignment_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_os_policy_assignment(request) @@ -10067,6 +10092,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_os_policy_assignment(request) # Establish that the response is the type that we expect. @@ -10110,6 +10136,7 @@ def test_create_os_policy_assignment_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -10158,6 +10185,7 @@ def test_update_os_policy_assignment_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_os_policy_assignment(request) @@ -10392,6 +10420,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_os_policy_assignment(request) # Establish that the response is the type that we expect. @@ -10435,6 +10464,7 @@ def test_update_os_policy_assignment_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -10481,6 +10511,7 @@ def test_get_os_policy_assignment_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_os_policy_assignment(request) @@ -10526,6 +10557,7 @@ def test_get_os_policy_assignment_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_os_policy_assignment(request) # Establish that the response is the type that we expect. @@ -10577,6 +10609,7 @@ def test_get_os_policy_assignment_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = os_policy_assignments.OSPolicyAssignment.to_json( os_policy_assignments.OSPolicyAssignment() ) @@ -10623,6 +10656,7 @@ def test_list_os_policy_assignments_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_os_policy_assignments(request) @@ -10660,6 +10694,7 @@ def test_list_os_policy_assignments_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_os_policy_assignments(request) # Establish that the response is the type that we expect. @@ -10701,6 +10736,7 @@ def test_list_os_policy_assignments_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = os_policy_assignments.ListOSPolicyAssignmentsResponse.to_json( os_policy_assignments.ListOSPolicyAssignmentsResponse() ) @@ -10749,6 +10785,7 @@ def test_list_os_policy_assignment_revisions_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_os_policy_assignment_revisions(request) @@ -10788,6 +10825,7 @@ def test_list_os_policy_assignment_revisions_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_os_policy_assignment_revisions(request) # Establish that the response is the type that we expect. @@ -10830,6 +10868,7 @@ def test_list_os_policy_assignment_revisions_rest_interceptors(null_interceptor) req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = ( os_policy_assignments.ListOSPolicyAssignmentRevisionsResponse.to_json( os_policy_assignments.ListOSPolicyAssignmentRevisionsResponse() @@ -10882,6 +10921,7 @@ def test_delete_os_policy_assignment_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_os_policy_assignment(request) @@ -10914,6 +10954,7 @@ def test_delete_os_policy_assignment_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_os_policy_assignment(request) # Establish that the response is the type that we expect. @@ -10957,6 +10998,7 @@ def test_delete_os_policy_assignment_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -11003,6 +11045,7 @@ def test_get_os_policy_assignment_report_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_os_policy_assignment_report(request) @@ -11045,6 +11088,7 @@ def test_get_os_policy_assignment_report_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_os_policy_assignment_report(request) # Establish that the response is the type that we expect. @@ -11090,6 +11134,7 @@ def test_get_os_policy_assignment_report_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = os_policy_assignment_reports.OSPolicyAssignmentReport.to_json( os_policy_assignment_reports.OSPolicyAssignmentReport() ) @@ -11138,6 +11183,7 @@ def test_list_os_policy_assignment_reports_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_os_policy_assignment_reports(request) @@ -11181,6 +11227,7 @@ def test_list_os_policy_assignment_reports_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_os_policy_assignment_reports(request) # Establish that the response is the type that we expect. @@ -11225,6 +11272,7 @@ def test_list_os_policy_assignment_reports_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = ( os_policy_assignment_reports.ListOSPolicyAssignmentReportsResponse.to_json( os_policy_assignment_reports.ListOSPolicyAssignmentReportsResponse() @@ -11275,6 +11323,7 @@ def test_get_inventory_rest_bad_request(request_type=inventory.GetInventoryReque response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_inventory(request) @@ -11312,6 +11361,7 @@ def test_get_inventory_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_inventory(request) # Establish that the response is the type that we expect. @@ -11350,6 +11400,7 @@ def test_get_inventory_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = inventory.Inventory.to_json(inventory.Inventory()) req.return_value.content = return_value @@ -11394,6 +11445,7 @@ def test_list_inventories_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_inventories(request) @@ -11429,6 +11481,7 @@ def test_list_inventories_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_inventories(request) # Establish that the response is the type that we expect. @@ -11469,6 +11522,7 @@ def test_list_inventories_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = inventory.ListInventoriesResponse.to_json( inventory.ListInventoriesResponse() ) @@ -11517,6 +11571,7 @@ def test_get_vulnerability_report_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_vulnerability_report(request) @@ -11554,6 +11609,7 @@ def test_get_vulnerability_report_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_vulnerability_report(request) # Establish that the response is the type that we expect. @@ -11594,6 +11650,7 @@ def test_get_vulnerability_report_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = vulnerability.VulnerabilityReport.to_json( vulnerability.VulnerabilityReport() ) @@ -11640,6 +11697,7 @@ def test_list_vulnerability_reports_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_vulnerability_reports(request) @@ -11675,6 +11733,7 @@ def test_list_vulnerability_reports_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_vulnerability_reports(request) # Establish that the response is the type that we expect. @@ -11716,6 +11775,7 @@ def test_list_vulnerability_reports_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = vulnerability.ListVulnerabilityReportsResponse.to_json( vulnerability.ListVulnerabilityReportsResponse() ) diff --git a/packages/google-cloud-os-config/tests/unit/gapic/osconfig_v1alpha/test_os_config_zonal_service.py b/packages/google-cloud-os-config/tests/unit/gapic/osconfig_v1alpha/test_os_config_zonal_service.py index 7959347c0bd4..aeb30b77eb53 100644 --- a/packages/google-cloud-os-config/tests/unit/gapic/osconfig_v1alpha/test_os_config_zonal_service.py +++ b/packages/google-cloud-os-config/tests/unit/gapic/osconfig_v1alpha/test_os_config_zonal_service.py @@ -7456,6 +7456,7 @@ def test_create_os_policy_assignment_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_os_policy_assignment(request) @@ -7518,6 +7519,7 @@ def test_create_os_policy_assignment_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_os_policy_assignment(**mock_args) @@ -7657,6 +7659,7 @@ def test_update_os_policy_assignment_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_os_policy_assignment(request) @@ -7707,6 +7710,7 @@ def test_update_os_policy_assignment_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_os_policy_assignment(**mock_args) @@ -7846,6 +7850,7 @@ def test_get_os_policy_assignment_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_os_policy_assignment(request) @@ -7893,6 +7898,7 @@ def test_get_os_policy_assignment_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_os_policy_assignment(**mock_args) @@ -8038,6 +8044,7 @@ def test_list_os_policy_assignments_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_os_policy_assignments(request) @@ -8093,6 +8100,7 @@ def test_list_os_policy_assignments_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_os_policy_assignments(**mock_args) @@ -8306,6 +8314,7 @@ def test_list_os_policy_assignment_revisions_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_os_policy_assignment_revisions(request) @@ -8365,6 +8374,7 @@ def test_list_os_policy_assignment_revisions_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_os_policy_assignment_revisions(**mock_args) @@ -8574,6 +8584,7 @@ def test_delete_os_policy_assignment_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_os_policy_assignment(request) @@ -8619,6 +8630,7 @@ def test_delete_os_policy_assignment_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_os_policy_assignment(**mock_args) @@ -8759,6 +8771,7 @@ def test_get_instance_os_policies_compliance_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_instance_os_policies_compliance(request) @@ -8810,6 +8823,7 @@ def test_get_instance_os_policies_compliance_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_instance_os_policies_compliance(**mock_args) @@ -8964,6 +8978,7 @@ def test_list_instance_os_policies_compliances_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_instance_os_policies_compliances(request) @@ -9024,6 +9039,7 @@ def test_list_instance_os_policies_compliances_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_instance_os_policies_compliances(**mock_args) @@ -9235,6 +9251,7 @@ def test_get_os_policy_assignment_report_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_os_policy_assignment_report(request) @@ -9286,6 +9303,7 @@ def test_get_os_policy_assignment_report_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_os_policy_assignment_report(**mock_args) @@ -9434,6 +9452,7 @@ def test_list_os_policy_assignment_reports_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_os_policy_assignment_reports(request) @@ -9498,6 +9517,7 @@ def test_list_os_policy_assignment_reports_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_os_policy_assignment_reports(**mock_args) @@ -9704,6 +9724,7 @@ def test_get_inventory_rest_required_fields(request_type=inventory.GetInventoryR response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_inventory(request) @@ -9751,6 +9772,7 @@ def test_get_inventory_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_inventory(**mock_args) @@ -9893,6 +9915,7 @@ def test_list_inventories_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_inventories(request) @@ -9950,6 +9973,7 @@ def test_list_inventories_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_inventories(**mock_args) @@ -10149,6 +10173,7 @@ def test_get_vulnerability_report_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_vulnerability_report(request) @@ -10196,6 +10221,7 @@ def test_get_vulnerability_report_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_vulnerability_report(**mock_args) @@ -10342,6 +10368,7 @@ def test_list_vulnerability_reports_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_vulnerability_reports(request) @@ -10398,6 +10425,7 @@ def test_list_vulnerability_reports_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_vulnerability_reports(**mock_args) @@ -11390,6 +11418,7 @@ def test_create_os_policy_assignment_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_os_policy_assignment(request) @@ -11625,6 +11654,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_os_policy_assignment(request) # Establish that the response is the type that we expect. @@ -11668,6 +11698,7 @@ def test_create_os_policy_assignment_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -11716,6 +11747,7 @@ def test_update_os_policy_assignment_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_os_policy_assignment(request) @@ -11955,6 +11987,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_os_policy_assignment(request) # Establish that the response is the type that we expect. @@ -11998,6 +12031,7 @@ def test_update_os_policy_assignment_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -12044,6 +12078,7 @@ def test_get_os_policy_assignment_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_os_policy_assignment(request) @@ -12089,6 +12124,7 @@ def test_get_os_policy_assignment_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_os_policy_assignment(request) # Establish that the response is the type that we expect. @@ -12140,6 +12176,7 @@ def test_get_os_policy_assignment_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = os_policy_assignments.OSPolicyAssignment.to_json( os_policy_assignments.OSPolicyAssignment() ) @@ -12186,6 +12223,7 @@ def test_list_os_policy_assignments_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_os_policy_assignments(request) @@ -12223,6 +12261,7 @@ def test_list_os_policy_assignments_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_os_policy_assignments(request) # Establish that the response is the type that we expect. @@ -12264,6 +12303,7 @@ def test_list_os_policy_assignments_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = os_policy_assignments.ListOSPolicyAssignmentsResponse.to_json( os_policy_assignments.ListOSPolicyAssignmentsResponse() ) @@ -12312,6 +12352,7 @@ def test_list_os_policy_assignment_revisions_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_os_policy_assignment_revisions(request) @@ -12351,6 +12392,7 @@ def test_list_os_policy_assignment_revisions_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_os_policy_assignment_revisions(request) # Establish that the response is the type that we expect. @@ -12393,6 +12435,7 @@ def test_list_os_policy_assignment_revisions_rest_interceptors(null_interceptor) req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = ( os_policy_assignments.ListOSPolicyAssignmentRevisionsResponse.to_json( os_policy_assignments.ListOSPolicyAssignmentRevisionsResponse() @@ -12445,6 +12488,7 @@ def test_delete_os_policy_assignment_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_os_policy_assignment(request) @@ -12477,6 +12521,7 @@ def test_delete_os_policy_assignment_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_os_policy_assignment(request) # Establish that the response is the type that we expect. @@ -12520,6 +12565,7 @@ def test_delete_os_policy_assignment_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -12566,6 +12612,7 @@ def test_get_instance_os_policies_compliance_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_instance_os_policies_compliance(request) @@ -12610,6 +12657,7 @@ def test_get_instance_os_policies_compliance_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_instance_os_policies_compliance(request) # Establish that the response is the type that we expect. @@ -12661,6 +12709,7 @@ def test_get_instance_os_policies_compliance_rest_interceptors(null_interceptor) req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = ( instance_os_policies_compliance.InstanceOSPoliciesCompliance.to_json( instance_os_policies_compliance.InstanceOSPoliciesCompliance() @@ -12713,6 +12762,7 @@ def test_list_instance_os_policies_compliances_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_instance_os_policies_compliances(request) @@ -12752,6 +12802,7 @@ def test_list_instance_os_policies_compliances_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_instance_os_policies_compliances(request) # Establish that the response is the type that we expect. @@ -12794,6 +12845,7 @@ def test_list_instance_os_policies_compliances_rest_interceptors(null_intercepto req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = instance_os_policies_compliance.ListInstanceOSPoliciesCompliancesResponse.to_json( instance_os_policies_compliance.ListInstanceOSPoliciesCompliancesResponse() ) @@ -12846,6 +12898,7 @@ def test_get_os_policy_assignment_report_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_os_policy_assignment_report(request) @@ -12888,6 +12941,7 @@ def test_get_os_policy_assignment_report_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_os_policy_assignment_report(request) # Establish that the response is the type that we expect. @@ -12933,6 +12987,7 @@ def test_get_os_policy_assignment_report_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = os_policy_assignment_reports.OSPolicyAssignmentReport.to_json( os_policy_assignment_reports.OSPolicyAssignmentReport() ) @@ -12981,6 +13036,7 @@ def test_list_os_policy_assignment_reports_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_os_policy_assignment_reports(request) @@ -13024,6 +13080,7 @@ def test_list_os_policy_assignment_reports_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_os_policy_assignment_reports(request) # Establish that the response is the type that we expect. @@ -13068,6 +13125,7 @@ def test_list_os_policy_assignment_reports_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = ( os_policy_assignment_reports.ListOSPolicyAssignmentReportsResponse.to_json( os_policy_assignment_reports.ListOSPolicyAssignmentReportsResponse() @@ -13118,6 +13176,7 @@ def test_get_inventory_rest_bad_request(request_type=inventory.GetInventoryReque response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_inventory(request) @@ -13155,6 +13214,7 @@ def test_get_inventory_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_inventory(request) # Establish that the response is the type that we expect. @@ -13193,6 +13253,7 @@ def test_get_inventory_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = inventory.Inventory.to_json(inventory.Inventory()) req.return_value.content = return_value @@ -13237,6 +13298,7 @@ def test_list_inventories_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_inventories(request) @@ -13272,6 +13334,7 @@ def test_list_inventories_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_inventories(request) # Establish that the response is the type that we expect. @@ -13312,6 +13375,7 @@ def test_list_inventories_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = inventory.ListInventoriesResponse.to_json( inventory.ListInventoriesResponse() ) @@ -13360,6 +13424,7 @@ def test_get_vulnerability_report_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_vulnerability_report(request) @@ -13397,6 +13462,7 @@ def test_get_vulnerability_report_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_vulnerability_report(request) # Establish that the response is the type that we expect. @@ -13437,6 +13503,7 @@ def test_get_vulnerability_report_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = vulnerability.VulnerabilityReport.to_json( vulnerability.VulnerabilityReport() ) @@ -13483,6 +13550,7 @@ def test_list_vulnerability_reports_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_vulnerability_reports(request) @@ -13518,6 +13586,7 @@ def test_list_vulnerability_reports_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_vulnerability_reports(request) # Establish that the response is the type that we expect. @@ -13559,6 +13628,7 @@ def test_list_vulnerability_reports_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = vulnerability.ListVulnerabilityReportsResponse.to_json( vulnerability.ListVulnerabilityReportsResponse() ) diff --git a/packages/google-cloud-os-login/google/cloud/oslogin/gapic_version.py b/packages/google-cloud-os-login/google/cloud/oslogin/gapic_version.py index c7d2e6b06092..558c8aab67c5 100644 --- a/packages/google-cloud-os-login/google/cloud/oslogin/gapic_version.py +++ b/packages/google-cloud-os-login/google/cloud/oslogin/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.15.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-os-login/google/cloud/oslogin_v1/gapic_version.py b/packages/google-cloud-os-login/google/cloud/oslogin_v1/gapic_version.py index c7d2e6b06092..558c8aab67c5 100644 --- a/packages/google-cloud-os-login/google/cloud/oslogin_v1/gapic_version.py +++ b/packages/google-cloud-os-login/google/cloud/oslogin_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.15.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_service/async_client.py b/packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_service/async_client.py index d3f4d4cc7247..997e490841fc 100644 --- a/packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_service/async_client.py +++ b/packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_service/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -51,6 +52,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, OsLoginServiceTransport from .transports.grpc_asyncio import OsLoginServiceGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class OsLoginServiceAsyncClient: """Cloud OS Login API @@ -267,6 +277,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.oslogin_v1.OsLoginServiceAsyncClient`.", + extra={ + "serviceName": "google.cloud.oslogin.v1.OsLoginService", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.oslogin.v1.OsLoginService", + "credentialsType": None, + }, + ) + async def create_ssh_public_key( self, request: Optional[Union[oslogin.CreateSshPublicKeyRequest, dict]] = None, @@ -275,7 +307,7 @@ async def create_ssh_public_key( ssh_public_key: Optional[common.SshPublicKey] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> common.SshPublicKey: r"""Create an SSH public key @@ -326,8 +358,10 @@ async def sample_create_ssh_public_key(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.oslogin_v1.common.types.SshPublicKey: @@ -390,7 +424,7 @@ async def delete_posix_account( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Deletes a POSIX account. @@ -433,8 +467,10 @@ async def sample_delete_posix_account(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ # Create or coerce a protobuf request object. # - Quick check: If we got a request object, we should *not* have @@ -486,7 +522,7 @@ async def delete_ssh_public_key( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Deletes an SSH public key. @@ -529,8 +565,10 @@ async def sample_delete_ssh_public_key(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ # Create or coerce a protobuf request object. # - Quick check: If we got a request object, we should *not* have @@ -582,7 +620,7 @@ async def get_login_profile( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> oslogin.LoginProfile: r"""Retrieves the profile information used for logging in to a virtual machine on Google Compute Engine. @@ -627,8 +665,10 @@ async def sample_get_login_profile(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.oslogin_v1.types.LoginProfile: @@ -690,7 +730,7 @@ async def get_ssh_public_key( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> common.SshPublicKey: r"""Retrieves an SSH public key. @@ -736,8 +776,10 @@ async def sample_get_ssh_public_key(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.oslogin_v1.common.types.SshPublicKey: @@ -800,7 +842,7 @@ async def import_ssh_public_key( project_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> oslogin.ImportSshPublicKeyResponse: r"""Adds an SSH public key and returns the profile information. Default POSIX account information is set @@ -861,8 +903,10 @@ async def sample_import_ssh_public_key(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.oslogin_v1.types.ImportSshPublicKeyResponse: @@ -929,7 +973,7 @@ async def update_ssh_public_key( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> common.SshPublicKey: r"""Updates an SSH public key and returns the profile information. This method supports patch semantics. @@ -990,8 +1034,10 @@ async def sample_update_ssh_public_key(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.oslogin_v1.common.types.SshPublicKey: diff --git a/packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_service/client.py b/packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_service/client.py index eaef1d103a71..f29353952e1f 100644 --- a/packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_service/client.py +++ b/packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_service/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.protobuf import field_mask_pb2 # type: ignore from google.cloud.oslogin_v1.common.types import common @@ -597,6 +607,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -662,6 +676,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.oslogin_v1.OsLoginServiceClient`.", + extra={ + "serviceName": "google.cloud.oslogin.v1.OsLoginService", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.oslogin.v1.OsLoginService", + "credentialsType": None, + }, + ) + def create_ssh_public_key( self, request: Optional[Union[oslogin.CreateSshPublicKeyRequest, dict]] = None, @@ -670,7 +707,7 @@ def create_ssh_public_key( ssh_public_key: Optional[common.SshPublicKey] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> common.SshPublicKey: r"""Create an SSH public key @@ -721,8 +758,10 @@ def sample_create_ssh_public_key(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.oslogin_v1.common.types.SshPublicKey: @@ -782,7 +821,7 @@ def delete_posix_account( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Deletes a POSIX account. @@ -825,8 +864,10 @@ def sample_delete_posix_account(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ # Create or coerce a protobuf request object. # - Quick check: If we got a request object, we should *not* have @@ -875,7 +916,7 @@ def delete_ssh_public_key( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Deletes an SSH public key. @@ -918,8 +959,10 @@ def sample_delete_ssh_public_key(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ # Create or coerce a protobuf request object. # - Quick check: If we got a request object, we should *not* have @@ -968,7 +1011,7 @@ def get_login_profile( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> oslogin.LoginProfile: r"""Retrieves the profile information used for logging in to a virtual machine on Google Compute Engine. @@ -1013,8 +1056,10 @@ def sample_get_login_profile(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.oslogin_v1.types.LoginProfile: @@ -1073,7 +1118,7 @@ def get_ssh_public_key( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> common.SshPublicKey: r"""Retrieves an SSH public key. @@ -1119,8 +1164,10 @@ def sample_get_ssh_public_key(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.oslogin_v1.common.types.SshPublicKey: @@ -1180,7 +1227,7 @@ def import_ssh_public_key( project_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> oslogin.ImportSshPublicKeyResponse: r"""Adds an SSH public key and returns the profile information. Default POSIX account information is set @@ -1241,8 +1288,10 @@ def sample_import_ssh_public_key(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.oslogin_v1.types.ImportSshPublicKeyResponse: @@ -1306,7 +1355,7 @@ def update_ssh_public_key( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> common.SshPublicKey: r"""Updates an SSH public key and returns the profile information. This method supports patch semantics. @@ -1367,8 +1416,10 @@ def sample_update_ssh_public_key(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.oslogin_v1.common.types.SshPublicKey: diff --git a/packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_service/transports/grpc.py b/packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_service/transports/grpc.py index c039c044aad3..4748cd6419d5 100644 --- a/packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_service/transports/grpc.py +++ b/packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_service/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -21,13 +24,91 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.protobuf import empty_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.oslogin_v1.common.types import common from google.cloud.oslogin_v1.types import oslogin from .base import DEFAULT_CLIENT_INFO, OsLoginServiceTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.oslogin.v1.OsLoginService", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.oslogin.v1.OsLoginService", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class OsLoginServiceGrpcTransport(OsLoginServiceTransport): """gRPC backend transport for OsLoginService. @@ -185,7 +266,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -259,7 +345,7 @@ def create_ssh_public_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_ssh_public_key" not in self._stubs: - self._stubs["create_ssh_public_key"] = self.grpc_channel.unary_unary( + self._stubs["create_ssh_public_key"] = self._logged_channel.unary_unary( "/google.cloud.oslogin.v1.OsLoginService/CreateSshPublicKey", request_serializer=oslogin.CreateSshPublicKeyRequest.serialize, response_deserializer=common.SshPublicKey.deserialize, @@ -285,7 +371,7 @@ def delete_posix_account( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_posix_account" not in self._stubs: - self._stubs["delete_posix_account"] = self.grpc_channel.unary_unary( + self._stubs["delete_posix_account"] = self._logged_channel.unary_unary( "/google.cloud.oslogin.v1.OsLoginService/DeletePosixAccount", request_serializer=oslogin.DeletePosixAccountRequest.serialize, response_deserializer=empty_pb2.Empty.FromString, @@ -311,7 +397,7 @@ def delete_ssh_public_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_ssh_public_key" not in self._stubs: - self._stubs["delete_ssh_public_key"] = self.grpc_channel.unary_unary( + self._stubs["delete_ssh_public_key"] = self._logged_channel.unary_unary( "/google.cloud.oslogin.v1.OsLoginService/DeleteSshPublicKey", request_serializer=oslogin.DeleteSshPublicKeyRequest.serialize, response_deserializer=empty_pb2.Empty.FromString, @@ -338,7 +424,7 @@ def get_login_profile( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_login_profile" not in self._stubs: - self._stubs["get_login_profile"] = self.grpc_channel.unary_unary( + self._stubs["get_login_profile"] = self._logged_channel.unary_unary( "/google.cloud.oslogin.v1.OsLoginService/GetLoginProfile", request_serializer=oslogin.GetLoginProfileRequest.serialize, response_deserializer=oslogin.LoginProfile.deserialize, @@ -364,7 +450,7 @@ def get_ssh_public_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_ssh_public_key" not in self._stubs: - self._stubs["get_ssh_public_key"] = self.grpc_channel.unary_unary( + self._stubs["get_ssh_public_key"] = self._logged_channel.unary_unary( "/google.cloud.oslogin.v1.OsLoginService/GetSshPublicKey", request_serializer=oslogin.GetSshPublicKeyRequest.serialize, response_deserializer=common.SshPublicKey.deserialize, @@ -395,7 +481,7 @@ def import_ssh_public_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "import_ssh_public_key" not in self._stubs: - self._stubs["import_ssh_public_key"] = self.grpc_channel.unary_unary( + self._stubs["import_ssh_public_key"] = self._logged_channel.unary_unary( "/google.cloud.oslogin.v1.OsLoginService/ImportSshPublicKey", request_serializer=oslogin.ImportSshPublicKeyRequest.serialize, response_deserializer=oslogin.ImportSshPublicKeyResponse.deserialize, @@ -422,7 +508,7 @@ def update_ssh_public_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_ssh_public_key" not in self._stubs: - self._stubs["update_ssh_public_key"] = self.grpc_channel.unary_unary( + self._stubs["update_ssh_public_key"] = self._logged_channel.unary_unary( "/google.cloud.oslogin.v1.OsLoginService/UpdateSshPublicKey", request_serializer=oslogin.UpdateSshPublicKeyRequest.serialize, response_deserializer=common.SshPublicKey.deserialize, @@ -430,7 +516,7 @@ def update_ssh_public_key( return self._stubs["update_ssh_public_key"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_service/transports/grpc_asyncio.py b/packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_service/transports/grpc_asyncio.py index 0dad331f6072..742736979e91 100644 --- a/packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_service/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -23,8 +26,11 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.protobuf import empty_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.oslogin_v1.common.types import common from google.cloud.oslogin_v1.types import oslogin @@ -32,6 +38,82 @@ from .base import DEFAULT_CLIENT_INFO, OsLoginServiceTransport from .grpc import OsLoginServiceGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.oslogin.v1.OsLoginService", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.oslogin.v1.OsLoginService", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class OsLoginServiceGrpcAsyncIOTransport(OsLoginServiceTransport): """gRPC AsyncIO backend transport for OsLoginService. @@ -232,10 +314,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -267,7 +352,7 @@ def create_ssh_public_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_ssh_public_key" not in self._stubs: - self._stubs["create_ssh_public_key"] = self.grpc_channel.unary_unary( + self._stubs["create_ssh_public_key"] = self._logged_channel.unary_unary( "/google.cloud.oslogin.v1.OsLoginService/CreateSshPublicKey", request_serializer=oslogin.CreateSshPublicKeyRequest.serialize, response_deserializer=common.SshPublicKey.deserialize, @@ -293,7 +378,7 @@ def delete_posix_account( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_posix_account" not in self._stubs: - self._stubs["delete_posix_account"] = self.grpc_channel.unary_unary( + self._stubs["delete_posix_account"] = self._logged_channel.unary_unary( "/google.cloud.oslogin.v1.OsLoginService/DeletePosixAccount", request_serializer=oslogin.DeletePosixAccountRequest.serialize, response_deserializer=empty_pb2.Empty.FromString, @@ -319,7 +404,7 @@ def delete_ssh_public_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_ssh_public_key" not in self._stubs: - self._stubs["delete_ssh_public_key"] = self.grpc_channel.unary_unary( + self._stubs["delete_ssh_public_key"] = self._logged_channel.unary_unary( "/google.cloud.oslogin.v1.OsLoginService/DeleteSshPublicKey", request_serializer=oslogin.DeleteSshPublicKeyRequest.serialize, response_deserializer=empty_pb2.Empty.FromString, @@ -346,7 +431,7 @@ def get_login_profile( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_login_profile" not in self._stubs: - self._stubs["get_login_profile"] = self.grpc_channel.unary_unary( + self._stubs["get_login_profile"] = self._logged_channel.unary_unary( "/google.cloud.oslogin.v1.OsLoginService/GetLoginProfile", request_serializer=oslogin.GetLoginProfileRequest.serialize, response_deserializer=oslogin.LoginProfile.deserialize, @@ -372,7 +457,7 @@ def get_ssh_public_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_ssh_public_key" not in self._stubs: - self._stubs["get_ssh_public_key"] = self.grpc_channel.unary_unary( + self._stubs["get_ssh_public_key"] = self._logged_channel.unary_unary( "/google.cloud.oslogin.v1.OsLoginService/GetSshPublicKey", request_serializer=oslogin.GetSshPublicKeyRequest.serialize, response_deserializer=common.SshPublicKey.deserialize, @@ -404,7 +489,7 @@ def import_ssh_public_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "import_ssh_public_key" not in self._stubs: - self._stubs["import_ssh_public_key"] = self.grpc_channel.unary_unary( + self._stubs["import_ssh_public_key"] = self._logged_channel.unary_unary( "/google.cloud.oslogin.v1.OsLoginService/ImportSshPublicKey", request_serializer=oslogin.ImportSshPublicKeyRequest.serialize, response_deserializer=oslogin.ImportSshPublicKeyResponse.deserialize, @@ -431,7 +516,7 @@ def update_ssh_public_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_ssh_public_key" not in self._stubs: - self._stubs["update_ssh_public_key"] = self.grpc_channel.unary_unary( + self._stubs["update_ssh_public_key"] = self._logged_channel.unary_unary( "/google.cloud.oslogin.v1.OsLoginService/UpdateSshPublicKey", request_serializer=oslogin.UpdateSshPublicKeyRequest.serialize, response_deserializer=common.SshPublicKey.deserialize, @@ -544,7 +629,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_service/transports/rest.py b/packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_service/transports/rest.py index 9ffc4c72b296..ed3f88558628 100644 --- a/packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_service/transports/rest.py +++ b/packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_service/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -39,6 +39,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -119,8 +127,10 @@ def post_update_ssh_public_key(self, response): def pre_create_ssh_public_key( self, request: oslogin.CreateSshPublicKeyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[oslogin.CreateSshPublicKeyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + oslogin.CreateSshPublicKeyRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for create_ssh_public_key Override in a subclass to manipulate the request or metadata @@ -142,8 +152,10 @@ def post_create_ssh_public_key( def pre_delete_posix_account( self, request: oslogin.DeletePosixAccountRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[oslogin.DeletePosixAccountRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + oslogin.DeletePosixAccountRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for delete_posix_account Override in a subclass to manipulate the request or metadata @@ -154,8 +166,10 @@ def pre_delete_posix_account( def pre_delete_ssh_public_key( self, request: oslogin.DeleteSshPublicKeyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[oslogin.DeleteSshPublicKeyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + oslogin.DeleteSshPublicKeyRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for delete_ssh_public_key Override in a subclass to manipulate the request or metadata @@ -166,8 +180,8 @@ def pre_delete_ssh_public_key( def pre_get_login_profile( self, request: oslogin.GetLoginProfileRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[oslogin.GetLoginProfileRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[oslogin.GetLoginProfileRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for get_login_profile Override in a subclass to manipulate the request or metadata @@ -189,8 +203,8 @@ def post_get_login_profile( def pre_get_ssh_public_key( self, request: oslogin.GetSshPublicKeyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[oslogin.GetSshPublicKeyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[oslogin.GetSshPublicKeyRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for get_ssh_public_key Override in a subclass to manipulate the request or metadata @@ -212,8 +226,10 @@ def post_get_ssh_public_key( def pre_import_ssh_public_key( self, request: oslogin.ImportSshPublicKeyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[oslogin.ImportSshPublicKeyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + oslogin.ImportSshPublicKeyRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for import_ssh_public_key Override in a subclass to manipulate the request or metadata @@ -235,8 +251,10 @@ def post_import_ssh_public_key( def pre_update_ssh_public_key( self, request: oslogin.UpdateSshPublicKeyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[oslogin.UpdateSshPublicKeyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + oslogin.UpdateSshPublicKeyRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for update_ssh_public_key Override in a subclass to manipulate the request or metadata @@ -381,7 +399,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> common.SshPublicKey: r"""Call the create ssh public key method over HTTP. @@ -392,8 +410,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.common.SshPublicKey: @@ -405,6 +425,7 @@ def __call__( http_options = ( _BaseOsLoginServiceRestTransport._BaseCreateSshPublicKey._get_http_options() ) + request, metadata = self._interceptor.pre_create_ssh_public_key( request, metadata ) @@ -421,6 +442,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.oslogin_v1.OsLoginServiceClient.CreateSshPublicKey", + extra={ + "serviceName": "google.cloud.oslogin.v1.OsLoginService", + "rpcName": "CreateSshPublicKey", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsLoginServiceRestTransport._CreateSshPublicKey._get_response( self._host, @@ -442,7 +490,29 @@ def __call__( pb_resp = common.SshPublicKey.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_ssh_public_key(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = common.SshPublicKey.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.oslogin_v1.OsLoginServiceClient.create_ssh_public_key", + extra={ + "serviceName": "google.cloud.oslogin.v1.OsLoginService", + "rpcName": "CreateSshPublicKey", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DeletePosixAccount( @@ -479,7 +549,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): r"""Call the delete posix account method over HTTP. @@ -490,13 +560,16 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ http_options = ( _BaseOsLoginServiceRestTransport._BaseDeletePosixAccount._get_http_options() ) + request, metadata = self._interceptor.pre_delete_posix_account( request, metadata ) @@ -509,6 +582,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.oslogin_v1.OsLoginServiceClient.DeletePosixAccount", + extra={ + "serviceName": "google.cloud.oslogin.v1.OsLoginService", + "rpcName": "DeletePosixAccount", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsLoginServiceRestTransport._DeletePosixAccount._get_response( self._host, @@ -558,7 +658,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): r"""Call the delete ssh public key method over HTTP. @@ -569,13 +669,16 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ http_options = ( _BaseOsLoginServiceRestTransport._BaseDeleteSshPublicKey._get_http_options() ) + request, metadata = self._interceptor.pre_delete_ssh_public_key( request, metadata ) @@ -588,6 +691,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.oslogin_v1.OsLoginServiceClient.DeleteSshPublicKey", + extra={ + "serviceName": "google.cloud.oslogin.v1.OsLoginService", + "rpcName": "DeleteSshPublicKey", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsLoginServiceRestTransport._DeleteSshPublicKey._get_response( self._host, @@ -637,7 +767,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> oslogin.LoginProfile: r"""Call the get login profile method over HTTP. @@ -648,8 +778,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.oslogin.LoginProfile: @@ -662,6 +794,7 @@ def __call__( http_options = ( _BaseOsLoginServiceRestTransport._BaseGetLoginProfile._get_http_options() ) + request, metadata = self._interceptor.pre_get_login_profile( request, metadata ) @@ -674,6 +807,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.oslogin_v1.OsLoginServiceClient.GetLoginProfile", + extra={ + "serviceName": "google.cloud.oslogin.v1.OsLoginService", + "rpcName": "GetLoginProfile", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsLoginServiceRestTransport._GetLoginProfile._get_response( self._host, @@ -694,7 +854,29 @@ def __call__( pb_resp = oslogin.LoginProfile.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_login_profile(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = oslogin.LoginProfile.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.oslogin_v1.OsLoginServiceClient.get_login_profile", + extra={ + "serviceName": "google.cloud.oslogin.v1.OsLoginService", + "rpcName": "GetLoginProfile", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetSshPublicKey( @@ -731,7 +913,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> common.SshPublicKey: r"""Call the get ssh public key method over HTTP. @@ -742,8 +924,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.common.SshPublicKey: @@ -755,6 +939,7 @@ def __call__( http_options = ( _BaseOsLoginServiceRestTransport._BaseGetSshPublicKey._get_http_options() ) + request, metadata = self._interceptor.pre_get_ssh_public_key( request, metadata ) @@ -767,6 +952,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.oslogin_v1.OsLoginServiceClient.GetSshPublicKey", + extra={ + "serviceName": "google.cloud.oslogin.v1.OsLoginService", + "rpcName": "GetSshPublicKey", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsLoginServiceRestTransport._GetSshPublicKey._get_response( self._host, @@ -787,7 +999,29 @@ def __call__( pb_resp = common.SshPublicKey.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_ssh_public_key(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = common.SshPublicKey.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.oslogin_v1.OsLoginServiceClient.get_ssh_public_key", + extra={ + "serviceName": "google.cloud.oslogin.v1.OsLoginService", + "rpcName": "GetSshPublicKey", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ImportSshPublicKey( @@ -825,7 +1059,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> oslogin.ImportSshPublicKeyResponse: r"""Call the import ssh public key method over HTTP. @@ -836,8 +1070,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.oslogin.ImportSshPublicKeyResponse: @@ -849,6 +1085,7 @@ def __call__( http_options = ( _BaseOsLoginServiceRestTransport._BaseImportSshPublicKey._get_http_options() ) + request, metadata = self._interceptor.pre_import_ssh_public_key( request, metadata ) @@ -865,6 +1102,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.oslogin_v1.OsLoginServiceClient.ImportSshPublicKey", + extra={ + "serviceName": "google.cloud.oslogin.v1.OsLoginService", + "rpcName": "ImportSshPublicKey", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsLoginServiceRestTransport._ImportSshPublicKey._get_response( self._host, @@ -886,7 +1150,31 @@ def __call__( pb_resp = oslogin.ImportSshPublicKeyResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_import_ssh_public_key(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = oslogin.ImportSshPublicKeyResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.oslogin_v1.OsLoginServiceClient.import_ssh_public_key", + extra={ + "serviceName": "google.cloud.oslogin.v1.OsLoginService", + "rpcName": "ImportSshPublicKey", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateSshPublicKey( @@ -924,7 +1212,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> common.SshPublicKey: r"""Call the update ssh public key method over HTTP. @@ -935,8 +1223,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.common.SshPublicKey: @@ -948,6 +1238,7 @@ def __call__( http_options = ( _BaseOsLoginServiceRestTransport._BaseUpdateSshPublicKey._get_http_options() ) + request, metadata = self._interceptor.pre_update_ssh_public_key( request, metadata ) @@ -964,6 +1255,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.oslogin_v1.OsLoginServiceClient.UpdateSshPublicKey", + extra={ + "serviceName": "google.cloud.oslogin.v1.OsLoginService", + "rpcName": "UpdateSshPublicKey", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OsLoginServiceRestTransport._UpdateSshPublicKey._get_response( self._host, @@ -985,7 +1303,29 @@ def __call__( pb_resp = common.SshPublicKey.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_ssh_public_key(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = common.SshPublicKey.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.oslogin_v1.OsLoginServiceClient.update_ssh_public_key", + extra={ + "serviceName": "google.cloud.oslogin.v1.OsLoginService", + "rpcName": "UpdateSshPublicKey", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property diff --git a/packages/google-cloud-os-login/samples/generated_samples/snippet_metadata_google.cloud.oslogin.v1.json b/packages/google-cloud-os-login/samples/generated_samples/snippet_metadata_google.cloud.oslogin.v1.json index 51fdc812ebb0..7e2657df02a7 100644 --- a/packages/google-cloud-os-login/samples/generated_samples/snippet_metadata_google.cloud.oslogin.v1.json +++ b/packages/google-cloud-os-login/samples/generated_samples/snippet_metadata_google.cloud.oslogin.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-os-login", - "version": "2.15.1" + "version": "0.1.0" }, "snippets": [ { @@ -51,7 +51,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.oslogin.common.types.SshPublicKey", @@ -135,7 +135,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.oslogin.common.types.SshPublicKey", @@ -216,7 +216,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "shortName": "delete_posix_account" @@ -293,7 +293,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "shortName": "delete_posix_account" @@ -371,7 +371,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "shortName": "delete_ssh_public_key" @@ -448,7 +448,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "shortName": "delete_ssh_public_key" @@ -526,7 +526,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.oslogin_v1.types.LoginProfile", @@ -606,7 +606,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.oslogin_v1.types.LoginProfile", @@ -687,7 +687,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.oslogin.common.types.SshPublicKey", @@ -767,7 +767,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.oslogin.common.types.SshPublicKey", @@ -856,7 +856,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.oslogin_v1.types.ImportSshPublicKeyResponse", @@ -944,7 +944,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.oslogin_v1.types.ImportSshPublicKeyResponse", @@ -1033,7 +1033,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.oslogin.common.types.SshPublicKey", @@ -1121,7 +1121,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.oslogin.common.types.SshPublicKey", diff --git a/packages/google-cloud-os-login/tests/unit/gapic/oslogin_v1/test_os_login_service.py b/packages/google-cloud-os-login/tests/unit/gapic/oslogin_v1/test_os_login_service.py index 89dd5a35107d..d7e554e2740b 100644 --- a/packages/google-cloud-os-login/tests/unit/gapic/oslogin_v1/test_os_login_service.py +++ b/packages/google-cloud-os-login/tests/unit/gapic/oslogin_v1/test_os_login_service.py @@ -3623,6 +3623,7 @@ def test_create_ssh_public_key_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_ssh_public_key(request) @@ -3677,6 +3678,7 @@ def test_create_ssh_public_key_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_ssh_public_key(**mock_args) @@ -3808,6 +3810,7 @@ def test_delete_posix_account_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_posix_account(request) @@ -3851,6 +3854,7 @@ def test_delete_posix_account_rest_flattened(): json_return_value = "" response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_posix_account(**mock_args) @@ -3982,6 +3986,7 @@ def test_delete_ssh_public_key_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_ssh_public_key(request) @@ -4025,6 +4030,7 @@ def test_delete_ssh_public_key_rest_flattened(): json_return_value = "" response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_ssh_public_key(**mock_args) @@ -4163,6 +4169,7 @@ def test_get_login_profile_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_login_profile(request) @@ -4216,6 +4223,7 @@ def test_get_login_profile_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_login_profile(**mock_args) @@ -4349,6 +4357,7 @@ def test_get_ssh_public_key_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_ssh_public_key(request) @@ -4394,6 +4403,7 @@ def test_get_ssh_public_key_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_ssh_public_key(**mock_args) @@ -4536,6 +4546,7 @@ def test_import_ssh_public_key_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.import_ssh_public_key(request) @@ -4591,6 +4602,7 @@ def test_import_ssh_public_key_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.import_ssh_public_key(**mock_args) @@ -4731,6 +4743,7 @@ def test_update_ssh_public_key_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_ssh_public_key(request) @@ -4786,6 +4799,7 @@ def test_update_ssh_public_key_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_ssh_public_key(**mock_args) @@ -5328,6 +5342,7 @@ def test_create_ssh_public_key_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_ssh_public_key(request) @@ -5439,6 +5454,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_ssh_public_key(request) # Establish that the response is the type that we expect. @@ -5482,6 +5498,7 @@ def test_create_ssh_public_key_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = common.SshPublicKey.to_json(common.SshPublicKey()) req.return_value.content = return_value @@ -5526,6 +5543,7 @@ def test_delete_posix_account_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_posix_account(request) @@ -5556,6 +5574,7 @@ def test_delete_posix_account_rest_call_success(request_type): json_return_value = "" response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_posix_account(request) # Establish that the response is the type that we expect. @@ -5592,6 +5611,7 @@ def test_delete_posix_account_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} request = oslogin.DeletePosixAccountRequest() metadata = [ @@ -5632,6 +5652,7 @@ def test_delete_ssh_public_key_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_ssh_public_key(request) @@ -5662,6 +5683,7 @@ def test_delete_ssh_public_key_rest_call_success(request_type): json_return_value = "" response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_ssh_public_key(request) # Establish that the response is the type that we expect. @@ -5698,6 +5720,7 @@ def test_delete_ssh_public_key_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} request = oslogin.DeleteSshPublicKeyRequest() metadata = [ @@ -5738,6 +5761,7 @@ def test_get_login_profile_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_login_profile(request) @@ -5773,6 +5797,7 @@ def test_get_login_profile_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_login_profile(request) # Establish that the response is the type that we expect. @@ -5811,6 +5836,7 @@ def test_get_login_profile_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = oslogin.LoginProfile.to_json(oslogin.LoginProfile()) req.return_value.content = return_value @@ -5855,6 +5881,7 @@ def test_get_ssh_public_key_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_ssh_public_key(request) @@ -5893,6 +5920,7 @@ def test_get_ssh_public_key_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_ssh_public_key(request) # Establish that the response is the type that we expect. @@ -5934,6 +5962,7 @@ def test_get_ssh_public_key_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = common.SshPublicKey.to_json(common.SshPublicKey()) req.return_value.content = return_value @@ -5978,6 +6007,7 @@ def test_import_ssh_public_key_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.import_ssh_public_key(request) @@ -6086,6 +6116,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.import_ssh_public_key(request) # Establish that the response is the type that we expect. @@ -6126,6 +6157,7 @@ def test_import_ssh_public_key_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = oslogin.ImportSshPublicKeyResponse.to_json( oslogin.ImportSshPublicKeyResponse() ) @@ -6172,6 +6204,7 @@ def test_update_ssh_public_key_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_ssh_public_key(request) @@ -6283,6 +6316,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_ssh_public_key(request) # Establish that the response is the type that we expect. @@ -6326,6 +6360,7 @@ def test_update_ssh_public_key_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = common.SshPublicKey.to_json(common.SshPublicKey()) req.return_value.content = return_value diff --git a/packages/google-cloud-phishing-protection/google/cloud/phishingprotection/gapic_version.py b/packages/google-cloud-phishing-protection/google/cloud/phishingprotection/gapic_version.py index 49ddc22ee702..558c8aab67c5 100644 --- a/packages/google-cloud-phishing-protection/google/cloud/phishingprotection/gapic_version.py +++ b/packages/google-cloud-phishing-protection/google/cloud/phishingprotection/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.12.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/gapic_version.py b/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/gapic_version.py index 49ddc22ee702..558c8aab67c5 100644 --- a/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/gapic_version.py +++ b/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.12.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/async_client.py b/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/async_client.py index dbc87ff76c1e..cab40e5883bf 100644 --- a/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/async_client.py +++ b/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -53,6 +54,15 @@ PhishingProtectionServiceV1Beta1GrpcAsyncIOTransport, ) +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class PhishingProtectionServiceV1Beta1AsyncClient: """Service to report phishing URIs.""" @@ -268,6 +278,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.phishingprotection_v1beta1.PhishingProtectionServiceV1Beta1AsyncClient`.", + extra={ + "serviceName": "google.cloud.phishingprotection.v1beta1.PhishingProtectionServiceV1Beta1", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.phishingprotection.v1beta1.PhishingProtectionServiceV1Beta1", + "credentialsType": None, + }, + ) + async def report_phishing( self, request: Optional[Union[phishingprotection.ReportPhishingRequest, dict]] = None, @@ -276,7 +308,7 @@ async def report_phishing( uri: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> phishingprotection.ReportPhishingResponse: r"""Reports a URI suspected of containing phishing content to be reviewed. Once the report review is complete, its result can be @@ -337,8 +369,10 @@ async def sample_report_phishing(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.phishingprotection_v1beta1.types.ReportPhishingResponse: diff --git a/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/client.py b/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/client.py index 63678f3c3ceb..83a86c06083b 100644 --- a/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/client.py +++ b/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.cloud.phishingprotection_v1beta1.types import phishingprotection from .transports.base import ( @@ -572,6 +582,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -642,6 +656,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.phishingprotection_v1beta1.PhishingProtectionServiceV1Beta1Client`.", + extra={ + "serviceName": "google.cloud.phishingprotection.v1beta1.PhishingProtectionServiceV1Beta1", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.phishingprotection.v1beta1.PhishingProtectionServiceV1Beta1", + "credentialsType": None, + }, + ) + def report_phishing( self, request: Optional[Union[phishingprotection.ReportPhishingRequest, dict]] = None, @@ -650,7 +687,7 @@ def report_phishing( uri: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> phishingprotection.ReportPhishingResponse: r"""Reports a URI suspected of containing phishing content to be reviewed. Once the report review is complete, its result can be @@ -711,8 +748,10 @@ def sample_report_phishing(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.phishingprotection_v1beta1.types.ReportPhishingResponse: diff --git a/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/transports/grpc.py b/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/transports/grpc.py index a502e62d0a3e..664f4d83f2ae 100644 --- a/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/transports/grpc.py +++ b/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -20,12 +23,90 @@ import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.phishingprotection_v1beta1.types import phishingprotection from .base import DEFAULT_CLIENT_INFO, PhishingProtectionServiceV1Beta1Transport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.phishingprotection.v1beta1.PhishingProtectionServiceV1Beta1", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.phishingprotection.v1beta1.PhishingProtectionServiceV1Beta1", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class PhishingProtectionServiceV1Beta1GrpcTransport( PhishingProtectionServiceV1Beta1Transport @@ -181,7 +262,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -266,7 +352,7 @@ def report_phishing( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "report_phishing" not in self._stubs: - self._stubs["report_phishing"] = self.grpc_channel.unary_unary( + self._stubs["report_phishing"] = self._logged_channel.unary_unary( "/google.cloud.phishingprotection.v1beta1.PhishingProtectionServiceV1Beta1/ReportPhishing", request_serializer=phishingprotection.ReportPhishingRequest.serialize, response_deserializer=phishingprotection.ReportPhishingResponse.deserialize, @@ -274,7 +360,7 @@ def report_phishing( return self._stubs["report_phishing"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/transports/grpc_asyncio.py b/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/transports/grpc_asyncio.py index fde362f6b51f..59a16e9bd217 100644 --- a/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/transports/grpc_asyncio.py +++ b/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -22,14 +25,93 @@ from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.phishingprotection_v1beta1.types import phishingprotection from .base import DEFAULT_CLIENT_INFO, PhishingProtectionServiceV1Beta1Transport from .grpc import PhishingProtectionServiceV1Beta1GrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.phishingprotection.v1beta1.PhishingProtectionServiceV1Beta1", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.phishingprotection.v1beta1.PhishingProtectionServiceV1Beta1", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class PhishingProtectionServiceV1Beta1GrpcAsyncIOTransport( PhishingProtectionServiceV1Beta1Transport @@ -228,10 +310,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -274,7 +359,7 @@ def report_phishing( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "report_phishing" not in self._stubs: - self._stubs["report_phishing"] = self.grpc_channel.unary_unary( + self._stubs["report_phishing"] = self._logged_channel.unary_unary( "/google.cloud.phishingprotection.v1beta1.PhishingProtectionServiceV1Beta1/ReportPhishing", request_serializer=phishingprotection.ReportPhishingRequest.serialize, response_deserializer=phishingprotection.ReportPhishingResponse.deserialize, @@ -297,7 +382,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/transports/rest.py b/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/transports/rest.py index f0dfb500d92d..9cfcab23d3e4 100644 --- a/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/transports/rest.py +++ b/packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -37,6 +37,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -77,8 +85,11 @@ def post_report_phishing(self, response): def pre_report_phishing( self, request: phishingprotection.ReportPhishingRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[phishingprotection.ReportPhishingRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + phishingprotection.ReportPhishingRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for report_phishing Override in a subclass to manipulate the request or metadata @@ -224,7 +235,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> phishingprotection.ReportPhishingResponse: r"""Call the report phishing method over HTTP. @@ -234,8 +245,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.phishingprotection.ReportPhishingResponse: @@ -247,6 +260,7 @@ def __call__( http_options = ( _BasePhishingProtectionServiceV1Beta1RestTransport._BaseReportPhishing._get_http_options() ) + request, metadata = self._interceptor.pre_report_phishing(request, metadata) transcoded_request = _BasePhishingProtectionServiceV1Beta1RestTransport._BaseReportPhishing._get_transcoded_request( http_options, request @@ -261,6 +275,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.phishingprotection_v1beta1.PhishingProtectionServiceV1Beta1Client.ReportPhishing", + extra={ + "serviceName": "google.cloud.phishingprotection.v1beta1.PhishingProtectionServiceV1Beta1", + "rpcName": "ReportPhishing", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = PhishingProtectionServiceV1Beta1RestTransport._ReportPhishing._get_response( self._host, @@ -282,7 +323,31 @@ def __call__( pb_resp = phishingprotection.ReportPhishingResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_report_phishing(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + phishingprotection.ReportPhishingResponse.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.phishingprotection_v1beta1.PhishingProtectionServiceV1Beta1Client.report_phishing", + extra={ + "serviceName": "google.cloud.phishingprotection.v1beta1.PhishingProtectionServiceV1Beta1", + "rpcName": "ReportPhishing", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property diff --git a/packages/google-cloud-phishing-protection/samples/generated_samples/snippet_metadata_google.cloud.phishingprotection.v1beta1.json b/packages/google-cloud-phishing-protection/samples/generated_samples/snippet_metadata_google.cloud.phishingprotection.v1beta1.json index 18e8fed56b57..18460381eb04 100644 --- a/packages/google-cloud-phishing-protection/samples/generated_samples/snippet_metadata_google.cloud.phishingprotection.v1beta1.json +++ b/packages/google-cloud-phishing-protection/samples/generated_samples/snippet_metadata_google.cloud.phishingprotection.v1beta1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-phishing-protection", - "version": "1.12.1" + "version": "0.1.0" }, "snippets": [ { @@ -51,7 +51,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.phishingprotection_v1beta1.types.ReportPhishingResponse", @@ -135,7 +135,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.phishingprotection_v1beta1.types.ReportPhishingResponse", diff --git a/packages/google-cloud-phishing-protection/tests/unit/gapic/phishingprotection_v1beta1/test_phishing_protection_service_v1_beta1.py b/packages/google-cloud-phishing-protection/tests/unit/gapic/phishingprotection_v1beta1/test_phishing_protection_service_v1_beta1.py index 879cf5d039d4..c1a7c97aff17 100644 --- a/packages/google-cloud-phishing-protection/tests/unit/gapic/phishingprotection_v1beta1/test_phishing_protection_service_v1_beta1.py +++ b/packages/google-cloud-phishing-protection/tests/unit/gapic/phishingprotection_v1beta1/test_phishing_protection_service_v1_beta1.py @@ -1598,6 +1598,7 @@ def test_report_phishing_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.report_phishing(request) @@ -1652,6 +1653,7 @@ def test_report_phishing_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.report_phishing(**mock_args) @@ -1875,6 +1877,7 @@ def test_report_phishing_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.report_phishing(request) @@ -1908,6 +1911,7 @@ def test_report_phishing_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.report_phishing(request) # Establish that the response is the type that we expect. @@ -1949,6 +1953,7 @@ def test_report_phishing_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = phishingprotection.ReportPhishingResponse.to_json( phishingprotection.ReportPhishingResponse() ) diff --git a/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter/gapic_version.py b/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter/gapic_version.py index 49ddc22ee702..558c8aab67c5 100644 --- a/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter/gapic_version.py +++ b/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.12.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/gapic_version.py b/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/gapic_version.py index 49ddc22ee702..558c8aab67c5 100644 --- a/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/gapic_version.py +++ b/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.12.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/services/iam_checker/async_client.py b/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/services/iam_checker/async_client.py index 16a70165f089..ea1a414ac6ba 100644 --- a/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/services/iam_checker/async_client.py +++ b/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/services/iam_checker/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -50,6 +51,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, IamCheckerTransport from .transports.grpc_asyncio import IamCheckerGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class IamCheckerAsyncClient: """IAM Policy Troubleshooter service. @@ -251,13 +261,35 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.policytroubleshooter_v1.IamCheckerAsyncClient`.", + extra={ + "serviceName": "google.cloud.policytroubleshooter.v1.IamChecker", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.policytroubleshooter.v1.IamChecker", + "credentialsType": None, + }, + ) + async def troubleshoot_iam_policy( self, request: Optional[Union[checker.TroubleshootIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> checker.TroubleshootIamPolicyResponse: r"""Checks whether a principal has a specific permission for a specific resource, and explains why the principal @@ -295,8 +327,10 @@ async def sample_troubleshoot_iam_policy(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.policytroubleshooter_v1.types.TroubleshootIamPolicyResponse: diff --git a/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/services/iam_checker/client.py b/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/services/iam_checker/client.py index 8de6f3d62d51..7b4813324e3a 100644 --- a/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/services/iam_checker/client.py +++ b/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/services/iam_checker/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.rpc import status_pb2 # type: ignore from google.cloud.policytroubleshooter_v1.types import checker, explanations @@ -559,6 +569,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -621,13 +635,36 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.policytroubleshooter_v1.IamCheckerClient`.", + extra={ + "serviceName": "google.cloud.policytroubleshooter.v1.IamChecker", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.policytroubleshooter.v1.IamChecker", + "credentialsType": None, + }, + ) + def troubleshoot_iam_policy( self, request: Optional[Union[checker.TroubleshootIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> checker.TroubleshootIamPolicyResponse: r"""Checks whether a principal has a specific permission for a specific resource, and explains why the principal @@ -665,8 +702,10 @@ def sample_troubleshoot_iam_policy(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.policytroubleshooter_v1.types.TroubleshootIamPolicyResponse: diff --git a/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/services/iam_checker/transports/grpc.py b/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/services/iam_checker/transports/grpc.py index c89ebf478473..0783f5eaaa9d 100644 --- a/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/services/iam_checker/transports/grpc.py +++ b/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/services/iam_checker/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -20,12 +23,90 @@ import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.policytroubleshooter_v1.types import checker from .base import DEFAULT_CLIENT_INFO, IamCheckerTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.policytroubleshooter.v1.IamChecker", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.policytroubleshooter.v1.IamChecker", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class IamCheckerGrpcTransport(IamCheckerTransport): """gRPC backend transport for IamChecker. @@ -182,7 +263,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -260,7 +346,7 @@ def troubleshoot_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "troubleshoot_iam_policy" not in self._stubs: - self._stubs["troubleshoot_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["troubleshoot_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.policytroubleshooter.v1.IamChecker/TroubleshootIamPolicy", request_serializer=checker.TroubleshootIamPolicyRequest.serialize, response_deserializer=checker.TroubleshootIamPolicyResponse.deserialize, @@ -268,7 +354,7 @@ def troubleshoot_iam_policy( return self._stubs["troubleshoot_iam_policy"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/services/iam_checker/transports/grpc_asyncio.py b/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/services/iam_checker/transports/grpc_asyncio.py index 3561b9e2026e..6c210723d261 100644 --- a/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/services/iam_checker/transports/grpc_asyncio.py +++ b/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/services/iam_checker/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -22,14 +25,93 @@ from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.policytroubleshooter_v1.types import checker from .base import DEFAULT_CLIENT_INFO, IamCheckerTransport from .grpc import IamCheckerGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.policytroubleshooter.v1.IamChecker", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.policytroubleshooter.v1.IamChecker", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class IamCheckerGrpcAsyncIOTransport(IamCheckerTransport): """gRPC AsyncIO backend transport for IamChecker. @@ -229,10 +311,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -269,7 +354,7 @@ def troubleshoot_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "troubleshoot_iam_policy" not in self._stubs: - self._stubs["troubleshoot_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["troubleshoot_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.policytroubleshooter.v1.IamChecker/TroubleshootIamPolicy", request_serializer=checker.TroubleshootIamPolicyRequest.serialize, response_deserializer=checker.TroubleshootIamPolicyResponse.deserialize, @@ -292,7 +377,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/services/iam_checker/transports/rest.py b/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/services/iam_checker/transports/rest.py index c84a6ae8466a..90722d7080de 100644 --- a/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/services/iam_checker/transports/rest.py +++ b/packages/google-cloud-policy-troubleshooter/google/cloud/policytroubleshooter_v1/services/iam_checker/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -37,6 +37,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -77,8 +85,10 @@ def post_troubleshoot_iam_policy(self, response): def pre_troubleshoot_iam_policy( self, request: checker.TroubleshootIamPolicyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[checker.TroubleshootIamPolicyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + checker.TroubleshootIamPolicyRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for troubleshoot_iam_policy Override in a subclass to manipulate the request or metadata @@ -222,7 +232,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> checker.TroubleshootIamPolicyResponse: r"""Call the troubleshoot iam policy method over HTTP. @@ -233,8 +243,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.checker.TroubleshootIamPolicyResponse: @@ -246,6 +258,7 @@ def __call__( http_options = ( _BaseIamCheckerRestTransport._BaseTroubleshootIamPolicy._get_http_options() ) + request, metadata = self._interceptor.pre_troubleshoot_iam_policy( request, metadata ) @@ -262,6 +275,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.policytroubleshooter_v1.IamCheckerClient.TroubleshootIamPolicy", + extra={ + "serviceName": "google.cloud.policytroubleshooter.v1.IamChecker", + "rpcName": "TroubleshootIamPolicy", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = IamCheckerRestTransport._TroubleshootIamPolicy._get_response( self._host, @@ -283,7 +323,31 @@ def __call__( pb_resp = checker.TroubleshootIamPolicyResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_troubleshoot_iam_policy(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = checker.TroubleshootIamPolicyResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.policytroubleshooter_v1.IamCheckerClient.troubleshoot_iam_policy", + extra={ + "serviceName": "google.cloud.policytroubleshooter.v1.IamChecker", + "rpcName": "TroubleshootIamPolicy", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property diff --git a/packages/google-cloud-policy-troubleshooter/samples/generated_samples/snippet_metadata_google.cloud.policytroubleshooter.v1.json b/packages/google-cloud-policy-troubleshooter/samples/generated_samples/snippet_metadata_google.cloud.policytroubleshooter.v1.json index d5a69310b8ab..24a7fb5b901c 100644 --- a/packages/google-cloud-policy-troubleshooter/samples/generated_samples/snippet_metadata_google.cloud.policytroubleshooter.v1.json +++ b/packages/google-cloud-policy-troubleshooter/samples/generated_samples/snippet_metadata_google.cloud.policytroubleshooter.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-policy-troubleshooter", - "version": "1.12.1" + "version": "0.1.0" }, "snippets": [ { @@ -43,7 +43,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.policytroubleshooter_v1.types.TroubleshootIamPolicyResponse", @@ -119,7 +119,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.policytroubleshooter_v1.types.TroubleshootIamPolicyResponse", diff --git a/packages/google-cloud-policy-troubleshooter/tests/unit/gapic/policytroubleshooter_v1/test_iam_checker.py b/packages/google-cloud-policy-troubleshooter/tests/unit/gapic/policytroubleshooter_v1/test_iam_checker.py index c58aad91cc79..de24ce06f458 100644 --- a/packages/google-cloud-policy-troubleshooter/tests/unit/gapic/policytroubleshooter_v1/test_iam_checker.py +++ b/packages/google-cloud-policy-troubleshooter/tests/unit/gapic/policytroubleshooter_v1/test_iam_checker.py @@ -1447,6 +1447,7 @@ def test_troubleshoot_iam_policy_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.troubleshoot_iam_policy(request) @@ -1482,6 +1483,7 @@ def test_troubleshoot_iam_policy_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.troubleshoot_iam_policy(request) # Establish that the response is the type that we expect. @@ -1522,6 +1524,7 @@ def test_troubleshoot_iam_policy_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = checker.TroubleshootIamPolicyResponse.to_json( checker.TroubleshootIamPolicyResponse() ) diff --git a/packages/google-cloud-policysimulator/google/cloud/policysimulator/gapic_version.py b/packages/google-cloud-policysimulator/google/cloud/policysimulator/gapic_version.py index 9413c3341313..558c8aab67c5 100644 --- a/packages/google-cloud-policysimulator/google/cloud/policysimulator/gapic_version.py +++ b/packages/google-cloud-policysimulator/google/cloud/policysimulator/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.1.10" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/gapic_version.py b/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/gapic_version.py index 9413c3341313..558c8aab67c5 100644 --- a/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/gapic_version.py +++ b/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.1.10" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/async_client.py b/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/async_client.py index 55c1eefd489a..08ab0d089932 100644 --- a/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/async_client.py +++ b/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -53,6 +54,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, SimulatorTransport from .transports.grpc_asyncio import SimulatorGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class SimulatorAsyncClient: """Policy Simulator API service. @@ -267,6 +277,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.policysimulator_v1.SimulatorAsyncClient`.", + extra={ + "serviceName": "google.cloud.policysimulator.v1.Simulator", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.policysimulator.v1.Simulator", + "credentialsType": None, + }, + ) + async def get_replay( self, request: Optional[Union[simulator.GetReplayRequest, dict]] = None, @@ -274,7 +306,7 @@ async def get_replay( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> simulator.Replay: r"""Gets the specified [Replay][google.cloud.policysimulator.v1.Replay]. Each @@ -328,8 +360,10 @@ async def sample_get_replay(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.policysimulator_v1.types.Replay: @@ -389,7 +423,7 @@ async def create_replay( replay: Optional[simulator.Replay] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Creates and starts a [Replay][google.cloud.policysimulator.v1.Replay] using the given @@ -453,8 +487,10 @@ async def sample_create_replay(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -528,7 +564,7 @@ async def list_replay_results( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListReplayResultsAsyncPager: r"""Lists the results of running a [Replay][google.cloud.policysimulator.v1.Replay]. @@ -580,8 +616,10 @@ async def sample_list_replay_results(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.policysimulator_v1.services.simulator.pagers.ListReplayResultsAsyncPager: @@ -655,7 +693,7 @@ async def list_operations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Lists operations that match the specified filter in the request. @@ -666,8 +704,10 @@ async def list_operations( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.ListOperationsResponse: Response message for ``ListOperations`` method. @@ -708,7 +748,7 @@ async def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -719,8 +759,10 @@ async def get_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. diff --git a/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/client.py b/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/client.py index 5106ff800f25..b0f78f897d30 100644 --- a/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/client.py +++ b/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -617,6 +627,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -679,6 +693,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.policysimulator_v1.SimulatorClient`.", + extra={ + "serviceName": "google.cloud.policysimulator.v1.Simulator", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.policysimulator.v1.Simulator", + "credentialsType": None, + }, + ) + def get_replay( self, request: Optional[Union[simulator.GetReplayRequest, dict]] = None, @@ -686,7 +723,7 @@ def get_replay( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> simulator.Replay: r"""Gets the specified [Replay][google.cloud.policysimulator.v1.Replay]. Each @@ -740,8 +777,10 @@ def sample_get_replay(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.policysimulator_v1.types.Replay: @@ -798,7 +837,7 @@ def create_replay( replay: Optional[simulator.Replay] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Creates and starts a [Replay][google.cloud.policysimulator.v1.Replay] using the given @@ -862,8 +901,10 @@ def sample_create_replay(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -934,7 +975,7 @@ def list_replay_results( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListReplayResultsPager: r"""Lists the results of running a [Replay][google.cloud.policysimulator.v1.Replay]. @@ -986,8 +1027,10 @@ def sample_list_replay_results(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.policysimulator_v1.services.simulator.pagers.ListReplayResultsPager: @@ -1071,7 +1114,7 @@ def list_operations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Lists operations that match the specified filter in the request. @@ -1082,8 +1125,10 @@ def list_operations( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.ListOperationsResponse: Response message for ``ListOperations`` method. @@ -1124,7 +1169,7 @@ def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -1135,8 +1180,10 @@ def get_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. diff --git a/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/pagers.py b/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/pagers.py index b5a674919b2d..f2b980adda58 100644 --- a/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/pagers.py +++ b/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -81,8 +81,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = simulator.ListReplayResultsRequest(request) @@ -141,7 +143,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -155,8 +157,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = simulator.ListReplayResultsRequest(request) diff --git a/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/transports/grpc.py b/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/transports/grpc.py index 155223150c30..b918bac76323 100644 --- a/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/transports/grpc.py +++ b/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -21,12 +24,90 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.policysimulator_v1.types import simulator from .base import DEFAULT_CLIENT_INFO, SimulatorTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.policysimulator.v1.Simulator", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.policysimulator.v1.Simulator", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class SimulatorGrpcTransport(SimulatorTransport): """gRPC backend transport for Simulator. @@ -193,7 +274,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -257,7 +343,9 @@ def operations_client(self) -> operations_v1.OperationsClient: """ # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + self._operations_client = operations_v1.OperationsClient( + self._logged_channel + ) # Return the client from cache. return self._operations_client @@ -281,7 +369,7 @@ def get_replay(self) -> Callable[[simulator.GetReplayRequest], simulator.Replay] # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_replay" not in self._stubs: - self._stubs["get_replay"] = self.grpc_channel.unary_unary( + self._stubs["get_replay"] = self._logged_channel.unary_unary( "/google.cloud.policysimulator.v1.Simulator/GetReplay", request_serializer=simulator.GetReplayRequest.serialize, response_deserializer=simulator.Replay.deserialize, @@ -309,7 +397,7 @@ def create_replay( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_replay" not in self._stubs: - self._stubs["create_replay"] = self.grpc_channel.unary_unary( + self._stubs["create_replay"] = self._logged_channel.unary_unary( "/google.cloud.policysimulator.v1.Simulator/CreateReplay", request_serializer=simulator.CreateReplayRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -338,7 +426,7 @@ def list_replay_results( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_replay_results" not in self._stubs: - self._stubs["list_replay_results"] = self.grpc_channel.unary_unary( + self._stubs["list_replay_results"] = self._logged_channel.unary_unary( "/google.cloud.policysimulator.v1.Simulator/ListReplayResults", request_serializer=simulator.ListReplayResultsRequest.serialize, response_deserializer=simulator.ListReplayResultsResponse.deserialize, @@ -346,7 +434,7 @@ def list_replay_results( return self._stubs["list_replay_results"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def get_operation( @@ -358,7 +446,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, @@ -377,7 +465,7 @@ def list_operations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_operations" not in self._stubs: - self._stubs["list_operations"] = self.grpc_channel.unary_unary( + self._stubs["list_operations"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/ListOperations", request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, response_deserializer=operations_pb2.ListOperationsResponse.FromString, diff --git a/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/transports/grpc_asyncio.py b/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/transports/grpc_asyncio.py index 4bda0d77dc28..7dcbbb9d7695 100644 --- a/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/transports/grpc_asyncio.py +++ b/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -23,14 +26,93 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.policysimulator_v1.types import simulator from .base import DEFAULT_CLIENT_INFO, SimulatorTransport from .grpc import SimulatorGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.policysimulator.v1.Simulator", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.policysimulator.v1.Simulator", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class SimulatorGrpcAsyncIOTransport(SimulatorTransport): """gRPC AsyncIO backend transport for Simulator. @@ -240,10 +322,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -266,7 +351,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel + self._logged_channel ) # Return the client from cache. @@ -293,7 +378,7 @@ def get_replay( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_replay" not in self._stubs: - self._stubs["get_replay"] = self.grpc_channel.unary_unary( + self._stubs["get_replay"] = self._logged_channel.unary_unary( "/google.cloud.policysimulator.v1.Simulator/GetReplay", request_serializer=simulator.GetReplayRequest.serialize, response_deserializer=simulator.Replay.deserialize, @@ -321,7 +406,7 @@ def create_replay( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_replay" not in self._stubs: - self._stubs["create_replay"] = self.grpc_channel.unary_unary( + self._stubs["create_replay"] = self._logged_channel.unary_unary( "/google.cloud.policysimulator.v1.Simulator/CreateReplay", request_serializer=simulator.CreateReplayRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -351,7 +436,7 @@ def list_replay_results( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_replay_results" not in self._stubs: - self._stubs["list_replay_results"] = self.grpc_channel.unary_unary( + self._stubs["list_replay_results"] = self._logged_channel.unary_unary( "/google.cloud.policysimulator.v1.Simulator/ListReplayResults", request_serializer=simulator.ListReplayResultsRequest.serialize, response_deserializer=simulator.ListReplayResultsResponse.deserialize, @@ -412,7 +497,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: @@ -428,7 +513,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, @@ -447,7 +532,7 @@ def list_operations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_operations" not in self._stubs: - self._stubs["list_operations"] = self.grpc_channel.unary_unary( + self._stubs["list_operations"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/ListOperations", request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, response_deserializer=operations_pb2.ListOperationsResponse.FromString, diff --git a/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/transports/rest.py b/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/transports/rest.py index d194f4187e37..a33fc9056af4 100644 --- a/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/transports/rest.py +++ b/packages/google-cloud-policysimulator/google/cloud/policysimulator_v1/services/simulator/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -38,6 +38,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -94,8 +102,8 @@ def post_list_replay_results(self, response): def pre_create_replay( self, request: simulator.CreateReplayRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[simulator.CreateReplayRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[simulator.CreateReplayRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for create_replay Override in a subclass to manipulate the request or metadata @@ -115,8 +123,10 @@ def post_create_replay( return response def pre_get_replay( - self, request: simulator.GetReplayRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[simulator.GetReplayRequest, Sequence[Tuple[str, str]]]: + self, + request: simulator.GetReplayRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[simulator.GetReplayRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for get_replay Override in a subclass to manipulate the request or metadata @@ -136,8 +146,10 @@ def post_get_replay(self, response: simulator.Replay) -> simulator.Replay: def pre_list_replay_results( self, request: simulator.ListReplayResultsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[simulator.ListReplayResultsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + simulator.ListReplayResultsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_replay_results Override in a subclass to manipulate the request or metadata @@ -159,8 +171,10 @@ def post_list_replay_results( def pre_get_operation( self, request: operations_pb2.GetOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.GetOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.GetOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_operation Override in a subclass to manipulate the request or metadata @@ -182,8 +196,10 @@ def post_get_operation( def pre_list_operations( self, request: operations_pb2.ListOperationsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.ListOperationsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.ListOperationsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_operations Override in a subclass to manipulate the request or metadata @@ -401,7 +417,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the create replay method over HTTP. @@ -412,8 +428,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -426,6 +444,7 @@ def __call__( http_options = ( _BaseSimulatorRestTransport._BaseCreateReplay._get_http_options() ) + request, metadata = self._interceptor.pre_create_replay(request, metadata) transcoded_request = ( _BaseSimulatorRestTransport._BaseCreateReplay._get_transcoded_request( @@ -444,6 +463,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.policysimulator_v1.SimulatorClient.CreateReplay", + extra={ + "serviceName": "google.cloud.policysimulator.v1.Simulator", + "rpcName": "CreateReplay", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = SimulatorRestTransport._CreateReplay._get_response( self._host, @@ -463,7 +509,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_replay(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.policysimulator_v1.SimulatorClient.create_replay", + extra={ + "serviceName": "google.cloud.policysimulator.v1.Simulator", + "rpcName": "CreateReplay", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetReplay(_BaseSimulatorRestTransport._BaseGetReplay, SimulatorRestStub): @@ -498,7 +566,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> simulator.Replay: r"""Call the get replay method over HTTP. @@ -509,8 +577,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.simulator.Replay: @@ -520,6 +590,7 @@ def __call__( http_options = ( _BaseSimulatorRestTransport._BaseGetReplay._get_http_options() ) + request, metadata = self._interceptor.pre_get_replay(request, metadata) transcoded_request = ( _BaseSimulatorRestTransport._BaseGetReplay._get_transcoded_request( @@ -534,6 +605,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.policysimulator_v1.SimulatorClient.GetReplay", + extra={ + "serviceName": "google.cloud.policysimulator.v1.Simulator", + "rpcName": "GetReplay", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = SimulatorRestTransport._GetReplay._get_response( self._host, @@ -554,7 +652,29 @@ def __call__( pb_resp = simulator.Replay.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_replay(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = simulator.Replay.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.policysimulator_v1.SimulatorClient.get_replay", + extra={ + "serviceName": "google.cloud.policysimulator.v1.Simulator", + "rpcName": "GetReplay", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListReplayResults( @@ -591,7 +711,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> simulator.ListReplayResultsResponse: r"""Call the list replay results method over HTTP. @@ -602,8 +722,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.simulator.ListReplayResultsResponse: @@ -615,6 +737,7 @@ def __call__( http_options = ( _BaseSimulatorRestTransport._BaseListReplayResults._get_http_options() ) + request, metadata = self._interceptor.pre_list_replay_results( request, metadata ) @@ -627,6 +750,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.policysimulator_v1.SimulatorClient.ListReplayResults", + extra={ + "serviceName": "google.cloud.policysimulator.v1.Simulator", + "rpcName": "ListReplayResults", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = SimulatorRestTransport._ListReplayResults._get_response( self._host, @@ -647,7 +797,31 @@ def __call__( pb_resp = simulator.ListReplayResultsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_replay_results(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = simulator.ListReplayResultsResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.policysimulator_v1.SimulatorClient.list_replay_results", + extra={ + "serviceName": "google.cloud.policysimulator.v1.Simulator", + "rpcName": "ListReplayResults", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property @@ -712,7 +886,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the get operation method over HTTP. @@ -722,8 +896,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: operations_pb2.Operation: Response from GetOperation method. @@ -732,6 +908,7 @@ def __call__( http_options = ( _BaseSimulatorRestTransport._BaseGetOperation._get_http_options() ) + request, metadata = self._interceptor.pre_get_operation(request, metadata) transcoded_request = ( _BaseSimulatorRestTransport._BaseGetOperation._get_transcoded_request( @@ -746,6 +923,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.policysimulator_v1.SimulatorClient.GetOperation", + extra={ + "serviceName": "google.cloud.policysimulator.v1.Simulator", + "rpcName": "GetOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = SimulatorRestTransport._GetOperation._get_response( self._host, @@ -765,6 +969,27 @@ def __call__( resp = operations_pb2.Operation() resp = json_format.Parse(content, resp) resp = self._interceptor.post_get_operation(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.policysimulator_v1.SimulatorAsyncClient.GetOperation", + extra={ + "serviceName": "google.cloud.policysimulator.v1.Simulator", + "rpcName": "GetOperation", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property @@ -805,7 +1030,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Call the list operations method over HTTP. @@ -815,8 +1040,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: operations_pb2.ListOperationsResponse: Response from ListOperations method. @@ -825,6 +1052,7 @@ def __call__( http_options = ( _BaseSimulatorRestTransport._BaseListOperations._get_http_options() ) + request, metadata = self._interceptor.pre_list_operations(request, metadata) transcoded_request = ( _BaseSimulatorRestTransport._BaseListOperations._get_transcoded_request( @@ -839,6 +1067,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.policysimulator_v1.SimulatorClient.ListOperations", + extra={ + "serviceName": "google.cloud.policysimulator.v1.Simulator", + "rpcName": "ListOperations", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = SimulatorRestTransport._ListOperations._get_response( self._host, @@ -858,6 +1113,27 @@ def __call__( resp = operations_pb2.ListOperationsResponse() resp = json_format.Parse(content, resp) resp = self._interceptor.post_list_operations(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.policysimulator_v1.SimulatorAsyncClient.ListOperations", + extra={ + "serviceName": "google.cloud.policysimulator.v1.Simulator", + "rpcName": "ListOperations", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property diff --git a/packages/google-cloud-policysimulator/samples/generated_samples/snippet_metadata_google.cloud.policysimulator.v1.json b/packages/google-cloud-policysimulator/samples/generated_samples/snippet_metadata_google.cloud.policysimulator.v1.json index 602d543b880d..a6025abb1eff 100644 --- a/packages/google-cloud-policysimulator/samples/generated_samples/snippet_metadata_google.cloud.policysimulator.v1.json +++ b/packages/google-cloud-policysimulator/samples/generated_samples/snippet_metadata_google.cloud.policysimulator.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-policysimulator", - "version": "0.1.10" + "version": "0.1.0" }, "snippets": [ { @@ -51,7 +51,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -135,7 +135,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -216,7 +216,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.policysimulator_v1.types.Replay", @@ -296,7 +296,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.policysimulator_v1.types.Replay", @@ -377,7 +377,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.policysimulator_v1.services.simulator.pagers.ListReplayResultsAsyncPager", @@ -457,7 +457,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.policysimulator_v1.services.simulator.pagers.ListReplayResultsPager", diff --git a/packages/google-cloud-policysimulator/tests/unit/gapic/policysimulator_v1/test_simulator.py b/packages/google-cloud-policysimulator/tests/unit/gapic/policysimulator_v1/test_simulator.py index 978b0c0036c1..f480031f602e 100644 --- a/packages/google-cloud-policysimulator/tests/unit/gapic/policysimulator_v1/test_simulator.py +++ b/packages/google-cloud-policysimulator/tests/unit/gapic/policysimulator_v1/test_simulator.py @@ -2331,6 +2331,7 @@ def test_get_replay_rest_required_fields(request_type=simulator.GetReplayRequest response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_replay(request) @@ -2376,6 +2377,7 @@ def test_get_replay_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_replay(**mock_args) @@ -2506,6 +2508,7 @@ def test_create_replay_rest_required_fields(request_type=simulator.CreateReplayR response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_replay(request) @@ -2558,6 +2561,7 @@ def test_create_replay_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_replay(**mock_args) @@ -2700,6 +2704,7 @@ def test_list_replay_results_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_replay_results(request) @@ -2755,6 +2760,7 @@ def test_list_replay_results_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_replay_results(**mock_args) @@ -3142,6 +3148,7 @@ def test_get_replay_rest_bad_request(request_type=simulator.GetReplayRequest): response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_replay(request) @@ -3178,6 +3185,7 @@ def test_get_replay_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_replay(request) # Establish that the response is the type that we expect. @@ -3215,6 +3223,7 @@ def test_get_replay_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = simulator.Replay.to_json(simulator.Replay()) req.return_value.content = return_value @@ -3257,6 +3266,7 @@ def test_create_replay_rest_bad_request(request_type=simulator.CreateReplayReque response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_replay(request) @@ -3367,6 +3377,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_replay(request) # Establish that the response is the type that we expect. @@ -3404,6 +3415,7 @@ def test_create_replay_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -3448,6 +3460,7 @@ def test_list_replay_results_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_replay_results(request) @@ -3483,6 +3496,7 @@ def test_list_replay_results_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_replay_results(request) # Establish that the response is the type that we expect. @@ -3521,6 +3535,7 @@ def test_list_replay_results_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = simulator.ListReplayResultsResponse.to_json( simulator.ListReplayResultsResponse() ) @@ -3567,6 +3582,7 @@ def test_get_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_operation(request) @@ -3597,6 +3613,7 @@ def test_get_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_operation(request) @@ -3625,6 +3642,7 @@ def test_list_operations_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_operations(request) @@ -3655,6 +3673,7 @@ def test_list_operations_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_operations(request) diff --git a/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam/gapic_version.py b/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam/gapic_version.py index f8ea948a9c30..558c8aab67c5 100644 --- a/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam/gapic_version.py +++ b/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.1.9" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/gapic_version.py b/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/gapic_version.py index f8ea948a9c30..558c8aab67c5 100644 --- a/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/gapic_version.py +++ b/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.1.9" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/services/policy_troubleshooter/async_client.py b/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/services/policy_troubleshooter/async_client.py index 5911aff64219..747c37a13c4e 100644 --- a/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/services/policy_troubleshooter/async_client.py +++ b/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/services/policy_troubleshooter/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -48,6 +49,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, PolicyTroubleshooterTransport from .transports.grpc_asyncio import PolicyTroubleshooterGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class PolicyTroubleshooterAsyncClient: """IAM Policy Troubleshooter service. @@ -259,6 +269,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.policytroubleshooter.iam_v3.PolicyTroubleshooterAsyncClient`.", + extra={ + "serviceName": "google.cloud.policytroubleshooter.iam.v3.PolicyTroubleshooter", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.policytroubleshooter.iam.v3.PolicyTroubleshooter", + "credentialsType": None, + }, + ) + async def troubleshoot_iam_policy( self, request: Optional[ @@ -267,7 +299,7 @@ async def troubleshoot_iam_policy( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> troubleshooter.TroubleshootIamPolicyResponse: r"""Checks whether a principal has a specific permission for a specific resource, and explains why the principal @@ -305,8 +337,10 @@ async def sample_troubleshoot_iam_policy(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.policytroubleshooter_iam_v3.types.TroubleshootIamPolicyResponse: diff --git a/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/services/policy_troubleshooter/client.py b/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/services/policy_troubleshooter/client.py index affefcd994e9..0686abdd9876 100644 --- a/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/services/policy_troubleshooter/client.py +++ b/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/services/policy_troubleshooter/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.cloud.policytroubleshooter_iam_v3.types import troubleshooter from .transports.base import DEFAULT_CLIENT_INFO, PolicyTroubleshooterTransport @@ -563,6 +573,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -629,6 +643,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.policytroubleshooter.iam_v3.PolicyTroubleshooterClient`.", + extra={ + "serviceName": "google.cloud.policytroubleshooter.iam.v3.PolicyTroubleshooter", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.policytroubleshooter.iam.v3.PolicyTroubleshooter", + "credentialsType": None, + }, + ) + def troubleshoot_iam_policy( self, request: Optional[ @@ -637,7 +674,7 @@ def troubleshoot_iam_policy( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> troubleshooter.TroubleshootIamPolicyResponse: r"""Checks whether a principal has a specific permission for a specific resource, and explains why the principal @@ -675,8 +712,10 @@ def sample_troubleshoot_iam_policy(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.policytroubleshooter_iam_v3.types.TroubleshootIamPolicyResponse: diff --git a/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/services/policy_troubleshooter/transports/grpc.py b/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/services/policy_troubleshooter/transports/grpc.py index b6199bf0aee5..1ee43ff1d2f4 100644 --- a/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/services/policy_troubleshooter/transports/grpc.py +++ b/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/services/policy_troubleshooter/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -20,12 +23,90 @@ import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.policytroubleshooter_iam_v3.types import troubleshooter from .base import DEFAULT_CLIENT_INFO, PolicyTroubleshooterTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.policytroubleshooter.iam.v3.PolicyTroubleshooter", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.policytroubleshooter.iam.v3.PolicyTroubleshooter", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class PolicyTroubleshooterGrpcTransport(PolicyTroubleshooterTransport): """gRPC backend transport for PolicyTroubleshooter. @@ -182,7 +263,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -261,7 +347,7 @@ def troubleshoot_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "troubleshoot_iam_policy" not in self._stubs: - self._stubs["troubleshoot_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["troubleshoot_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.policytroubleshooter.iam.v3.PolicyTroubleshooter/TroubleshootIamPolicy", request_serializer=troubleshooter.TroubleshootIamPolicyRequest.serialize, response_deserializer=troubleshooter.TroubleshootIamPolicyResponse.deserialize, @@ -269,7 +355,7 @@ def troubleshoot_iam_policy( return self._stubs["troubleshoot_iam_policy"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/services/policy_troubleshooter/transports/grpc_asyncio.py b/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/services/policy_troubleshooter/transports/grpc_asyncio.py index c489df56b809..2ff8ce911955 100644 --- a/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/services/policy_troubleshooter/transports/grpc_asyncio.py +++ b/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/services/policy_troubleshooter/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -22,14 +25,93 @@ from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.policytroubleshooter_iam_v3.types import troubleshooter from .base import DEFAULT_CLIENT_INFO, PolicyTroubleshooterTransport from .grpc import PolicyTroubleshooterGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.policytroubleshooter.iam.v3.PolicyTroubleshooter", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.policytroubleshooter.iam.v3.PolicyTroubleshooter", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class PolicyTroubleshooterGrpcAsyncIOTransport(PolicyTroubleshooterTransport): """gRPC AsyncIO backend transport for PolicyTroubleshooter. @@ -229,10 +311,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -269,7 +354,7 @@ def troubleshoot_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "troubleshoot_iam_policy" not in self._stubs: - self._stubs["troubleshoot_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["troubleshoot_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.policytroubleshooter.iam.v3.PolicyTroubleshooter/TroubleshootIamPolicy", request_serializer=troubleshooter.TroubleshootIamPolicyRequest.serialize, response_deserializer=troubleshooter.TroubleshootIamPolicyResponse.deserialize, @@ -301,7 +386,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/services/policy_troubleshooter/transports/rest.py b/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/services/policy_troubleshooter/transports/rest.py index 04fd56e17677..b86635758a38 100644 --- a/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/services/policy_troubleshooter/transports/rest.py +++ b/packages/google-cloud-policytroubleshooter-iam/google/cloud/policytroubleshooter_iam_v3/services/policy_troubleshooter/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -37,6 +37,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -77,8 +85,11 @@ def post_troubleshoot_iam_policy(self, response): def pre_troubleshoot_iam_policy( self, request: troubleshooter.TroubleshootIamPolicyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[troubleshooter.TroubleshootIamPolicyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + troubleshooter.TroubleshootIamPolicyRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for troubleshoot_iam_policy Override in a subclass to manipulate the request or metadata @@ -223,7 +234,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> troubleshooter.TroubleshootIamPolicyResponse: r"""Call the troubleshoot iam policy method over HTTP. @@ -234,8 +245,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.troubleshooter.TroubleshootIamPolicyResponse: @@ -247,6 +260,7 @@ def __call__( http_options = ( _BasePolicyTroubleshooterRestTransport._BaseTroubleshootIamPolicy._get_http_options() ) + request, metadata = self._interceptor.pre_troubleshoot_iam_policy( request, metadata ) @@ -263,6 +277,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.policytroubleshooter.iam_v3.PolicyTroubleshooterClient.TroubleshootIamPolicy", + extra={ + "serviceName": "google.cloud.policytroubleshooter.iam.v3.PolicyTroubleshooter", + "rpcName": "TroubleshootIamPolicy", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( PolicyTroubleshooterRestTransport._TroubleshootIamPolicy._get_response( @@ -286,7 +327,31 @@ def __call__( pb_resp = troubleshooter.TroubleshootIamPolicyResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_troubleshoot_iam_policy(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + troubleshooter.TroubleshootIamPolicyResponse.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.policytroubleshooter.iam_v3.PolicyTroubleshooterClient.troubleshoot_iam_policy", + extra={ + "serviceName": "google.cloud.policytroubleshooter.iam.v3.PolicyTroubleshooter", + "rpcName": "TroubleshootIamPolicy", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property diff --git a/packages/google-cloud-policytroubleshooter-iam/samples/generated_samples/snippet_metadata_google.cloud.policytroubleshooter.iam.v3.json b/packages/google-cloud-policytroubleshooter-iam/samples/generated_samples/snippet_metadata_google.cloud.policytroubleshooter.iam.v3.json index 4e1fac93718b..3ec65c7e8d34 100644 --- a/packages/google-cloud-policytroubleshooter-iam/samples/generated_samples/snippet_metadata_google.cloud.policytroubleshooter.iam.v3.json +++ b/packages/google-cloud-policytroubleshooter-iam/samples/generated_samples/snippet_metadata_google.cloud.policytroubleshooter.iam.v3.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-policytroubleshooter-iam", - "version": "0.1.9" + "version": "0.1.0" }, "snippets": [ { @@ -43,7 +43,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.policytroubleshooter_iam_v3.types.TroubleshootIamPolicyResponse", @@ -119,7 +119,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.policytroubleshooter_iam_v3.types.TroubleshootIamPolicyResponse", diff --git a/packages/google-cloud-policytroubleshooter-iam/tests/unit/gapic/policytroubleshooter_iam_v3/test_policy_troubleshooter.py b/packages/google-cloud-policytroubleshooter-iam/tests/unit/gapic/policytroubleshooter_iam_v3/test_policy_troubleshooter.py index d4951d6a8e28..ba1ad796eeec 100644 --- a/packages/google-cloud-policytroubleshooter-iam/tests/unit/gapic/policytroubleshooter_iam_v3/test_policy_troubleshooter.py +++ b/packages/google-cloud-policytroubleshooter-iam/tests/unit/gapic/policytroubleshooter_iam_v3/test_policy_troubleshooter.py @@ -1555,6 +1555,7 @@ def test_troubleshoot_iam_policy_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.troubleshoot_iam_policy(request) @@ -1590,6 +1591,7 @@ def test_troubleshoot_iam_policy_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.troubleshoot_iam_policy(request) # Establish that the response is the type that we expect. @@ -1633,6 +1635,7 @@ def test_troubleshoot_iam_policy_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = troubleshooter.TroubleshootIamPolicyResponse.to_json( troubleshooter.TroubleshootIamPolicyResponse() ) diff --git a/packages/google-cloud-private-ca/google/cloud/security/privateca/gapic_version.py b/packages/google-cloud-private-ca/google/cloud/security/privateca/gapic_version.py index 0b9427f4e8a5..558c8aab67c5 100644 --- a/packages/google-cloud-private-ca/google/cloud/security/privateca/gapic_version.py +++ b/packages/google-cloud-private-ca/google/cloud/security/privateca/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.13.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/gapic_version.py b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/gapic_version.py index 0b9427f4e8a5..558c8aab67c5 100644 --- a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/gapic_version.py +++ b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.13.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/async_client.py b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/async_client.py index 46e642f28c84..177a504a6318 100644 --- a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/async_client.py +++ b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -62,6 +63,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, CertificateAuthorityServiceTransport from .transports.grpc_asyncio import CertificateAuthorityServiceGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class CertificateAuthorityServiceAsyncClient: """[Certificate Authority @@ -306,6 +316,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.security.privateca_v1.CertificateAuthorityServiceAsyncClient`.", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "credentialsType": None, + }, + ) + async def create_certificate( self, request: Optional[Union[service.CreateCertificateRequest, dict]] = None, @@ -315,7 +347,7 @@ async def create_certificate( certificate_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Create a new [Certificate][google.cloud.security.privateca.v1.Certificate] in @@ -388,8 +420,10 @@ async def sample_create_certificate(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.types.Certificate: @@ -455,7 +489,7 @@ async def get_certificate( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Returns a [Certificate][google.cloud.security.privateca.v1.Certificate]. @@ -503,8 +537,10 @@ async def sample_get_certificate(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.types.Certificate: @@ -566,7 +602,7 @@ async def list_certificates( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListCertificatesAsyncPager: r"""Lists [Certificates][google.cloud.security.privateca.v1.Certificate]. @@ -614,8 +650,10 @@ async def sample_list_certificates(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.services.certificate_authority_service.pagers.ListCertificatesAsyncPager: @@ -690,7 +728,7 @@ async def revoke_certificate( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Revoke a [Certificate][google.cloud.security.privateca.v1.Certificate]. @@ -738,8 +776,10 @@ async def sample_revoke_certificate(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.types.Certificate: @@ -802,7 +842,7 @@ async def update_certificate( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Update a [Certificate][google.cloud.security.privateca.v1.Certificate]. @@ -861,8 +901,10 @@ async def sample_update_certificate(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.types.Certificate: @@ -930,7 +972,7 @@ async def activate_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Activate a [CertificateAuthority][google.cloud.security.privateca.v1.CertificateAuthority] @@ -994,8 +1036,10 @@ async def sample_activate_certificate_authority(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1074,7 +1118,7 @@ async def create_certificate_authority( certificate_authority_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Create a new [CertificateAuthority][google.cloud.security.privateca.v1.CertificateAuthority] @@ -1148,8 +1192,10 @@ async def sample_create_certificate_authority(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1232,7 +1278,7 @@ async def disable_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Disable a [CertificateAuthority][google.cloud.security.privateca.v1.CertificateAuthority]. @@ -1283,8 +1329,10 @@ async def sample_disable_certificate_authority(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1361,7 +1409,7 @@ async def enable_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Enable a [CertificateAuthority][google.cloud.security.privateca.v1.CertificateAuthority]. @@ -1412,8 +1460,10 @@ async def sample_enable_certificate_authority(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1490,7 +1540,7 @@ async def fetch_certificate_authority_csr( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> service.FetchCertificateAuthorityCsrResponse: r"""Fetch a certificate signing request (CSR) from a [CertificateAuthority][google.cloud.security.privateca.v1.CertificateAuthority] @@ -1546,8 +1596,10 @@ async def sample_fetch_certificate_authority_csr(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.types.FetchCertificateAuthorityCsrResponse: @@ -1608,7 +1660,7 @@ async def get_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.CertificateAuthority: r"""Returns a [CertificateAuthority][google.cloud.security.privateca.v1.CertificateAuthority]. @@ -1656,8 +1708,10 @@ async def sample_get_certificate_authority(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.types.CertificateAuthority: @@ -1724,7 +1778,7 @@ async def list_certificate_authorities( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListCertificateAuthoritiesAsyncPager: r"""Lists [CertificateAuthorities][google.cloud.security.privateca.v1.CertificateAuthority]. @@ -1773,8 +1827,10 @@ async def sample_list_certificate_authorities(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.services.certificate_authority_service.pagers.ListCertificateAuthoritiesAsyncPager: @@ -1851,7 +1907,7 @@ async def undelete_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Undelete a [CertificateAuthority][google.cloud.security.privateca.v1.CertificateAuthority] @@ -1903,8 +1959,10 @@ async def sample_undelete_certificate_authority(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1981,7 +2039,7 @@ async def delete_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Delete a [CertificateAuthority][google.cloud.security.privateca.v1.CertificateAuthority]. @@ -2032,8 +2090,10 @@ async def sample_delete_certificate_authority(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -2111,7 +2171,7 @@ async def update_certificate_authority( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Update a [CertificateAuthority][google.cloud.security.privateca.v1.CertificateAuthority]. @@ -2172,8 +2232,10 @@ async def sample_update_certificate_authority(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -2254,7 +2316,7 @@ async def create_ca_pool( ca_pool_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Create a [CaPool][google.cloud.security.privateca.v1.CaPool]. @@ -2324,8 +2386,10 @@ async def sample_create_ca_pool(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -2408,7 +2472,7 @@ async def update_ca_pool( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Update a [CaPool][google.cloud.security.privateca.v1.CaPool]. @@ -2467,8 +2531,10 @@ async def sample_update_ca_pool(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -2550,7 +2616,7 @@ async def get_ca_pool( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.CaPool: r"""Returns a [CaPool][google.cloud.security.privateca.v1.CaPool]. @@ -2597,8 +2663,10 @@ async def sample_get_ca_pool(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.types.CaPool: @@ -2666,7 +2734,7 @@ async def list_ca_pools( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListCaPoolsAsyncPager: r"""Lists [CaPools][google.cloud.security.privateca.v1.CaPool]. @@ -2713,8 +2781,10 @@ async def sample_list_ca_pools(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.services.certificate_authority_service.pagers.ListCaPoolsAsyncPager: @@ -2789,7 +2859,7 @@ async def delete_ca_pool( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Delete a [CaPool][google.cloud.security.privateca.v1.CaPool]. @@ -2838,8 +2908,10 @@ async def sample_delete_ca_pool(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -2918,7 +2990,7 @@ async def fetch_ca_certs( ca_pool: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> service.FetchCaCertsResponse: r"""FetchCaCerts returns the current trust anchor for the [CaPool][google.cloud.security.privateca.v1.CaPool]. This will @@ -2966,8 +3038,10 @@ async def sample_fetch_ca_certs(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.types.FetchCaCertsResponse: @@ -3030,7 +3104,7 @@ async def get_certificate_revocation_list( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.CertificateRevocationList: r"""Returns a [CertificateRevocationList][google.cloud.security.privateca.v1.CertificateRevocationList]. @@ -3078,8 +3152,10 @@ async def sample_get_certificate_revocation_list(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.types.CertificateRevocationList: @@ -3145,7 +3221,7 @@ async def list_certificate_revocation_lists( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListCertificateRevocationListsAsyncPager: r"""Lists [CertificateRevocationLists][google.cloud.security.privateca.v1.CertificateRevocationList]. @@ -3194,8 +3270,10 @@ async def sample_list_certificate_revocation_lists(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.services.certificate_authority_service.pagers.ListCertificateRevocationListsAsyncPager: @@ -3275,7 +3353,7 @@ async def update_certificate_revocation_list( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Update a [CertificateRevocationList][google.cloud.security.privateca.v1.CertificateRevocationList]. @@ -3331,8 +3409,10 @@ async def sample_update_certificate_revocation_list(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -3417,7 +3497,7 @@ async def create_certificate_template( certificate_template_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Create a new [CertificateTemplate][google.cloud.security.privateca.v1.CertificateTemplate] @@ -3485,8 +3565,10 @@ async def sample_create_certificate_template(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -3565,7 +3647,7 @@ async def delete_certificate_template( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""DeleteCertificateTemplate deletes a [CertificateTemplate][google.cloud.security.privateca.v1.CertificateTemplate]. @@ -3616,8 +3698,10 @@ async def sample_delete_certificate_template(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -3696,7 +3780,7 @@ async def get_certificate_template( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.CertificateTemplate: r"""Returns a [CertificateTemplate][google.cloud.security.privateca.v1.CertificateTemplate]. @@ -3744,8 +3828,10 @@ async def sample_get_certificate_template(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.types.CertificateTemplate: @@ -3808,7 +3894,7 @@ async def list_certificate_templates( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListCertificateTemplatesAsyncPager: r"""Lists [CertificateTemplates][google.cloud.security.privateca.v1.CertificateTemplate]. @@ -3856,8 +3942,10 @@ async def sample_list_certificate_templates(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.services.certificate_authority_service.pagers.ListCertificateTemplatesAsyncPager: @@ -3933,7 +4021,7 @@ async def update_certificate_template( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Update a [CertificateTemplate][google.cloud.security.privateca.v1.CertificateTemplate]. @@ -3989,8 +4077,10 @@ async def sample_update_certificate_template(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -4066,7 +4156,7 @@ async def list_operations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Lists operations that match the specified filter in the request. @@ -4077,8 +4167,10 @@ async def list_operations( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.ListOperationsResponse: Response message for ``ListOperations`` method. @@ -4119,7 +4211,7 @@ async def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -4130,8 +4222,10 @@ async def get_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. @@ -4172,7 +4266,7 @@ async def delete_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Deletes a long-running operation. @@ -4188,8 +4282,10 @@ async def delete_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: None """ @@ -4226,7 +4322,7 @@ async def cancel_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Starts asynchronous cancellation on a long-running operation. @@ -4241,8 +4337,10 @@ async def cancel_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: None """ @@ -4279,7 +4377,7 @@ async def set_iam_policy( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Sets the IAM access control policy on the specified function. @@ -4292,8 +4390,10 @@ async def set_iam_policy( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.policy_pb2.Policy: Defines an Identity and Access Management (IAM) policy. @@ -4398,7 +4498,7 @@ async def get_iam_policy( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Gets the IAM access control policy for a function. @@ -4412,8 +4512,10 @@ async def get_iam_policy( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.policy_pb2.Policy: Defines an Identity and Access Management (IAM) policy. @@ -4518,7 +4620,7 @@ async def test_iam_permissions( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: r"""Tests the specified IAM permissions against the IAM access control policy for a function. @@ -4533,8 +4635,10 @@ async def test_iam_permissions( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.iam_policy_pb2.TestIamPermissionsResponse: Response message for ``TestIamPermissions`` method. @@ -4578,7 +4682,7 @@ async def get_location( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.Location: r"""Gets information about a location. @@ -4589,8 +4693,10 @@ async def get_location( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.Location: Location object. @@ -4631,7 +4737,7 @@ async def list_locations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.ListLocationsResponse: r"""Lists information about the supported locations for this service. @@ -4642,8 +4748,10 @@ async def list_locations( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.ListLocationsResponse: Response message for ``ListLocations`` method. diff --git a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/client.py b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/client.py index c5cef6e3f44f..606be23f4074 100644 --- a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/client.py +++ b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.location import locations_pb2 # type: ignore @@ -702,6 +712,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -770,6 +784,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.security.privateca_v1.CertificateAuthorityServiceClient`.", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "credentialsType": None, + }, + ) + def create_certificate( self, request: Optional[Union[service.CreateCertificateRequest, dict]] = None, @@ -779,7 +816,7 @@ def create_certificate( certificate_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Create a new [Certificate][google.cloud.security.privateca.v1.Certificate] in @@ -852,8 +889,10 @@ def sample_create_certificate(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.types.Certificate: @@ -916,7 +955,7 @@ def get_certificate( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Returns a [Certificate][google.cloud.security.privateca.v1.Certificate]. @@ -964,8 +1003,10 @@ def sample_get_certificate(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.types.Certificate: @@ -1024,7 +1065,7 @@ def list_certificates( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListCertificatesPager: r"""Lists [Certificates][google.cloud.security.privateca.v1.Certificate]. @@ -1072,8 +1113,10 @@ def sample_list_certificates(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.services.certificate_authority_service.pagers.ListCertificatesPager: @@ -1145,7 +1188,7 @@ def revoke_certificate( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Revoke a [Certificate][google.cloud.security.privateca.v1.Certificate]. @@ -1193,8 +1236,10 @@ def sample_revoke_certificate(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.types.Certificate: @@ -1254,7 +1299,7 @@ def update_certificate( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Update a [Certificate][google.cloud.security.privateca.v1.Certificate]. @@ -1313,8 +1358,10 @@ def sample_update_certificate(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.types.Certificate: @@ -1379,7 +1426,7 @@ def activate_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Activate a [CertificateAuthority][google.cloud.security.privateca.v1.CertificateAuthority] @@ -1443,8 +1490,10 @@ def sample_activate_certificate_authority(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1522,7 +1571,7 @@ def create_certificate_authority( certificate_authority_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Create a new [CertificateAuthority][google.cloud.security.privateca.v1.CertificateAuthority] @@ -1596,8 +1645,10 @@ def sample_create_certificate_authority(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1679,7 +1730,7 @@ def disable_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Disable a [CertificateAuthority][google.cloud.security.privateca.v1.CertificateAuthority]. @@ -1730,8 +1781,10 @@ def sample_disable_certificate_authority(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1807,7 +1860,7 @@ def enable_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Enable a [CertificateAuthority][google.cloud.security.privateca.v1.CertificateAuthority]. @@ -1858,8 +1911,10 @@ def sample_enable_certificate_authority(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1935,7 +1990,7 @@ def fetch_certificate_authority_csr( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> service.FetchCertificateAuthorityCsrResponse: r"""Fetch a certificate signing request (CSR) from a [CertificateAuthority][google.cloud.security.privateca.v1.CertificateAuthority] @@ -1991,8 +2046,10 @@ def sample_fetch_certificate_authority_csr(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.types.FetchCertificateAuthorityCsrResponse: @@ -2052,7 +2109,7 @@ def get_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.CertificateAuthority: r"""Returns a [CertificateAuthority][google.cloud.security.privateca.v1.CertificateAuthority]. @@ -2100,8 +2157,10 @@ def sample_get_certificate_authority(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.types.CertificateAuthority: @@ -2167,7 +2226,7 @@ def list_certificate_authorities( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListCertificateAuthoritiesPager: r"""Lists [CertificateAuthorities][google.cloud.security.privateca.v1.CertificateAuthority]. @@ -2216,8 +2275,10 @@ def sample_list_certificate_authorities(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.services.certificate_authority_service.pagers.ListCertificateAuthoritiesPager: @@ -2293,7 +2354,7 @@ def undelete_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Undelete a [CertificateAuthority][google.cloud.security.privateca.v1.CertificateAuthority] @@ -2345,8 +2406,10 @@ def sample_undelete_certificate_authority(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -2422,7 +2485,7 @@ def delete_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Delete a [CertificateAuthority][google.cloud.security.privateca.v1.CertificateAuthority]. @@ -2473,8 +2536,10 @@ def sample_delete_certificate_authority(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -2551,7 +2616,7 @@ def update_certificate_authority( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Update a [CertificateAuthority][google.cloud.security.privateca.v1.CertificateAuthority]. @@ -2612,8 +2677,10 @@ def sample_update_certificate_authority(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -2693,7 +2760,7 @@ def create_ca_pool( ca_pool_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Create a [CaPool][google.cloud.security.privateca.v1.CaPool]. @@ -2763,8 +2830,10 @@ def sample_create_ca_pool(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -2844,7 +2913,7 @@ def update_ca_pool( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Update a [CaPool][google.cloud.security.privateca.v1.CaPool]. @@ -2903,8 +2972,10 @@ def sample_update_ca_pool(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -2983,7 +3054,7 @@ def get_ca_pool( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.CaPool: r"""Returns a [CaPool][google.cloud.security.privateca.v1.CaPool]. @@ -3030,8 +3101,10 @@ def sample_get_ca_pool(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.types.CaPool: @@ -3096,7 +3169,7 @@ def list_ca_pools( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListCaPoolsPager: r"""Lists [CaPools][google.cloud.security.privateca.v1.CaPool]. @@ -3143,8 +3216,10 @@ def sample_list_ca_pools(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.services.certificate_authority_service.pagers.ListCaPoolsPager: @@ -3216,7 +3291,7 @@ def delete_ca_pool( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Delete a [CaPool][google.cloud.security.privateca.v1.CaPool]. @@ -3265,8 +3340,10 @@ def sample_delete_ca_pool(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -3342,7 +3419,7 @@ def fetch_ca_certs( ca_pool: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> service.FetchCaCertsResponse: r"""FetchCaCerts returns the current trust anchor for the [CaPool][google.cloud.security.privateca.v1.CaPool]. This will @@ -3390,8 +3467,10 @@ def sample_fetch_ca_certs(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.types.FetchCaCertsResponse: @@ -3451,7 +3530,7 @@ def get_certificate_revocation_list( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.CertificateRevocationList: r"""Returns a [CertificateRevocationList][google.cloud.security.privateca.v1.CertificateRevocationList]. @@ -3499,8 +3578,10 @@ def sample_get_certificate_revocation_list(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.types.CertificateRevocationList: @@ -3565,7 +3646,7 @@ def list_certificate_revocation_lists( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListCertificateRevocationListsPager: r"""Lists [CertificateRevocationLists][google.cloud.security.privateca.v1.CertificateRevocationList]. @@ -3614,8 +3695,10 @@ def sample_list_certificate_revocation_lists(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.services.certificate_authority_service.pagers.ListCertificateRevocationListsPager: @@ -3694,7 +3777,7 @@ def update_certificate_revocation_list( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Update a [CertificateRevocationList][google.cloud.security.privateca.v1.CertificateRevocationList]. @@ -3750,8 +3833,10 @@ def sample_update_certificate_revocation_list(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -3835,7 +3920,7 @@ def create_certificate_template( certificate_template_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Create a new [CertificateTemplate][google.cloud.security.privateca.v1.CertificateTemplate] @@ -3903,8 +3988,10 @@ def sample_create_certificate_template(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -3982,7 +4069,7 @@ def delete_certificate_template( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""DeleteCertificateTemplate deletes a [CertificateTemplate][google.cloud.security.privateca.v1.CertificateTemplate]. @@ -4033,8 +4120,10 @@ def sample_delete_certificate_template(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -4112,7 +4201,7 @@ def get_certificate_template( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.CertificateTemplate: r"""Returns a [CertificateTemplate][google.cloud.security.privateca.v1.CertificateTemplate]. @@ -4160,8 +4249,10 @@ def sample_get_certificate_template(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.types.CertificateTemplate: @@ -4221,7 +4312,7 @@ def list_certificate_templates( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListCertificateTemplatesPager: r"""Lists [CertificateTemplates][google.cloud.security.privateca.v1.CertificateTemplate]. @@ -4269,8 +4360,10 @@ def sample_list_certificate_templates(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1.services.certificate_authority_service.pagers.ListCertificateTemplatesPager: @@ -4345,7 +4438,7 @@ def update_certificate_template( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Update a [CertificateTemplate][google.cloud.security.privateca.v1.CertificateTemplate]. @@ -4401,8 +4494,10 @@ def sample_update_certificate_template(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -4490,7 +4585,7 @@ def list_operations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Lists operations that match the specified filter in the request. @@ -4501,8 +4596,10 @@ def list_operations( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.ListOperationsResponse: Response message for ``ListOperations`` method. @@ -4543,7 +4640,7 @@ def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -4554,8 +4651,10 @@ def get_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. @@ -4596,7 +4695,7 @@ def delete_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Deletes a long-running operation. @@ -4612,8 +4711,10 @@ def delete_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: None """ @@ -4650,7 +4751,7 @@ def cancel_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Starts asynchronous cancellation on a long-running operation. @@ -4665,8 +4766,10 @@ def cancel_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: None """ @@ -4703,7 +4806,7 @@ def set_iam_policy( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Sets the IAM access control policy on the specified function. @@ -4716,8 +4819,10 @@ def set_iam_policy( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.policy_pb2.Policy: Defines an Identity and Access Management (IAM) policy. @@ -4822,7 +4927,7 @@ def get_iam_policy( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Gets the IAM access control policy for a function. @@ -4836,8 +4941,10 @@ def get_iam_policy( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.policy_pb2.Policy: Defines an Identity and Access Management (IAM) policy. @@ -4942,7 +5049,7 @@ def test_iam_permissions( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: r"""Tests the specified IAM permissions against the IAM access control policy for a function. @@ -4957,8 +5064,10 @@ def test_iam_permissions( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.iam_policy_pb2.TestIamPermissionsResponse: Response message for ``TestIamPermissions`` method. @@ -5000,7 +5109,7 @@ def get_location( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.Location: r"""Gets information about a location. @@ -5011,8 +5120,10 @@ def get_location( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.Location: Location object. @@ -5053,7 +5164,7 @@ def list_locations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.ListLocationsResponse: r"""Lists information about the supported locations for this service. @@ -5064,8 +5175,10 @@ def list_locations( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.ListLocationsResponse: Response message for ``ListLocations`` method. diff --git a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/pagers.py b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/pagers.py index 7fde73ce430a..d57a8ae02c8f 100644 --- a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/pagers.py +++ b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -81,8 +81,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = service.ListCertificatesRequest(request) @@ -141,7 +143,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -155,8 +157,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = service.ListCertificatesRequest(request) @@ -219,7 +223,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -233,8 +237,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = service.ListCertificateAuthoritiesRequest(request) @@ -293,7 +299,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -307,8 +313,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = service.ListCertificateAuthoritiesRequest(request) @@ -371,7 +379,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -385,8 +393,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = service.ListCaPoolsRequest(request) @@ -445,7 +455,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -459,8 +469,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = service.ListCaPoolsRequest(request) @@ -523,7 +535,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -537,8 +549,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = service.ListCertificateRevocationListsRequest(request) @@ -599,7 +613,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -613,8 +627,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = service.ListCertificateRevocationListsRequest(request) @@ -679,7 +695,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -693,8 +709,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = service.ListCertificateTemplatesRequest(request) @@ -753,7 +771,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -767,8 +785,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = service.ListCertificateTemplatesRequest(request) diff --git a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/transports/grpc.py b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/transports/grpc.py index 8f8c6b8e9fa2..30b79efbe4de 100644 --- a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/transports/grpc.py +++ b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -24,12 +27,90 @@ from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.security.privateca_v1.types import resources, service from .base import DEFAULT_CLIENT_INFO, CertificateAuthorityServiceTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class CertificateAuthorityServiceGrpcTransport(CertificateAuthorityServiceTransport): """gRPC backend transport for CertificateAuthorityService. @@ -186,7 +267,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -250,7 +336,9 @@ def operations_client(self) -> operations_v1.OperationsClient: """ # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + self._operations_client = operations_v1.OperationsClient( + self._logged_channel + ) # Return the client from cache. return self._operations_client @@ -277,7 +365,7 @@ def create_certificate( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_certificate" not in self._stubs: - self._stubs["create_certificate"] = self.grpc_channel.unary_unary( + self._stubs["create_certificate"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/CreateCertificate", request_serializer=service.CreateCertificateRequest.serialize, response_deserializer=resources.Certificate.deserialize, @@ -304,7 +392,7 @@ def get_certificate( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_certificate" not in self._stubs: - self._stubs["get_certificate"] = self.grpc_channel.unary_unary( + self._stubs["get_certificate"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/GetCertificate", request_serializer=service.GetCertificateRequest.serialize, response_deserializer=resources.Certificate.deserialize, @@ -331,7 +419,7 @@ def list_certificates( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_certificates" not in self._stubs: - self._stubs["list_certificates"] = self.grpc_channel.unary_unary( + self._stubs["list_certificates"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/ListCertificates", request_serializer=service.ListCertificatesRequest.serialize, response_deserializer=service.ListCertificatesResponse.deserialize, @@ -358,7 +446,7 @@ def revoke_certificate( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "revoke_certificate" not in self._stubs: - self._stubs["revoke_certificate"] = self.grpc_channel.unary_unary( + self._stubs["revoke_certificate"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/RevokeCertificate", request_serializer=service.RevokeCertificateRequest.serialize, response_deserializer=resources.Certificate.deserialize, @@ -388,7 +476,7 @@ def update_certificate( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_certificate" not in self._stubs: - self._stubs["update_certificate"] = self.grpc_channel.unary_unary( + self._stubs["update_certificate"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/UpdateCertificate", request_serializer=service.UpdateCertificateRequest.serialize, response_deserializer=resources.Certificate.deserialize, @@ -427,7 +515,7 @@ def activate_certificate_authority( if "activate_certificate_authority" not in self._stubs: self._stubs[ "activate_certificate_authority" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/ActivateCertificateAuthority", request_serializer=service.ActivateCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -457,7 +545,9 @@ def create_certificate_authority( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_certificate_authority" not in self._stubs: - self._stubs["create_certificate_authority"] = self.grpc_channel.unary_unary( + self._stubs[ + "create_certificate_authority" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/CreateCertificateAuthority", request_serializer=service.CreateCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -488,7 +578,7 @@ def disable_certificate_authority( if "disable_certificate_authority" not in self._stubs: self._stubs[ "disable_certificate_authority" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/DisableCertificateAuthority", request_serializer=service.DisableCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -517,7 +607,9 @@ def enable_certificate_authority( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "enable_certificate_authority" not in self._stubs: - self._stubs["enable_certificate_authority"] = self.grpc_channel.unary_unary( + self._stubs[ + "enable_certificate_authority" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/EnableCertificateAuthority", request_serializer=service.EnableCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -559,7 +651,7 @@ def fetch_certificate_authority_csr( if "fetch_certificate_authority_csr" not in self._stubs: self._stubs[ "fetch_certificate_authority_csr" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/FetchCertificateAuthorityCsr", request_serializer=service.FetchCertificateAuthorityCsrRequest.serialize, response_deserializer=service.FetchCertificateAuthorityCsrResponse.deserialize, @@ -588,7 +680,7 @@ def get_certificate_authority( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_certificate_authority" not in self._stubs: - self._stubs["get_certificate_authority"] = self.grpc_channel.unary_unary( + self._stubs["get_certificate_authority"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/GetCertificateAuthority", request_serializer=service.GetCertificateAuthorityRequest.serialize, response_deserializer=resources.CertificateAuthority.deserialize, @@ -618,7 +710,9 @@ def list_certificate_authorities( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_certificate_authorities" not in self._stubs: - self._stubs["list_certificate_authorities"] = self.grpc_channel.unary_unary( + self._stubs[ + "list_certificate_authorities" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/ListCertificateAuthorities", request_serializer=service.ListCertificateAuthoritiesRequest.serialize, response_deserializer=service.ListCertificateAuthoritiesResponse.deserialize, @@ -650,7 +744,7 @@ def undelete_certificate_authority( if "undelete_certificate_authority" not in self._stubs: self._stubs[ "undelete_certificate_authority" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/UndeleteCertificateAuthority", request_serializer=service.UndeleteCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -679,7 +773,9 @@ def delete_certificate_authority( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_certificate_authority" not in self._stubs: - self._stubs["delete_certificate_authority"] = self.grpc_channel.unary_unary( + self._stubs[ + "delete_certificate_authority" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/DeleteCertificateAuthority", request_serializer=service.DeleteCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -708,7 +804,9 @@ def update_certificate_authority( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_certificate_authority" not in self._stubs: - self._stubs["update_certificate_authority"] = self.grpc_channel.unary_unary( + self._stubs[ + "update_certificate_authority" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/UpdateCertificateAuthority", request_serializer=service.UpdateCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -734,7 +832,7 @@ def create_ca_pool( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_ca_pool" not in self._stubs: - self._stubs["create_ca_pool"] = self.grpc_channel.unary_unary( + self._stubs["create_ca_pool"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/CreateCaPool", request_serializer=service.CreateCaPoolRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -760,7 +858,7 @@ def update_ca_pool( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_ca_pool" not in self._stubs: - self._stubs["update_ca_pool"] = self.grpc_channel.unary_unary( + self._stubs["update_ca_pool"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/UpdateCaPool", request_serializer=service.UpdateCaPoolRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -784,7 +882,7 @@ def get_ca_pool(self) -> Callable[[service.GetCaPoolRequest], resources.CaPool]: # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_ca_pool" not in self._stubs: - self._stubs["get_ca_pool"] = self.grpc_channel.unary_unary( + self._stubs["get_ca_pool"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/GetCaPool", request_serializer=service.GetCaPoolRequest.serialize, response_deserializer=resources.CaPool.deserialize, @@ -810,7 +908,7 @@ def list_ca_pools( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_ca_pools" not in self._stubs: - self._stubs["list_ca_pools"] = self.grpc_channel.unary_unary( + self._stubs["list_ca_pools"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/ListCaPools", request_serializer=service.ListCaPoolsRequest.serialize, response_deserializer=service.ListCaPoolsResponse.deserialize, @@ -836,7 +934,7 @@ def delete_ca_pool( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_ca_pool" not in self._stubs: - self._stubs["delete_ca_pool"] = self.grpc_channel.unary_unary( + self._stubs["delete_ca_pool"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/DeleteCaPool", request_serializer=service.DeleteCaPoolRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -865,7 +963,7 @@ def fetch_ca_certs( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "fetch_ca_certs" not in self._stubs: - self._stubs["fetch_ca_certs"] = self.grpc_channel.unary_unary( + self._stubs["fetch_ca_certs"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/FetchCaCerts", request_serializer=service.FetchCaCertsRequest.serialize, response_deserializer=service.FetchCaCertsResponse.deserialize, @@ -898,7 +996,7 @@ def get_certificate_revocation_list( if "get_certificate_revocation_list" not in self._stubs: self._stubs[ "get_certificate_revocation_list" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/GetCertificateRevocationList", request_serializer=service.GetCertificateRevocationListRequest.serialize, response_deserializer=resources.CertificateRevocationList.deserialize, @@ -931,7 +1029,7 @@ def list_certificate_revocation_lists( if "list_certificate_revocation_lists" not in self._stubs: self._stubs[ "list_certificate_revocation_lists" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/ListCertificateRevocationLists", request_serializer=service.ListCertificateRevocationListsRequest.serialize, response_deserializer=service.ListCertificateRevocationListsResponse.deserialize, @@ -963,7 +1061,7 @@ def update_certificate_revocation_list( if "update_certificate_revocation_list" not in self._stubs: self._stubs[ "update_certificate_revocation_list" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/UpdateCertificateRevocationList", request_serializer=service.UpdateCertificateRevocationListRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -991,7 +1089,9 @@ def create_certificate_template( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_certificate_template" not in self._stubs: - self._stubs["create_certificate_template"] = self.grpc_channel.unary_unary( + self._stubs[ + "create_certificate_template" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/CreateCertificateTemplate", request_serializer=service.CreateCertificateTemplateRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -1018,7 +1118,9 @@ def delete_certificate_template( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_certificate_template" not in self._stubs: - self._stubs["delete_certificate_template"] = self.grpc_channel.unary_unary( + self._stubs[ + "delete_certificate_template" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/DeleteCertificateTemplate", request_serializer=service.DeleteCertificateTemplateRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -1047,7 +1149,7 @@ def get_certificate_template( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_certificate_template" not in self._stubs: - self._stubs["get_certificate_template"] = self.grpc_channel.unary_unary( + self._stubs["get_certificate_template"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/GetCertificateTemplate", request_serializer=service.GetCertificateTemplateRequest.serialize, response_deserializer=resources.CertificateTemplate.deserialize, @@ -1077,7 +1179,9 @@ def list_certificate_templates( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_certificate_templates" not in self._stubs: - self._stubs["list_certificate_templates"] = self.grpc_channel.unary_unary( + self._stubs[ + "list_certificate_templates" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/ListCertificateTemplates", request_serializer=service.ListCertificateTemplatesRequest.serialize, response_deserializer=service.ListCertificateTemplatesResponse.deserialize, @@ -1104,7 +1208,9 @@ def update_certificate_template( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_certificate_template" not in self._stubs: - self._stubs["update_certificate_template"] = self.grpc_channel.unary_unary( + self._stubs[ + "update_certificate_template" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/UpdateCertificateTemplate", request_serializer=service.UpdateCertificateTemplateRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -1112,7 +1218,7 @@ def update_certificate_template( return self._stubs["update_certificate_template"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def delete_operation( @@ -1124,7 +1230,7 @@ def delete_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_operation" not in self._stubs: - self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + self._stubs["delete_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/DeleteOperation", request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, response_deserializer=None, @@ -1141,7 +1247,7 @@ def cancel_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "cancel_operation" not in self._stubs: - self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + self._stubs["cancel_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/CancelOperation", request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, response_deserializer=None, @@ -1158,7 +1264,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, @@ -1177,7 +1283,7 @@ def list_operations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_operations" not in self._stubs: - self._stubs["list_operations"] = self.grpc_channel.unary_unary( + self._stubs["list_operations"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/ListOperations", request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, response_deserializer=operations_pb2.ListOperationsResponse.FromString, @@ -1196,7 +1302,7 @@ def list_locations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_locations" not in self._stubs: - self._stubs["list_locations"] = self.grpc_channel.unary_unary( + self._stubs["list_locations"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/ListLocations", request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, response_deserializer=locations_pb2.ListLocationsResponse.FromString, @@ -1213,7 +1319,7 @@ def get_location( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_location" not in self._stubs: - self._stubs["get_location"] = self.grpc_channel.unary_unary( + self._stubs["get_location"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/GetLocation", request_serializer=locations_pb2.GetLocationRequest.SerializeToString, response_deserializer=locations_pb2.Location.FromString, @@ -1238,7 +1344,7 @@ def set_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "set_iam_policy" not in self._stubs: - self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["set_iam_policy"] = self._logged_channel.unary_unary( "/google.iam.v1.IAMPolicy/SetIamPolicy", request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -1264,7 +1370,7 @@ def get_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_iam_policy" not in self._stubs: - self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["get_iam_policy"] = self._logged_channel.unary_unary( "/google.iam.v1.IAMPolicy/GetIamPolicy", request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -1293,7 +1399,7 @@ def test_iam_permissions( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "test_iam_permissions" not in self._stubs: - self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + self._stubs["test_iam_permissions"] = self._logged_channel.unary_unary( "/google.iam.v1.IAMPolicy/TestIamPermissions", request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, diff --git a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/transports/grpc_asyncio.py b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/transports/grpc_asyncio.py index 4cc625ede062..79f1ff57396f 100644 --- a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -26,14 +29,93 @@ from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.security.privateca_v1.types import resources, service from .base import DEFAULT_CLIENT_INFO, CertificateAuthorityServiceTransport from .grpc import CertificateAuthorityServiceGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class CertificateAuthorityServiceGrpcAsyncIOTransport( CertificateAuthorityServiceTransport @@ -235,10 +317,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -261,7 +346,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel + self._logged_channel ) # Return the client from cache. @@ -289,7 +374,7 @@ def create_certificate( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_certificate" not in self._stubs: - self._stubs["create_certificate"] = self.grpc_channel.unary_unary( + self._stubs["create_certificate"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/CreateCertificate", request_serializer=service.CreateCertificateRequest.serialize, response_deserializer=resources.Certificate.deserialize, @@ -316,7 +401,7 @@ def get_certificate( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_certificate" not in self._stubs: - self._stubs["get_certificate"] = self.grpc_channel.unary_unary( + self._stubs["get_certificate"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/GetCertificate", request_serializer=service.GetCertificateRequest.serialize, response_deserializer=resources.Certificate.deserialize, @@ -345,7 +430,7 @@ def list_certificates( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_certificates" not in self._stubs: - self._stubs["list_certificates"] = self.grpc_channel.unary_unary( + self._stubs["list_certificates"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/ListCertificates", request_serializer=service.ListCertificatesRequest.serialize, response_deserializer=service.ListCertificatesResponse.deserialize, @@ -372,7 +457,7 @@ def revoke_certificate( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "revoke_certificate" not in self._stubs: - self._stubs["revoke_certificate"] = self.grpc_channel.unary_unary( + self._stubs["revoke_certificate"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/RevokeCertificate", request_serializer=service.RevokeCertificateRequest.serialize, response_deserializer=resources.Certificate.deserialize, @@ -402,7 +487,7 @@ def update_certificate( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_certificate" not in self._stubs: - self._stubs["update_certificate"] = self.grpc_channel.unary_unary( + self._stubs["update_certificate"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/UpdateCertificate", request_serializer=service.UpdateCertificateRequest.serialize, response_deserializer=resources.Certificate.deserialize, @@ -442,7 +527,7 @@ def activate_certificate_authority( if "activate_certificate_authority" not in self._stubs: self._stubs[ "activate_certificate_authority" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/ActivateCertificateAuthority", request_serializer=service.ActivateCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -472,7 +557,9 @@ def create_certificate_authority( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_certificate_authority" not in self._stubs: - self._stubs["create_certificate_authority"] = self.grpc_channel.unary_unary( + self._stubs[ + "create_certificate_authority" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/CreateCertificateAuthority", request_serializer=service.CreateCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -504,7 +591,7 @@ def disable_certificate_authority( if "disable_certificate_authority" not in self._stubs: self._stubs[ "disable_certificate_authority" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/DisableCertificateAuthority", request_serializer=service.DisableCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -533,7 +620,9 @@ def enable_certificate_authority( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "enable_certificate_authority" not in self._stubs: - self._stubs["enable_certificate_authority"] = self.grpc_channel.unary_unary( + self._stubs[ + "enable_certificate_authority" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/EnableCertificateAuthority", request_serializer=service.EnableCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -575,7 +664,7 @@ def fetch_certificate_authority_csr( if "fetch_certificate_authority_csr" not in self._stubs: self._stubs[ "fetch_certificate_authority_csr" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/FetchCertificateAuthorityCsr", request_serializer=service.FetchCertificateAuthorityCsrRequest.serialize, response_deserializer=service.FetchCertificateAuthorityCsrResponse.deserialize, @@ -605,7 +694,7 @@ def get_certificate_authority( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_certificate_authority" not in self._stubs: - self._stubs["get_certificate_authority"] = self.grpc_channel.unary_unary( + self._stubs["get_certificate_authority"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/GetCertificateAuthority", request_serializer=service.GetCertificateAuthorityRequest.serialize, response_deserializer=resources.CertificateAuthority.deserialize, @@ -635,7 +724,9 @@ def list_certificate_authorities( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_certificate_authorities" not in self._stubs: - self._stubs["list_certificate_authorities"] = self.grpc_channel.unary_unary( + self._stubs[ + "list_certificate_authorities" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/ListCertificateAuthorities", request_serializer=service.ListCertificateAuthoritiesRequest.serialize, response_deserializer=service.ListCertificateAuthoritiesResponse.deserialize, @@ -668,7 +759,7 @@ def undelete_certificate_authority( if "undelete_certificate_authority" not in self._stubs: self._stubs[ "undelete_certificate_authority" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/UndeleteCertificateAuthority", request_serializer=service.UndeleteCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -697,7 +788,9 @@ def delete_certificate_authority( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_certificate_authority" not in self._stubs: - self._stubs["delete_certificate_authority"] = self.grpc_channel.unary_unary( + self._stubs[ + "delete_certificate_authority" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/DeleteCertificateAuthority", request_serializer=service.DeleteCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -726,7 +819,9 @@ def update_certificate_authority( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_certificate_authority" not in self._stubs: - self._stubs["update_certificate_authority"] = self.grpc_channel.unary_unary( + self._stubs[ + "update_certificate_authority" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/UpdateCertificateAuthority", request_serializer=service.UpdateCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -752,7 +847,7 @@ def create_ca_pool( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_ca_pool" not in self._stubs: - self._stubs["create_ca_pool"] = self.grpc_channel.unary_unary( + self._stubs["create_ca_pool"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/CreateCaPool", request_serializer=service.CreateCaPoolRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -778,7 +873,7 @@ def update_ca_pool( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_ca_pool" not in self._stubs: - self._stubs["update_ca_pool"] = self.grpc_channel.unary_unary( + self._stubs["update_ca_pool"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/UpdateCaPool", request_serializer=service.UpdateCaPoolRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -804,7 +899,7 @@ def get_ca_pool( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_ca_pool" not in self._stubs: - self._stubs["get_ca_pool"] = self.grpc_channel.unary_unary( + self._stubs["get_ca_pool"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/GetCaPool", request_serializer=service.GetCaPoolRequest.serialize, response_deserializer=resources.CaPool.deserialize, @@ -830,7 +925,7 @@ def list_ca_pools( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_ca_pools" not in self._stubs: - self._stubs["list_ca_pools"] = self.grpc_channel.unary_unary( + self._stubs["list_ca_pools"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/ListCaPools", request_serializer=service.ListCaPoolsRequest.serialize, response_deserializer=service.ListCaPoolsResponse.deserialize, @@ -856,7 +951,7 @@ def delete_ca_pool( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_ca_pool" not in self._stubs: - self._stubs["delete_ca_pool"] = self.grpc_channel.unary_unary( + self._stubs["delete_ca_pool"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/DeleteCaPool", request_serializer=service.DeleteCaPoolRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -887,7 +982,7 @@ def fetch_ca_certs( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "fetch_ca_certs" not in self._stubs: - self._stubs["fetch_ca_certs"] = self.grpc_channel.unary_unary( + self._stubs["fetch_ca_certs"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/FetchCaCerts", request_serializer=service.FetchCaCertsRequest.serialize, response_deserializer=service.FetchCaCertsResponse.deserialize, @@ -920,7 +1015,7 @@ def get_certificate_revocation_list( if "get_certificate_revocation_list" not in self._stubs: self._stubs[ "get_certificate_revocation_list" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/GetCertificateRevocationList", request_serializer=service.GetCertificateRevocationListRequest.serialize, response_deserializer=resources.CertificateRevocationList.deserialize, @@ -953,7 +1048,7 @@ def list_certificate_revocation_lists( if "list_certificate_revocation_lists" not in self._stubs: self._stubs[ "list_certificate_revocation_lists" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/ListCertificateRevocationLists", request_serializer=service.ListCertificateRevocationListsRequest.serialize, response_deserializer=service.ListCertificateRevocationListsResponse.deserialize, @@ -986,7 +1081,7 @@ def update_certificate_revocation_list( if "update_certificate_revocation_list" not in self._stubs: self._stubs[ "update_certificate_revocation_list" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/UpdateCertificateRevocationList", request_serializer=service.UpdateCertificateRevocationListRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -1016,7 +1111,9 @@ def create_certificate_template( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_certificate_template" not in self._stubs: - self._stubs["create_certificate_template"] = self.grpc_channel.unary_unary( + self._stubs[ + "create_certificate_template" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/CreateCertificateTemplate", request_serializer=service.CreateCertificateTemplateRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -1045,7 +1142,9 @@ def delete_certificate_template( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_certificate_template" not in self._stubs: - self._stubs["delete_certificate_template"] = self.grpc_channel.unary_unary( + self._stubs[ + "delete_certificate_template" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/DeleteCertificateTemplate", request_serializer=service.DeleteCertificateTemplateRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -1075,7 +1174,7 @@ def get_certificate_template( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_certificate_template" not in self._stubs: - self._stubs["get_certificate_template"] = self.grpc_channel.unary_unary( + self._stubs["get_certificate_template"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/GetCertificateTemplate", request_serializer=service.GetCertificateTemplateRequest.serialize, response_deserializer=resources.CertificateTemplate.deserialize, @@ -1105,7 +1204,9 @@ def list_certificate_templates( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_certificate_templates" not in self._stubs: - self._stubs["list_certificate_templates"] = self.grpc_channel.unary_unary( + self._stubs[ + "list_certificate_templates" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/ListCertificateTemplates", request_serializer=service.ListCertificateTemplatesRequest.serialize, response_deserializer=service.ListCertificateTemplatesResponse.deserialize, @@ -1134,7 +1235,9 @@ def update_certificate_template( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_certificate_template" not in self._stubs: - self._stubs["update_certificate_template"] = self.grpc_channel.unary_unary( + self._stubs[ + "update_certificate_template" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1.CertificateAuthorityService/UpdateCertificateTemplate", request_serializer=service.UpdateCertificateTemplateRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -1342,7 +1445,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: @@ -1358,7 +1461,7 @@ def delete_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_operation" not in self._stubs: - self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + self._stubs["delete_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/DeleteOperation", request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, response_deserializer=None, @@ -1375,7 +1478,7 @@ def cancel_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "cancel_operation" not in self._stubs: - self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + self._stubs["cancel_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/CancelOperation", request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, response_deserializer=None, @@ -1392,7 +1495,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, @@ -1411,7 +1514,7 @@ def list_operations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_operations" not in self._stubs: - self._stubs["list_operations"] = self.grpc_channel.unary_unary( + self._stubs["list_operations"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/ListOperations", request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, response_deserializer=operations_pb2.ListOperationsResponse.FromString, @@ -1430,7 +1533,7 @@ def list_locations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_locations" not in self._stubs: - self._stubs["list_locations"] = self.grpc_channel.unary_unary( + self._stubs["list_locations"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/ListLocations", request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, response_deserializer=locations_pb2.ListLocationsResponse.FromString, @@ -1447,7 +1550,7 @@ def get_location( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_location" not in self._stubs: - self._stubs["get_location"] = self.grpc_channel.unary_unary( + self._stubs["get_location"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/GetLocation", request_serializer=locations_pb2.GetLocationRequest.SerializeToString, response_deserializer=locations_pb2.Location.FromString, @@ -1472,7 +1575,7 @@ def set_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "set_iam_policy" not in self._stubs: - self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["set_iam_policy"] = self._logged_channel.unary_unary( "/google.iam.v1.IAMPolicy/SetIamPolicy", request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -1498,7 +1601,7 @@ def get_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_iam_policy" not in self._stubs: - self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["get_iam_policy"] = self._logged_channel.unary_unary( "/google.iam.v1.IAMPolicy/GetIamPolicy", request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -1527,7 +1630,7 @@ def test_iam_permissions( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "test_iam_permissions" not in self._stubs: - self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + self._stubs["test_iam_permissions"] = self._logged_channel.unary_unary( "/google.iam.v1.IAMPolicy/TestIamPermissions", request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, diff --git a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/transports/rest.py b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/transports/rest.py index 7913b2bf5cbf..c317a66afd11 100644 --- a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/transports/rest.py +++ b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1/services/certificate_authority_service/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -41,6 +41,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -305,8 +313,11 @@ def post_update_certificate_template(self, response): def pre_activate_certificate_authority( self, request: service.ActivateCertificateAuthorityRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.ActivateCertificateAuthorityRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.ActivateCertificateAuthorityRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for activate_certificate_authority Override in a subclass to manipulate the request or metadata @@ -326,8 +337,10 @@ def post_activate_certificate_authority( return response def pre_create_ca_pool( - self, request: service.CreateCaPoolRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[service.CreateCaPoolRequest, Sequence[Tuple[str, str]]]: + self, + request: service.CreateCaPoolRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[service.CreateCaPoolRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for create_ca_pool Override in a subclass to manipulate the request or metadata @@ -349,8 +362,10 @@ def post_create_ca_pool( def pre_create_certificate( self, request: service.CreateCertificateRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.CreateCertificateRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.CreateCertificateRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for create_certificate Override in a subclass to manipulate the request or metadata @@ -372,8 +387,11 @@ def post_create_certificate( def pre_create_certificate_authority( self, request: service.CreateCertificateAuthorityRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.CreateCertificateAuthorityRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.CreateCertificateAuthorityRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for create_certificate_authority Override in a subclass to manipulate the request or metadata @@ -395,8 +413,11 @@ def post_create_certificate_authority( def pre_create_certificate_template( self, request: service.CreateCertificateTemplateRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.CreateCertificateTemplateRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.CreateCertificateTemplateRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for create_certificate_template Override in a subclass to manipulate the request or metadata @@ -416,8 +437,10 @@ def post_create_certificate_template( return response def pre_delete_ca_pool( - self, request: service.DeleteCaPoolRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[service.DeleteCaPoolRequest, Sequence[Tuple[str, str]]]: + self, + request: service.DeleteCaPoolRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[service.DeleteCaPoolRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for delete_ca_pool Override in a subclass to manipulate the request or metadata @@ -439,8 +462,11 @@ def post_delete_ca_pool( def pre_delete_certificate_authority( self, request: service.DeleteCertificateAuthorityRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.DeleteCertificateAuthorityRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.DeleteCertificateAuthorityRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for delete_certificate_authority Override in a subclass to manipulate the request or metadata @@ -462,8 +488,11 @@ def post_delete_certificate_authority( def pre_delete_certificate_template( self, request: service.DeleteCertificateTemplateRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.DeleteCertificateTemplateRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.DeleteCertificateTemplateRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for delete_certificate_template Override in a subclass to manipulate the request or metadata @@ -485,8 +514,11 @@ def post_delete_certificate_template( def pre_disable_certificate_authority( self, request: service.DisableCertificateAuthorityRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.DisableCertificateAuthorityRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.DisableCertificateAuthorityRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for disable_certificate_authority Override in a subclass to manipulate the request or metadata @@ -508,8 +540,11 @@ def post_disable_certificate_authority( def pre_enable_certificate_authority( self, request: service.EnableCertificateAuthorityRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.EnableCertificateAuthorityRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.EnableCertificateAuthorityRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for enable_certificate_authority Override in a subclass to manipulate the request or metadata @@ -529,8 +564,10 @@ def post_enable_certificate_authority( return response def pre_fetch_ca_certs( - self, request: service.FetchCaCertsRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[service.FetchCaCertsRequest, Sequence[Tuple[str, str]]]: + self, + request: service.FetchCaCertsRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[service.FetchCaCertsRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for fetch_ca_certs Override in a subclass to manipulate the request or metadata @@ -552,8 +589,11 @@ def post_fetch_ca_certs( def pre_fetch_certificate_authority_csr( self, request: service.FetchCertificateAuthorityCsrRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.FetchCertificateAuthorityCsrRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.FetchCertificateAuthorityCsrRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for fetch_certificate_authority_csr Override in a subclass to manipulate the request or metadata @@ -573,8 +613,10 @@ def post_fetch_certificate_authority_csr( return response def pre_get_ca_pool( - self, request: service.GetCaPoolRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[service.GetCaPoolRequest, Sequence[Tuple[str, str]]]: + self, + request: service.GetCaPoolRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[service.GetCaPoolRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for get_ca_pool Override in a subclass to manipulate the request or metadata @@ -594,8 +636,8 @@ def post_get_ca_pool(self, response: resources.CaPool) -> resources.CaPool: def pre_get_certificate( self, request: service.GetCertificateRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.GetCertificateRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[service.GetCertificateRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for get_certificate Override in a subclass to manipulate the request or metadata @@ -617,8 +659,10 @@ def post_get_certificate( def pre_get_certificate_authority( self, request: service.GetCertificateAuthorityRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.GetCertificateAuthorityRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.GetCertificateAuthorityRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_certificate_authority Override in a subclass to manipulate the request or metadata @@ -640,8 +684,11 @@ def post_get_certificate_authority( def pre_get_certificate_revocation_list( self, request: service.GetCertificateRevocationListRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.GetCertificateRevocationListRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.GetCertificateRevocationListRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for get_certificate_revocation_list Override in a subclass to manipulate the request or metadata @@ -663,8 +710,10 @@ def post_get_certificate_revocation_list( def pre_get_certificate_template( self, request: service.GetCertificateTemplateRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.GetCertificateTemplateRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.GetCertificateTemplateRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_certificate_template Override in a subclass to manipulate the request or metadata @@ -684,8 +733,10 @@ def post_get_certificate_template( return response def pre_list_ca_pools( - self, request: service.ListCaPoolsRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[service.ListCaPoolsRequest, Sequence[Tuple[str, str]]]: + self, + request: service.ListCaPoolsRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[service.ListCaPoolsRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for list_ca_pools Override in a subclass to manipulate the request or metadata @@ -707,8 +758,11 @@ def post_list_ca_pools( def pre_list_certificate_authorities( self, request: service.ListCertificateAuthoritiesRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.ListCertificateAuthoritiesRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.ListCertificateAuthoritiesRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for list_certificate_authorities Override in a subclass to manipulate the request or metadata @@ -730,9 +784,10 @@ def post_list_certificate_authorities( def pre_list_certificate_revocation_lists( self, request: service.ListCertificateRevocationListsRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - service.ListCertificateRevocationListsRequest, Sequence[Tuple[str, str]] + service.ListCertificateRevocationListsRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for list_certificate_revocation_lists @@ -755,8 +810,10 @@ def post_list_certificate_revocation_lists( def pre_list_certificates( self, request: service.ListCertificatesRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.ListCertificatesRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.ListCertificatesRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_certificates Override in a subclass to manipulate the request or metadata @@ -778,8 +835,10 @@ def post_list_certificates( def pre_list_certificate_templates( self, request: service.ListCertificateTemplatesRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.ListCertificateTemplatesRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.ListCertificateTemplatesRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_certificate_templates Override in a subclass to manipulate the request or metadata @@ -801,8 +860,10 @@ def post_list_certificate_templates( def pre_revoke_certificate( self, request: service.RevokeCertificateRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.RevokeCertificateRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.RevokeCertificateRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for revoke_certificate Override in a subclass to manipulate the request or metadata @@ -824,8 +885,11 @@ def post_revoke_certificate( def pre_undelete_certificate_authority( self, request: service.UndeleteCertificateAuthorityRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.UndeleteCertificateAuthorityRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.UndeleteCertificateAuthorityRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for undelete_certificate_authority Override in a subclass to manipulate the request or metadata @@ -845,8 +909,10 @@ def post_undelete_certificate_authority( return response def pre_update_ca_pool( - self, request: service.UpdateCaPoolRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[service.UpdateCaPoolRequest, Sequence[Tuple[str, str]]]: + self, + request: service.UpdateCaPoolRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[service.UpdateCaPoolRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for update_ca_pool Override in a subclass to manipulate the request or metadata @@ -868,8 +934,10 @@ def post_update_ca_pool( def pre_update_certificate( self, request: service.UpdateCertificateRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.UpdateCertificateRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.UpdateCertificateRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for update_certificate Override in a subclass to manipulate the request or metadata @@ -891,8 +959,11 @@ def post_update_certificate( def pre_update_certificate_authority( self, request: service.UpdateCertificateAuthorityRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.UpdateCertificateAuthorityRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.UpdateCertificateAuthorityRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for update_certificate_authority Override in a subclass to manipulate the request or metadata @@ -914,9 +985,10 @@ def post_update_certificate_authority( def pre_update_certificate_revocation_list( self, request: service.UpdateCertificateRevocationListRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - service.UpdateCertificateRevocationListRequest, Sequence[Tuple[str, str]] + service.UpdateCertificateRevocationListRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for update_certificate_revocation_list @@ -939,8 +1011,11 @@ def post_update_certificate_revocation_list( def pre_update_certificate_template( self, request: service.UpdateCertificateTemplateRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.UpdateCertificateTemplateRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.UpdateCertificateTemplateRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for update_certificate_template Override in a subclass to manipulate the request or metadata @@ -962,8 +1037,10 @@ def post_update_certificate_template( def pre_get_location( self, request: locations_pb2.GetLocationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[locations_pb2.GetLocationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + locations_pb2.GetLocationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_location Override in a subclass to manipulate the request or metadata @@ -985,8 +1062,10 @@ def post_get_location( def pre_list_locations( self, request: locations_pb2.ListLocationsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[locations_pb2.ListLocationsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + locations_pb2.ListLocationsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_locations Override in a subclass to manipulate the request or metadata @@ -1008,8 +1087,10 @@ def post_list_locations( def pre_get_iam_policy( self, request: iam_policy_pb2.GetIamPolicyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[iam_policy_pb2.GetIamPolicyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + iam_policy_pb2.GetIamPolicyRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_iam_policy Override in a subclass to manipulate the request or metadata @@ -1029,8 +1110,10 @@ def post_get_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: def pre_set_iam_policy( self, request: iam_policy_pb2.SetIamPolicyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[iam_policy_pb2.SetIamPolicyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + iam_policy_pb2.SetIamPolicyRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for set_iam_policy Override in a subclass to manipulate the request or metadata @@ -1050,8 +1133,11 @@ def post_set_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: def pre_test_iam_permissions( self, request: iam_policy_pb2.TestIamPermissionsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[iam_policy_pb2.TestIamPermissionsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + iam_policy_pb2.TestIamPermissionsRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for test_iam_permissions Override in a subclass to manipulate the request or metadata @@ -1073,8 +1159,10 @@ def post_test_iam_permissions( def pre_cancel_operation( self, request: operations_pb2.CancelOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.CancelOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.CancelOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for cancel_operation Override in a subclass to manipulate the request or metadata @@ -1094,8 +1182,10 @@ def post_cancel_operation(self, response: None) -> None: def pre_delete_operation( self, request: operations_pb2.DeleteOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.DeleteOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.DeleteOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for delete_operation Override in a subclass to manipulate the request or metadata @@ -1115,8 +1205,10 @@ def post_delete_operation(self, response: None) -> None: def pre_get_operation( self, request: operations_pb2.GetOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.GetOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.GetOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_operation Override in a subclass to manipulate the request or metadata @@ -1138,8 +1230,10 @@ def post_get_operation( def pre_list_operations( self, request: operations_pb2.ListOperationsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.ListOperationsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.ListOperationsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_operations Override in a subclass to manipulate the request or metadata @@ -1341,7 +1435,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the activate certificate authority method over HTTP. @@ -1353,8 +1447,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1367,6 +1463,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseActivateCertificateAuthority._get_http_options() ) + request, metadata = self._interceptor.pre_activate_certificate_authority( request, metadata ) @@ -1383,6 +1480,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.ActivateCertificateAuthority", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "ActivateCertificateAuthority", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._ActivateCertificateAuthority._get_response( self._host, @@ -1402,7 +1526,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_activate_certificate_authority(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.activate_certificate_authority", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "ActivateCertificateAuthority", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _CreateCaPool( @@ -1441,7 +1587,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the create ca pool method over HTTP. @@ -1452,8 +1598,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1466,6 +1614,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseCreateCaPool._get_http_options() ) + request, metadata = self._interceptor.pre_create_ca_pool(request, metadata) transcoded_request = _BaseCertificateAuthorityServiceRestTransport._BaseCreateCaPool._get_transcoded_request( http_options, request @@ -1480,6 +1629,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.CreateCaPool", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "CreateCaPool", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( CertificateAuthorityServiceRestTransport._CreateCaPool._get_response( @@ -1501,7 +1677,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_ca_pool(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.create_ca_pool", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "CreateCaPool", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _CreateCertificate( @@ -1540,7 +1738,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Call the create certificate method over HTTP. @@ -1551,8 +1749,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resources.Certificate: @@ -1566,6 +1766,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseCreateCertificate._get_http_options() ) + request, metadata = self._interceptor.pre_create_certificate( request, metadata ) @@ -1582,6 +1783,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.CreateCertificate", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "CreateCertificate", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._CreateCertificate._get_response( self._host, @@ -1603,7 +1831,29 @@ def __call__( pb_resp = resources.Certificate.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_certificate(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resources.Certificate.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.create_certificate", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "CreateCertificate", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _CreateCertificateAuthority( @@ -1644,7 +1894,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the create certificate authority method over HTTP. @@ -1656,8 +1906,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1670,6 +1922,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseCreateCertificateAuthority._get_http_options() ) + request, metadata = self._interceptor.pre_create_certificate_authority( request, metadata ) @@ -1686,6 +1939,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.CreateCertificateAuthority", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "CreateCertificateAuthority", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._CreateCertificateAuthority._get_response( self._host, @@ -1705,7 +1985,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_certificate_authority(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.create_certificate_authority", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "CreateCertificateAuthority", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _CreateCertificateTemplate( @@ -1746,7 +2048,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the create certificate template method over HTTP. @@ -1758,8 +2060,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1772,6 +2076,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseCreateCertificateTemplate._get_http_options() ) + request, metadata = self._interceptor.pre_create_certificate_template( request, metadata ) @@ -1788,6 +2093,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.CreateCertificateTemplate", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "CreateCertificateTemplate", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._CreateCertificateTemplate._get_response( self._host, @@ -1807,7 +2139,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_certificate_template(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.create_certificate_template", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "CreateCertificateTemplate", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DeleteCaPool( @@ -1845,7 +2199,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the delete ca pool method over HTTP. @@ -1856,8 +2210,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1870,6 +2226,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseDeleteCaPool._get_http_options() ) + request, metadata = self._interceptor.pre_delete_ca_pool(request, metadata) transcoded_request = _BaseCertificateAuthorityServiceRestTransport._BaseDeleteCaPool._get_transcoded_request( http_options, request @@ -1880,6 +2237,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.DeleteCaPool", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "DeleteCaPool", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( CertificateAuthorityServiceRestTransport._DeleteCaPool._get_response( @@ -1900,7 +2284,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_delete_ca_pool(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.delete_ca_pool", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "DeleteCaPool", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DeleteCertificateAuthority( @@ -1940,7 +2346,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the delete certificate authority method over HTTP. @@ -1952,8 +2358,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1966,6 +2374,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseDeleteCertificateAuthority._get_http_options() ) + request, metadata = self._interceptor.pre_delete_certificate_authority( request, metadata ) @@ -1978,6 +2387,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.DeleteCertificateAuthority", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "DeleteCertificateAuthority", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._DeleteCertificateAuthority._get_response( self._host, @@ -1996,7 +2432,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_delete_certificate_authority(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.delete_certificate_authority", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "DeleteCertificateAuthority", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DeleteCertificateTemplate( @@ -2036,7 +2494,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the delete certificate template method over HTTP. @@ -2048,8 +2506,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -2062,6 +2522,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseDeleteCertificateTemplate._get_http_options() ) + request, metadata = self._interceptor.pre_delete_certificate_template( request, metadata ) @@ -2074,6 +2535,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.DeleteCertificateTemplate", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "DeleteCertificateTemplate", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._DeleteCertificateTemplate._get_response( self._host, @@ -2092,7 +2580,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_delete_certificate_template(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.delete_certificate_template", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "DeleteCertificateTemplate", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DisableCertificateAuthority( @@ -2133,7 +2643,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the disable certificate authority method over HTTP. @@ -2145,8 +2655,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -2159,6 +2671,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseDisableCertificateAuthority._get_http_options() ) + request, metadata = self._interceptor.pre_disable_certificate_authority( request, metadata ) @@ -2175,6 +2688,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.DisableCertificateAuthority", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "DisableCertificateAuthority", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._DisableCertificateAuthority._get_response( self._host, @@ -2194,7 +2734,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_disable_certificate_authority(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.disable_certificate_authority", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "DisableCertificateAuthority", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _EnableCertificateAuthority( @@ -2235,7 +2797,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the enable certificate authority method over HTTP. @@ -2247,8 +2809,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -2261,6 +2825,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseEnableCertificateAuthority._get_http_options() ) + request, metadata = self._interceptor.pre_enable_certificate_authority( request, metadata ) @@ -2277,6 +2842,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.EnableCertificateAuthority", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "EnableCertificateAuthority", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._EnableCertificateAuthority._get_response( self._host, @@ -2296,7 +2888,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_enable_certificate_authority(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.enable_certificate_authority", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "EnableCertificateAuthority", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _FetchCaCerts( @@ -2335,7 +2949,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> service.FetchCaCertsResponse: r"""Call the fetch ca certs method over HTTP. @@ -2346,8 +2960,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.service.FetchCaCertsResponse: @@ -2359,6 +2975,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseFetchCaCerts._get_http_options() ) + request, metadata = self._interceptor.pre_fetch_ca_certs(request, metadata) transcoded_request = _BaseCertificateAuthorityServiceRestTransport._BaseFetchCaCerts._get_transcoded_request( http_options, request @@ -2373,6 +2990,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.FetchCaCerts", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "FetchCaCerts", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( CertificateAuthorityServiceRestTransport._FetchCaCerts._get_response( @@ -2396,7 +3040,29 @@ def __call__( pb_resp = service.FetchCaCertsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_fetch_ca_certs(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = service.FetchCaCertsResponse.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.fetch_ca_certs", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "FetchCaCerts", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _FetchCertificateAuthorityCsr( @@ -2436,7 +3102,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> service.FetchCertificateAuthorityCsrResponse: r"""Call the fetch certificate authority csr method over HTTP. @@ -2448,8 +3114,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.service.FetchCertificateAuthorityCsrResponse: @@ -2461,6 +3129,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseFetchCertificateAuthorityCsr._get_http_options() ) + request, metadata = self._interceptor.pre_fetch_certificate_authority_csr( request, metadata ) @@ -2473,6 +3142,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.FetchCertificateAuthorityCsr", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "FetchCertificateAuthorityCsr", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._FetchCertificateAuthorityCsr._get_response( self._host, @@ -2493,7 +3189,31 @@ def __call__( pb_resp = service.FetchCertificateAuthorityCsrResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_fetch_certificate_authority_csr(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + service.FetchCertificateAuthorityCsrResponse.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.fetch_certificate_authority_csr", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "FetchCertificateAuthorityCsr", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetCaPool( @@ -2531,7 +3251,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.CaPool: r"""Call the get ca pool method over HTTP. @@ -2542,8 +3262,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resources.CaPool: @@ -2562,6 +3284,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseGetCaPool._get_http_options() ) + request, metadata = self._interceptor.pre_get_ca_pool(request, metadata) transcoded_request = _BaseCertificateAuthorityServiceRestTransport._BaseGetCaPool._get_transcoded_request( http_options, request @@ -2572,6 +3295,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.GetCaPool", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "GetCaPool", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( CertificateAuthorityServiceRestTransport._GetCaPool._get_response( @@ -2594,7 +3344,29 @@ def __call__( pb_resp = resources.CaPool.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_ca_pool(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resources.CaPool.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.get_ca_pool", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "GetCaPool", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetCertificate( @@ -2632,7 +3404,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Call the get certificate method over HTTP. @@ -2643,8 +3415,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resources.Certificate: @@ -2658,6 +3432,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseGetCertificate._get_http_options() ) + request, metadata = self._interceptor.pre_get_certificate(request, metadata) transcoded_request = _BaseCertificateAuthorityServiceRestTransport._BaseGetCertificate._get_transcoded_request( http_options, request @@ -2668,6 +3443,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.GetCertificate", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "GetCertificate", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( CertificateAuthorityServiceRestTransport._GetCertificate._get_response( @@ -2690,7 +3492,29 @@ def __call__( pb_resp = resources.Certificate.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_certificate(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resources.Certificate.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.get_certificate", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "GetCertificate", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetCertificateAuthority( @@ -2730,7 +3554,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.CertificateAuthority: r"""Call the get certificate authority method over HTTP. @@ -2741,8 +3565,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resources.CertificateAuthority: @@ -2758,6 +3584,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseGetCertificateAuthority._get_http_options() ) + request, metadata = self._interceptor.pre_get_certificate_authority( request, metadata ) @@ -2770,6 +3597,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.GetCertificateAuthority", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "GetCertificateAuthority", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._GetCertificateAuthority._get_response( self._host, @@ -2790,7 +3644,29 @@ def __call__( pb_resp = resources.CertificateAuthority.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_certificate_authority(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resources.CertificateAuthority.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.get_certificate_authority", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "GetCertificateAuthority", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetCertificateRevocationList( @@ -2830,7 +3706,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.CertificateRevocationList: r"""Call the get certificate revocation list method over HTTP. @@ -2842,8 +3718,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resources.CertificateRevocationList: @@ -2858,6 +3736,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseGetCertificateRevocationList._get_http_options() ) + request, metadata = self._interceptor.pre_get_certificate_revocation_list( request, metadata ) @@ -2870,6 +3749,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.GetCertificateRevocationList", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "GetCertificateRevocationList", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._GetCertificateRevocationList._get_response( self._host, @@ -2890,7 +3796,31 @@ def __call__( pb_resp = resources.CertificateRevocationList.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_certificate_revocation_list(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resources.CertificateRevocationList.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.get_certificate_revocation_list", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "GetCertificateRevocationList", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetCertificateTemplate( @@ -2930,7 +3860,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.CertificateTemplate: r"""Call the get certificate template method over HTTP. @@ -2941,8 +3871,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resources.CertificateTemplate: @@ -2955,6 +3887,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseGetCertificateTemplate._get_http_options() ) + request, metadata = self._interceptor.pre_get_certificate_template( request, metadata ) @@ -2967,6 +3900,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.GetCertificateTemplate", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "GetCertificateTemplate", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._GetCertificateTemplate._get_response( self._host, @@ -2987,7 +3947,29 @@ def __call__( pb_resp = resources.CertificateTemplate.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_certificate_template(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resources.CertificateTemplate.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.get_certificate_template", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "GetCertificateTemplate", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListCaPools( @@ -3025,7 +4007,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> service.ListCaPoolsResponse: r"""Call the list ca pools method over HTTP. @@ -3036,8 +4018,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.service.ListCaPoolsResponse: @@ -3049,6 +4033,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseListCaPools._get_http_options() ) + request, metadata = self._interceptor.pre_list_ca_pools(request, metadata) transcoded_request = _BaseCertificateAuthorityServiceRestTransport._BaseListCaPools._get_transcoded_request( http_options, request @@ -3059,6 +4044,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.ListCaPools", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "ListCaPools", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( CertificateAuthorityServiceRestTransport._ListCaPools._get_response( @@ -3081,7 +4093,29 @@ def __call__( pb_resp = service.ListCaPoolsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_ca_pools(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = service.ListCaPoolsResponse.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.list_ca_pools", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "ListCaPools", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListCertificateAuthorities( @@ -3121,7 +4155,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> service.ListCertificateAuthoritiesResponse: r"""Call the list certificate authorities method over HTTP. @@ -3133,8 +4167,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.service.ListCertificateAuthoritiesResponse: @@ -3146,6 +4182,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseListCertificateAuthorities._get_http_options() ) + request, metadata = self._interceptor.pre_list_certificate_authorities( request, metadata ) @@ -3158,6 +4195,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.ListCertificateAuthorities", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "ListCertificateAuthorities", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._ListCertificateAuthorities._get_response( self._host, @@ -3178,7 +4242,31 @@ def __call__( pb_resp = service.ListCertificateAuthoritiesResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_certificate_authorities(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + service.ListCertificateAuthoritiesResponse.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.list_certificate_authorities", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "ListCertificateAuthorities", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListCertificateRevocationLists( @@ -3218,7 +4306,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> service.ListCertificateRevocationListsResponse: r"""Call the list certificate revocation lists method over HTTP. @@ -3230,8 +4318,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.service.ListCertificateRevocationListsResponse: @@ -3243,6 +4333,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseListCertificateRevocationLists._get_http_options() ) + request, metadata = self._interceptor.pre_list_certificate_revocation_lists( request, metadata ) @@ -3255,6 +4346,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.ListCertificateRevocationLists", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "ListCertificateRevocationLists", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._ListCertificateRevocationLists._get_response( self._host, @@ -3275,7 +4393,31 @@ def __call__( pb_resp = service.ListCertificateRevocationListsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_certificate_revocation_lists(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + service.ListCertificateRevocationListsResponse.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.list_certificate_revocation_lists", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "ListCertificateRevocationLists", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListCertificates( @@ -3313,7 +4455,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> service.ListCertificatesResponse: r"""Call the list certificates method over HTTP. @@ -3324,8 +4466,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.service.ListCertificatesResponse: @@ -3337,6 +4481,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseListCertificates._get_http_options() ) + request, metadata = self._interceptor.pre_list_certificates( request, metadata ) @@ -3349,6 +4494,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.ListCertificates", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "ListCertificates", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._ListCertificates._get_response( self._host, @@ -3369,7 +4541,31 @@ def __call__( pb_resp = service.ListCertificatesResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_certificates(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = service.ListCertificatesResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.list_certificates", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "ListCertificates", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListCertificateTemplates( @@ -3409,7 +4605,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> service.ListCertificateTemplatesResponse: r"""Call the list certificate templates method over HTTP. @@ -3421,8 +4617,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.service.ListCertificateTemplatesResponse: @@ -3434,6 +4632,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseListCertificateTemplates._get_http_options() ) + request, metadata = self._interceptor.pre_list_certificate_templates( request, metadata ) @@ -3446,6 +4645,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.ListCertificateTemplates", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "ListCertificateTemplates", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._ListCertificateTemplates._get_response( self._host, @@ -3466,7 +4692,31 @@ def __call__( pb_resp = service.ListCertificateTemplatesResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_certificate_templates(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = service.ListCertificateTemplatesResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.list_certificate_templates", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "ListCertificateTemplates", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _RevokeCertificate( @@ -3505,7 +4755,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Call the revoke certificate method over HTTP. @@ -3516,8 +4766,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resources.Certificate: @@ -3531,6 +4783,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseRevokeCertificate._get_http_options() ) + request, metadata = self._interceptor.pre_revoke_certificate( request, metadata ) @@ -3547,6 +4800,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.RevokeCertificate", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "RevokeCertificate", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._RevokeCertificate._get_response( self._host, @@ -3568,7 +4848,29 @@ def __call__( pb_resp = resources.Certificate.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_revoke_certificate(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resources.Certificate.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.revoke_certificate", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "RevokeCertificate", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UndeleteCertificateAuthority( @@ -3609,7 +4911,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the undelete certificate authority method over HTTP. @@ -3621,8 +4923,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -3635,6 +4939,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseUndeleteCertificateAuthority._get_http_options() ) + request, metadata = self._interceptor.pre_undelete_certificate_authority( request, metadata ) @@ -3651,6 +4956,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.UndeleteCertificateAuthority", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "UndeleteCertificateAuthority", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._UndeleteCertificateAuthority._get_response( self._host, @@ -3670,7 +5002,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_undelete_certificate_authority(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.undelete_certificate_authority", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "UndeleteCertificateAuthority", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateCaPool( @@ -3709,7 +5063,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the update ca pool method over HTTP. @@ -3720,8 +5074,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -3734,6 +5090,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseUpdateCaPool._get_http_options() ) + request, metadata = self._interceptor.pre_update_ca_pool(request, metadata) transcoded_request = _BaseCertificateAuthorityServiceRestTransport._BaseUpdateCaPool._get_transcoded_request( http_options, request @@ -3748,6 +5105,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.UpdateCaPool", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "UpdateCaPool", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( CertificateAuthorityServiceRestTransport._UpdateCaPool._get_response( @@ -3769,7 +5153,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_ca_pool(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.update_ca_pool", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "UpdateCaPool", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateCertificate( @@ -3808,7 +5214,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Call the update certificate method over HTTP. @@ -3819,8 +5225,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resources.Certificate: @@ -3834,6 +5242,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseUpdateCertificate._get_http_options() ) + request, metadata = self._interceptor.pre_update_certificate( request, metadata ) @@ -3850,6 +5259,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.UpdateCertificate", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "UpdateCertificate", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._UpdateCertificate._get_response( self._host, @@ -3871,7 +5307,29 @@ def __call__( pb_resp = resources.Certificate.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_certificate(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resources.Certificate.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.update_certificate", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "UpdateCertificate", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateCertificateAuthority( @@ -3912,7 +5370,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the update certificate authority method over HTTP. @@ -3924,8 +5382,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -3938,6 +5398,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseUpdateCertificateAuthority._get_http_options() ) + request, metadata = self._interceptor.pre_update_certificate_authority( request, metadata ) @@ -3954,6 +5415,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.UpdateCertificateAuthority", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "UpdateCertificateAuthority", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._UpdateCertificateAuthority._get_response( self._host, @@ -3973,7 +5461,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_certificate_authority(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.update_certificate_authority", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "UpdateCertificateAuthority", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateCertificateRevocationList( @@ -4014,7 +5524,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the update certificate revocation list method over HTTP. @@ -4026,8 +5536,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -4040,6 +5552,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseUpdateCertificateRevocationList._get_http_options() ) + ( request, metadata, @@ -4059,6 +5572,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.UpdateCertificateRevocationList", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "UpdateCertificateRevocationList", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._UpdateCertificateRevocationList._get_response( self._host, @@ -4078,7 +5618,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_certificate_revocation_list(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.update_certificate_revocation_list", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "UpdateCertificateRevocationList", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateCertificateTemplate( @@ -4119,7 +5681,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the update certificate template method over HTTP. @@ -4131,8 +5693,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -4145,6 +5709,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseUpdateCertificateTemplate._get_http_options() ) + request, metadata = self._interceptor.pre_update_certificate_template( request, metadata ) @@ -4161,6 +5726,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.UpdateCertificateTemplate", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "UpdateCertificateTemplate", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._UpdateCertificateTemplate._get_response( self._host, @@ -4180,7 +5772,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_certificate_template(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.update_certificate_template", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "UpdateCertificateTemplate", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property @@ -4487,7 +6101,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.Location: r"""Call the get location method over HTTP. @@ -4497,8 +6111,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: locations_pb2.Location: Response from GetLocation method. @@ -4507,6 +6123,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseGetLocation._get_http_options() ) + request, metadata = self._interceptor.pre_get_location(request, metadata) transcoded_request = _BaseCertificateAuthorityServiceRestTransport._BaseGetLocation._get_transcoded_request( http_options, request @@ -4517,6 +6134,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.GetLocation", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "GetLocation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( CertificateAuthorityServiceRestTransport._GetLocation._get_response( @@ -4538,6 +6182,27 @@ def __call__( resp = locations_pb2.Location() resp = json_format.Parse(content, resp) resp = self._interceptor.post_get_location(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceAsyncClient.GetLocation", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "GetLocation", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property @@ -4579,7 +6244,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.ListLocationsResponse: r"""Call the list locations method over HTTP. @@ -4589,8 +6254,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: locations_pb2.ListLocationsResponse: Response from ListLocations method. @@ -4599,6 +6266,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseListLocations._get_http_options() ) + request, metadata = self._interceptor.pre_list_locations(request, metadata) transcoded_request = _BaseCertificateAuthorityServiceRestTransport._BaseListLocations._get_transcoded_request( http_options, request @@ -4609,6 +6277,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.ListLocations", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "ListLocations", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( CertificateAuthorityServiceRestTransport._ListLocations._get_response( @@ -4630,6 +6325,27 @@ def __call__( resp = locations_pb2.ListLocationsResponse() resp = json_format.Parse(content, resp) resp = self._interceptor.post_list_locations(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceAsyncClient.ListLocations", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "ListLocations", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property @@ -4671,7 +6387,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Call the get iam policy method over HTTP. @@ -4681,8 +6397,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: policy_pb2.Policy: Response from GetIamPolicy method. @@ -4691,6 +6409,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseGetIamPolicy._get_http_options() ) + request, metadata = self._interceptor.pre_get_iam_policy(request, metadata) transcoded_request = _BaseCertificateAuthorityServiceRestTransport._BaseGetIamPolicy._get_transcoded_request( http_options, request @@ -4701,6 +6420,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.GetIamPolicy", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "GetIamPolicy", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( CertificateAuthorityServiceRestTransport._GetIamPolicy._get_response( @@ -4722,6 +6468,27 @@ def __call__( resp = policy_pb2.Policy() resp = json_format.Parse(content, resp) resp = self._interceptor.post_get_iam_policy(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceAsyncClient.GetIamPolicy", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "GetIamPolicy", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property @@ -4764,7 +6531,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Call the set iam policy method over HTTP. @@ -4774,8 +6541,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: policy_pb2.Policy: Response from SetIamPolicy method. @@ -4784,6 +6553,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseSetIamPolicy._get_http_options() ) + request, metadata = self._interceptor.pre_set_iam_policy(request, metadata) transcoded_request = _BaseCertificateAuthorityServiceRestTransport._BaseSetIamPolicy._get_transcoded_request( http_options, request @@ -4798,6 +6568,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.SetIamPolicy", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "SetIamPolicy", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( CertificateAuthorityServiceRestTransport._SetIamPolicy._get_response( @@ -4820,6 +6617,27 @@ def __call__( resp = policy_pb2.Policy() resp = json_format.Parse(content, resp) resp = self._interceptor.post_set_iam_policy(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceAsyncClient.SetIamPolicy", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "SetIamPolicy", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property @@ -4862,7 +6680,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: r"""Call the test iam permissions method over HTTP. @@ -4872,8 +6690,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: iam_policy_pb2.TestIamPermissionsResponse: Response from TestIamPermissions method. @@ -4882,6 +6702,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseTestIamPermissions._get_http_options() ) + request, metadata = self._interceptor.pre_test_iam_permissions( request, metadata ) @@ -4898,6 +6719,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.TestIamPermissions", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "TestIamPermissions", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._TestIamPermissions._get_response( self._host, @@ -4918,6 +6766,27 @@ def __call__( resp = iam_policy_pb2.TestIamPermissionsResponse() resp = json_format.Parse(content, resp) resp = self._interceptor.post_test_iam_permissions(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceAsyncClient.TestIamPermissions", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "TestIamPermissions", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property @@ -4960,7 +6829,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Call the cancel operation method over HTTP. @@ -4970,13 +6839,16 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseCancelOperation._get_http_options() ) + request, metadata = self._interceptor.pre_cancel_operation( request, metadata ) @@ -4993,6 +6865,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.CancelOperation", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "CancelOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( CertificateAuthorityServiceRestTransport._CancelOperation._get_response( @@ -5052,7 +6951,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Call the delete operation method over HTTP. @@ -5062,13 +6961,16 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseDeleteOperation._get_http_options() ) + request, metadata = self._interceptor.pre_delete_operation( request, metadata ) @@ -5081,6 +6983,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.DeleteOperation", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "DeleteOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( CertificateAuthorityServiceRestTransport._DeleteOperation._get_response( @@ -5139,7 +7068,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the get operation method over HTTP. @@ -5149,8 +7078,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: operations_pb2.Operation: Response from GetOperation method. @@ -5159,6 +7090,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseGetOperation._get_http_options() ) + request, metadata = self._interceptor.pre_get_operation(request, metadata) transcoded_request = _BaseCertificateAuthorityServiceRestTransport._BaseGetOperation._get_transcoded_request( http_options, request @@ -5169,6 +7101,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.GetOperation", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "GetOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( CertificateAuthorityServiceRestTransport._GetOperation._get_response( @@ -5190,6 +7149,27 @@ def __call__( resp = operations_pb2.Operation() resp = json_format.Parse(content, resp) resp = self._interceptor.post_get_operation(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceAsyncClient.GetOperation", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "GetOperation", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property @@ -5231,7 +7211,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Call the list operations method over HTTP. @@ -5241,8 +7221,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: operations_pb2.ListOperationsResponse: Response from ListOperations method. @@ -5251,6 +7233,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseListOperations._get_http_options() ) + request, metadata = self._interceptor.pre_list_operations(request, metadata) transcoded_request = _BaseCertificateAuthorityServiceRestTransport._BaseListOperations._get_transcoded_request( http_options, request @@ -5261,6 +7244,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1.CertificateAuthorityServiceClient.ListOperations", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "ListOperations", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( CertificateAuthorityServiceRestTransport._ListOperations._get_response( @@ -5282,6 +7292,27 @@ def __call__( resp = operations_pb2.ListOperationsResponse() resp = json_format.Parse(content, resp) resp = self._interceptor.post_list_operations(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1.CertificateAuthorityServiceAsyncClient.ListOperations", + extra={ + "serviceName": "google.cloud.security.privateca.v1.CertificateAuthorityService", + "rpcName": "ListOperations", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property diff --git a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/gapic_version.py b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/gapic_version.py index 0b9427f4e8a5..558c8aab67c5 100644 --- a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/gapic_version.py +++ b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.13.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/async_client.py b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/async_client.py index da4fbf6716a3..507f7ab0f92a 100644 --- a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/async_client.py +++ b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -57,6 +58,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, CertificateAuthorityServiceTransport from .transports.grpc_asyncio import CertificateAuthorityServiceGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class CertificateAuthorityServiceAsyncClient: """[Certificate Authority @@ -297,6 +307,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceAsyncClient`.", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "credentialsType": None, + }, + ) + async def create_certificate( self, request: Optional[Union[service.CreateCertificateRequest, dict]] = None, @@ -306,7 +338,7 @@ async def create_certificate( certificate_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Create a new [Certificate][google.cloud.security.privateca.v1beta1.Certificate] @@ -381,8 +413,10 @@ async def sample_create_certificate(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.types.Certificate: @@ -447,7 +481,7 @@ async def get_certificate( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Returns a [Certificate][google.cloud.security.privateca.v1beta1.Certificate]. @@ -495,8 +529,10 @@ async def sample_get_certificate(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.types.Certificate: @@ -557,7 +593,7 @@ async def list_certificates( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListCertificatesAsyncPager: r"""Lists [Certificates][google.cloud.security.privateca.v1beta1.Certificate]. @@ -606,8 +642,10 @@ async def sample_list_certificates(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.services.certificate_authority_service.pagers.ListCertificatesAsyncPager: @@ -682,7 +720,7 @@ async def revoke_certificate( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Revoke a [Certificate][google.cloud.security.privateca.v1beta1.Certificate]. @@ -730,8 +768,10 @@ async def sample_revoke_certificate(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.types.Certificate: @@ -793,7 +833,7 @@ async def update_certificate( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Update a [Certificate][google.cloud.security.privateca.v1beta1.Certificate]. @@ -852,8 +892,10 @@ async def sample_update_certificate(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.types.Certificate: @@ -920,7 +962,7 @@ async def activate_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Activate a [CertificateAuthority][google.cloud.security.privateca.v1beta1.CertificateAuthority] @@ -984,8 +1026,10 @@ async def sample_activate_certificate_authority(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1063,7 +1107,7 @@ async def create_certificate_authority( certificate_authority_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Create a new [CertificateAuthority][google.cloud.security.privateca.v1beta1.CertificateAuthority] @@ -1138,8 +1182,10 @@ async def sample_create_certificate_authority(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1221,7 +1267,7 @@ async def disable_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Disable a [CertificateAuthority][google.cloud.security.privateca.v1beta1.CertificateAuthority]. @@ -1272,8 +1318,10 @@ async def sample_disable_certificate_authority(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1349,7 +1397,7 @@ async def enable_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Enable a [CertificateAuthority][google.cloud.security.privateca.v1beta1.CertificateAuthority]. @@ -1400,8 +1448,10 @@ async def sample_enable_certificate_authority(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1477,7 +1527,7 @@ async def fetch_certificate_authority_csr( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> service.FetchCertificateAuthorityCsrResponse: r"""Fetch a certificate signing request (CSR) from a [CertificateAuthority][google.cloud.security.privateca.v1beta1.CertificateAuthority] @@ -1533,8 +1583,10 @@ async def sample_fetch_certificate_authority_csr(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.types.FetchCertificateAuthorityCsrResponse: @@ -1595,7 +1647,7 @@ async def get_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.CertificateAuthority: r"""Returns a [CertificateAuthority][google.cloud.security.privateca.v1beta1.CertificateAuthority]. @@ -1643,8 +1695,10 @@ async def sample_get_certificate_authority(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.types.CertificateAuthority: @@ -1710,7 +1764,7 @@ async def list_certificate_authorities( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListCertificateAuthoritiesAsyncPager: r"""Lists [CertificateAuthorities][google.cloud.security.privateca.v1beta1.CertificateAuthority]. @@ -1758,8 +1812,10 @@ async def sample_list_certificate_authorities(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.services.certificate_authority_service.pagers.ListCertificateAuthoritiesAsyncPager: @@ -1836,7 +1892,7 @@ async def restore_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Restore a [CertificateAuthority][google.cloud.security.privateca.v1beta1.CertificateAuthority] @@ -1888,8 +1944,10 @@ async def sample_restore_certificate_authority(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1965,7 +2023,7 @@ async def schedule_delete_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Schedule a [CertificateAuthority][google.cloud.security.privateca.v1beta1.CertificateAuthority] @@ -2017,8 +2075,10 @@ async def sample_schedule_delete_certificate_authority(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -2095,7 +2155,7 @@ async def update_certificate_authority( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Update a [CertificateAuthority][google.cloud.security.privateca.v1beta1.CertificateAuthority]. @@ -2158,8 +2218,10 @@ async def sample_update_certificate_authority(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -2239,7 +2301,7 @@ async def get_certificate_revocation_list( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.CertificateRevocationList: r"""Returns a [CertificateRevocationList][google.cloud.security.privateca.v1beta1.CertificateRevocationList]. @@ -2287,8 +2349,10 @@ async def sample_get_certificate_revocation_list(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.types.CertificateRevocationList: @@ -2353,7 +2417,7 @@ async def list_certificate_revocation_lists( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListCertificateRevocationListsAsyncPager: r"""Lists [CertificateRevocationLists][google.cloud.security.privateca.v1beta1.CertificateRevocationList]. @@ -2402,8 +2466,10 @@ async def sample_list_certificate_revocation_lists(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.services.certificate_authority_service.pagers.ListCertificateRevocationListsAsyncPager: @@ -2483,7 +2549,7 @@ async def update_certificate_revocation_list( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Update a [CertificateRevocationList][google.cloud.security.privateca.v1beta1.CertificateRevocationList]. @@ -2539,8 +2605,10 @@ async def sample_update_certificate_revocation_list(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -2622,7 +2690,7 @@ async def get_reusable_config( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.ReusableConfig: r"""Returns a [ReusableConfig][google.cloud.security.privateca.v1beta1.ReusableConfig]. @@ -2667,8 +2735,10 @@ async def sample_get_reusable_config(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.types.ReusableConfig: @@ -2732,7 +2802,7 @@ async def list_reusable_configs( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListReusableConfigsAsyncPager: r"""Lists [ReusableConfigs][google.cloud.security.privateca.v1beta1.ReusableConfig]. @@ -2780,8 +2850,10 @@ async def sample_list_reusable_configs(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.services.certificate_authority_service.pagers.ListReusableConfigsAsyncPager: diff --git a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/client.py b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/client.py index 350a0a483250..51f06dda205b 100644 --- a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/client.py +++ b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.protobuf import duration_pb2 # type: ignore @@ -671,6 +681,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -739,6 +753,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient`.", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "credentialsType": None, + }, + ) + def create_certificate( self, request: Optional[Union[service.CreateCertificateRequest, dict]] = None, @@ -748,7 +785,7 @@ def create_certificate( certificate_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Create a new [Certificate][google.cloud.security.privateca.v1beta1.Certificate] @@ -823,8 +860,10 @@ def sample_create_certificate(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.types.Certificate: @@ -886,7 +925,7 @@ def get_certificate( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Returns a [Certificate][google.cloud.security.privateca.v1beta1.Certificate]. @@ -934,8 +973,10 @@ def sample_get_certificate(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.types.Certificate: @@ -993,7 +1034,7 @@ def list_certificates( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListCertificatesPager: r"""Lists [Certificates][google.cloud.security.privateca.v1beta1.Certificate]. @@ -1042,8 +1083,10 @@ def sample_list_certificates(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.services.certificate_authority_service.pagers.ListCertificatesPager: @@ -1115,7 +1158,7 @@ def revoke_certificate( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Revoke a [Certificate][google.cloud.security.privateca.v1beta1.Certificate]. @@ -1163,8 +1206,10 @@ def sample_revoke_certificate(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.types.Certificate: @@ -1223,7 +1268,7 @@ def update_certificate( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Update a [Certificate][google.cloud.security.privateca.v1beta1.Certificate]. @@ -1282,8 +1327,10 @@ def sample_update_certificate(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.types.Certificate: @@ -1347,7 +1394,7 @@ def activate_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Activate a [CertificateAuthority][google.cloud.security.privateca.v1beta1.CertificateAuthority] @@ -1411,8 +1458,10 @@ def sample_activate_certificate_authority(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1489,7 +1538,7 @@ def create_certificate_authority( certificate_authority_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Create a new [CertificateAuthority][google.cloud.security.privateca.v1beta1.CertificateAuthority] @@ -1564,8 +1613,10 @@ def sample_create_certificate_authority(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1646,7 +1697,7 @@ def disable_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Disable a [CertificateAuthority][google.cloud.security.privateca.v1beta1.CertificateAuthority]. @@ -1697,8 +1748,10 @@ def sample_disable_certificate_authority(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1773,7 +1826,7 @@ def enable_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Enable a [CertificateAuthority][google.cloud.security.privateca.v1beta1.CertificateAuthority]. @@ -1824,8 +1877,10 @@ def sample_enable_certificate_authority(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1900,7 +1955,7 @@ def fetch_certificate_authority_csr( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> service.FetchCertificateAuthorityCsrResponse: r"""Fetch a certificate signing request (CSR) from a [CertificateAuthority][google.cloud.security.privateca.v1beta1.CertificateAuthority] @@ -1956,8 +2011,10 @@ def sample_fetch_certificate_authority_csr(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.types.FetchCertificateAuthorityCsrResponse: @@ -2017,7 +2074,7 @@ def get_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.CertificateAuthority: r"""Returns a [CertificateAuthority][google.cloud.security.privateca.v1beta1.CertificateAuthority]. @@ -2065,8 +2122,10 @@ def sample_get_certificate_authority(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.types.CertificateAuthority: @@ -2131,7 +2190,7 @@ def list_certificate_authorities( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListCertificateAuthoritiesPager: r"""Lists [CertificateAuthorities][google.cloud.security.privateca.v1beta1.CertificateAuthority]. @@ -2179,8 +2238,10 @@ def sample_list_certificate_authorities(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.services.certificate_authority_service.pagers.ListCertificateAuthoritiesPager: @@ -2256,7 +2317,7 @@ def restore_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Restore a [CertificateAuthority][google.cloud.security.privateca.v1beta1.CertificateAuthority] @@ -2308,8 +2369,10 @@ def sample_restore_certificate_authority(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -2384,7 +2447,7 @@ def schedule_delete_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Schedule a [CertificateAuthority][google.cloud.security.privateca.v1beta1.CertificateAuthority] @@ -2436,8 +2499,10 @@ def sample_schedule_delete_certificate_authority(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -2513,7 +2578,7 @@ def update_certificate_authority( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Update a [CertificateAuthority][google.cloud.security.privateca.v1beta1.CertificateAuthority]. @@ -2576,8 +2641,10 @@ def sample_update_certificate_authority(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -2656,7 +2723,7 @@ def get_certificate_revocation_list( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.CertificateRevocationList: r"""Returns a [CertificateRevocationList][google.cloud.security.privateca.v1beta1.CertificateRevocationList]. @@ -2704,8 +2771,10 @@ def sample_get_certificate_revocation_list(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.types.CertificateRevocationList: @@ -2769,7 +2838,7 @@ def list_certificate_revocation_lists( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListCertificateRevocationListsPager: r"""Lists [CertificateRevocationLists][google.cloud.security.privateca.v1beta1.CertificateRevocationList]. @@ -2818,8 +2887,10 @@ def sample_list_certificate_revocation_lists(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.services.certificate_authority_service.pagers.ListCertificateRevocationListsPager: @@ -2898,7 +2969,7 @@ def update_certificate_revocation_list( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Update a [CertificateRevocationList][google.cloud.security.privateca.v1beta1.CertificateRevocationList]. @@ -2954,8 +3025,10 @@ def sample_update_certificate_revocation_list(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -3036,7 +3109,7 @@ def get_reusable_config( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.ReusableConfig: r"""Returns a [ReusableConfig][google.cloud.security.privateca.v1beta1.ReusableConfig]. @@ -3081,8 +3154,10 @@ def sample_get_reusable_config(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.types.ReusableConfig: @@ -3143,7 +3218,7 @@ def list_reusable_configs( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListReusableConfigsPager: r"""Lists [ReusableConfigs][google.cloud.security.privateca.v1beta1.ReusableConfig]. @@ -3191,8 +3266,10 @@ def sample_list_reusable_configs(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.privateca_v1beta1.services.certificate_authority_service.pagers.ListReusableConfigsPager: diff --git a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/pagers.py b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/pagers.py index 947ede3f61f1..b7bbb8284cd7 100644 --- a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/pagers.py +++ b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -81,8 +81,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = service.ListCertificatesRequest(request) @@ -141,7 +143,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -155,8 +157,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = service.ListCertificatesRequest(request) @@ -219,7 +223,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -233,8 +237,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = service.ListCertificateAuthoritiesRequest(request) @@ -293,7 +299,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -307,8 +313,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = service.ListCertificateAuthoritiesRequest(request) @@ -371,7 +379,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -385,8 +393,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = service.ListCertificateRevocationListsRequest(request) @@ -447,7 +457,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -461,8 +471,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = service.ListCertificateRevocationListsRequest(request) @@ -527,7 +539,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -541,8 +553,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = service.ListReusableConfigsRequest(request) @@ -601,7 +615,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -615,8 +629,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = service.ListReusableConfigsRequest(request) diff --git a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/transports/grpc.py b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/transports/grpc.py index 307cf82aff76..08e83a91c156 100644 --- a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/transports/grpc.py +++ b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -21,12 +24,90 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.security.privateca_v1beta1.types import resources, service from .base import DEFAULT_CLIENT_INFO, CertificateAuthorityServiceTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class CertificateAuthorityServiceGrpcTransport(CertificateAuthorityServiceTransport): """gRPC backend transport for CertificateAuthorityService. @@ -183,7 +264,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -247,7 +333,9 @@ def operations_client(self) -> operations_v1.OperationsClient: """ # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + self._operations_client = operations_v1.OperationsClient( + self._logged_channel + ) # Return the client from cache. return self._operations_client @@ -274,7 +362,7 @@ def create_certificate( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_certificate" not in self._stubs: - self._stubs["create_certificate"] = self.grpc_channel.unary_unary( + self._stubs["create_certificate"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/CreateCertificate", request_serializer=service.CreateCertificateRequest.serialize, response_deserializer=resources.Certificate.deserialize, @@ -301,7 +389,7 @@ def get_certificate( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_certificate" not in self._stubs: - self._stubs["get_certificate"] = self.grpc_channel.unary_unary( + self._stubs["get_certificate"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/GetCertificate", request_serializer=service.GetCertificateRequest.serialize, response_deserializer=resources.Certificate.deserialize, @@ -328,7 +416,7 @@ def list_certificates( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_certificates" not in self._stubs: - self._stubs["list_certificates"] = self.grpc_channel.unary_unary( + self._stubs["list_certificates"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/ListCertificates", request_serializer=service.ListCertificatesRequest.serialize, response_deserializer=service.ListCertificatesResponse.deserialize, @@ -355,7 +443,7 @@ def revoke_certificate( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "revoke_certificate" not in self._stubs: - self._stubs["revoke_certificate"] = self.grpc_channel.unary_unary( + self._stubs["revoke_certificate"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/RevokeCertificate", request_serializer=service.RevokeCertificateRequest.serialize, response_deserializer=resources.Certificate.deserialize, @@ -385,7 +473,7 @@ def update_certificate( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_certificate" not in self._stubs: - self._stubs["update_certificate"] = self.grpc_channel.unary_unary( + self._stubs["update_certificate"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/UpdateCertificate", request_serializer=service.UpdateCertificateRequest.serialize, response_deserializer=resources.Certificate.deserialize, @@ -424,7 +512,7 @@ def activate_certificate_authority( if "activate_certificate_authority" not in self._stubs: self._stubs[ "activate_certificate_authority" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/ActivateCertificateAuthority", request_serializer=service.ActivateCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -454,7 +542,9 @@ def create_certificate_authority( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_certificate_authority" not in self._stubs: - self._stubs["create_certificate_authority"] = self.grpc_channel.unary_unary( + self._stubs[ + "create_certificate_authority" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/CreateCertificateAuthority", request_serializer=service.CreateCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -485,7 +575,7 @@ def disable_certificate_authority( if "disable_certificate_authority" not in self._stubs: self._stubs[ "disable_certificate_authority" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/DisableCertificateAuthority", request_serializer=service.DisableCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -514,7 +604,9 @@ def enable_certificate_authority( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "enable_certificate_authority" not in self._stubs: - self._stubs["enable_certificate_authority"] = self.grpc_channel.unary_unary( + self._stubs[ + "enable_certificate_authority" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/EnableCertificateAuthority", request_serializer=service.EnableCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -556,7 +648,7 @@ def fetch_certificate_authority_csr( if "fetch_certificate_authority_csr" not in self._stubs: self._stubs[ "fetch_certificate_authority_csr" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/FetchCertificateAuthorityCsr", request_serializer=service.FetchCertificateAuthorityCsrRequest.serialize, response_deserializer=service.FetchCertificateAuthorityCsrResponse.deserialize, @@ -585,7 +677,7 @@ def get_certificate_authority( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_certificate_authority" not in self._stubs: - self._stubs["get_certificate_authority"] = self.grpc_channel.unary_unary( + self._stubs["get_certificate_authority"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/GetCertificateAuthority", request_serializer=service.GetCertificateAuthorityRequest.serialize, response_deserializer=resources.CertificateAuthority.deserialize, @@ -615,7 +707,9 @@ def list_certificate_authorities( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_certificate_authorities" not in self._stubs: - self._stubs["list_certificate_authorities"] = self.grpc_channel.unary_unary( + self._stubs[ + "list_certificate_authorities" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/ListCertificateAuthorities", request_serializer=service.ListCertificateAuthoritiesRequest.serialize, response_deserializer=service.ListCertificateAuthoritiesResponse.deserialize, @@ -647,7 +741,7 @@ def restore_certificate_authority( if "restore_certificate_authority" not in self._stubs: self._stubs[ "restore_certificate_authority" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/RestoreCertificateAuthority", request_serializer=service.RestoreCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -680,7 +774,7 @@ def schedule_delete_certificate_authority( if "schedule_delete_certificate_authority" not in self._stubs: self._stubs[ "schedule_delete_certificate_authority" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/ScheduleDeleteCertificateAuthority", request_serializer=service.ScheduleDeleteCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -709,7 +803,9 @@ def update_certificate_authority( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_certificate_authority" not in self._stubs: - self._stubs["update_certificate_authority"] = self.grpc_channel.unary_unary( + self._stubs[ + "update_certificate_authority" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/UpdateCertificateAuthority", request_serializer=service.UpdateCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -742,7 +838,7 @@ def get_certificate_revocation_list( if "get_certificate_revocation_list" not in self._stubs: self._stubs[ "get_certificate_revocation_list" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/GetCertificateRevocationList", request_serializer=service.GetCertificateRevocationListRequest.serialize, response_deserializer=resources.CertificateRevocationList.deserialize, @@ -775,7 +871,7 @@ def list_certificate_revocation_lists( if "list_certificate_revocation_lists" not in self._stubs: self._stubs[ "list_certificate_revocation_lists" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/ListCertificateRevocationLists", request_serializer=service.ListCertificateRevocationListsRequest.serialize, response_deserializer=service.ListCertificateRevocationListsResponse.deserialize, @@ -807,7 +903,7 @@ def update_certificate_revocation_list( if "update_certificate_revocation_list" not in self._stubs: self._stubs[ "update_certificate_revocation_list" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/UpdateCertificateRevocationList", request_serializer=service.UpdateCertificateRevocationListRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -834,7 +930,7 @@ def get_reusable_config( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_reusable_config" not in self._stubs: - self._stubs["get_reusable_config"] = self.grpc_channel.unary_unary( + self._stubs["get_reusable_config"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/GetReusableConfig", request_serializer=service.GetReusableConfigRequest.serialize, response_deserializer=resources.ReusableConfig.deserialize, @@ -863,7 +959,7 @@ def list_reusable_configs( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_reusable_configs" not in self._stubs: - self._stubs["list_reusable_configs"] = self.grpc_channel.unary_unary( + self._stubs["list_reusable_configs"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/ListReusableConfigs", request_serializer=service.ListReusableConfigsRequest.serialize, response_deserializer=service.ListReusableConfigsResponse.deserialize, @@ -871,7 +967,7 @@ def list_reusable_configs( return self._stubs["list_reusable_configs"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/transports/grpc_asyncio.py b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/transports/grpc_asyncio.py index 2f04d947c6b0..d27586c7c883 100644 --- a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -23,14 +26,93 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.security.privateca_v1beta1.types import resources, service from .base import DEFAULT_CLIENT_INFO, CertificateAuthorityServiceTransport from .grpc import CertificateAuthorityServiceGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class CertificateAuthorityServiceGrpcAsyncIOTransport( CertificateAuthorityServiceTransport @@ -232,10 +314,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -258,7 +343,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel + self._logged_channel ) # Return the client from cache. @@ -286,7 +371,7 @@ def create_certificate( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_certificate" not in self._stubs: - self._stubs["create_certificate"] = self.grpc_channel.unary_unary( + self._stubs["create_certificate"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/CreateCertificate", request_serializer=service.CreateCertificateRequest.serialize, response_deserializer=resources.Certificate.deserialize, @@ -313,7 +398,7 @@ def get_certificate( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_certificate" not in self._stubs: - self._stubs["get_certificate"] = self.grpc_channel.unary_unary( + self._stubs["get_certificate"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/GetCertificate", request_serializer=service.GetCertificateRequest.serialize, response_deserializer=resources.Certificate.deserialize, @@ -342,7 +427,7 @@ def list_certificates( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_certificates" not in self._stubs: - self._stubs["list_certificates"] = self.grpc_channel.unary_unary( + self._stubs["list_certificates"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/ListCertificates", request_serializer=service.ListCertificatesRequest.serialize, response_deserializer=service.ListCertificatesResponse.deserialize, @@ -369,7 +454,7 @@ def revoke_certificate( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "revoke_certificate" not in self._stubs: - self._stubs["revoke_certificate"] = self.grpc_channel.unary_unary( + self._stubs["revoke_certificate"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/RevokeCertificate", request_serializer=service.RevokeCertificateRequest.serialize, response_deserializer=resources.Certificate.deserialize, @@ -399,7 +484,7 @@ def update_certificate( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_certificate" not in self._stubs: - self._stubs["update_certificate"] = self.grpc_channel.unary_unary( + self._stubs["update_certificate"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/UpdateCertificate", request_serializer=service.UpdateCertificateRequest.serialize, response_deserializer=resources.Certificate.deserialize, @@ -439,7 +524,7 @@ def activate_certificate_authority( if "activate_certificate_authority" not in self._stubs: self._stubs[ "activate_certificate_authority" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/ActivateCertificateAuthority", request_serializer=service.ActivateCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -469,7 +554,9 @@ def create_certificate_authority( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_certificate_authority" not in self._stubs: - self._stubs["create_certificate_authority"] = self.grpc_channel.unary_unary( + self._stubs[ + "create_certificate_authority" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/CreateCertificateAuthority", request_serializer=service.CreateCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -501,7 +588,7 @@ def disable_certificate_authority( if "disable_certificate_authority" not in self._stubs: self._stubs[ "disable_certificate_authority" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/DisableCertificateAuthority", request_serializer=service.DisableCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -530,7 +617,9 @@ def enable_certificate_authority( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "enable_certificate_authority" not in self._stubs: - self._stubs["enable_certificate_authority"] = self.grpc_channel.unary_unary( + self._stubs[ + "enable_certificate_authority" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/EnableCertificateAuthority", request_serializer=service.EnableCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -572,7 +661,7 @@ def fetch_certificate_authority_csr( if "fetch_certificate_authority_csr" not in self._stubs: self._stubs[ "fetch_certificate_authority_csr" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/FetchCertificateAuthorityCsr", request_serializer=service.FetchCertificateAuthorityCsrRequest.serialize, response_deserializer=service.FetchCertificateAuthorityCsrResponse.deserialize, @@ -602,7 +691,7 @@ def get_certificate_authority( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_certificate_authority" not in self._stubs: - self._stubs["get_certificate_authority"] = self.grpc_channel.unary_unary( + self._stubs["get_certificate_authority"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/GetCertificateAuthority", request_serializer=service.GetCertificateAuthorityRequest.serialize, response_deserializer=resources.CertificateAuthority.deserialize, @@ -632,7 +721,9 @@ def list_certificate_authorities( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_certificate_authorities" not in self._stubs: - self._stubs["list_certificate_authorities"] = self.grpc_channel.unary_unary( + self._stubs[ + "list_certificate_authorities" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/ListCertificateAuthorities", request_serializer=service.ListCertificateAuthoritiesRequest.serialize, response_deserializer=service.ListCertificateAuthoritiesResponse.deserialize, @@ -665,7 +756,7 @@ def restore_certificate_authority( if "restore_certificate_authority" not in self._stubs: self._stubs[ "restore_certificate_authority" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/RestoreCertificateAuthority", request_serializer=service.RestoreCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -699,7 +790,7 @@ def schedule_delete_certificate_authority( if "schedule_delete_certificate_authority" not in self._stubs: self._stubs[ "schedule_delete_certificate_authority" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/ScheduleDeleteCertificateAuthority", request_serializer=service.ScheduleDeleteCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -728,7 +819,9 @@ def update_certificate_authority( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_certificate_authority" not in self._stubs: - self._stubs["update_certificate_authority"] = self.grpc_channel.unary_unary( + self._stubs[ + "update_certificate_authority" + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/UpdateCertificateAuthority", request_serializer=service.UpdateCertificateAuthorityRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -761,7 +854,7 @@ def get_certificate_revocation_list( if "get_certificate_revocation_list" not in self._stubs: self._stubs[ "get_certificate_revocation_list" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/GetCertificateRevocationList", request_serializer=service.GetCertificateRevocationListRequest.serialize, response_deserializer=resources.CertificateRevocationList.deserialize, @@ -794,7 +887,7 @@ def list_certificate_revocation_lists( if "list_certificate_revocation_lists" not in self._stubs: self._stubs[ "list_certificate_revocation_lists" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/ListCertificateRevocationLists", request_serializer=service.ListCertificateRevocationListsRequest.serialize, response_deserializer=service.ListCertificateRevocationListsResponse.deserialize, @@ -827,7 +920,7 @@ def update_certificate_revocation_list( if "update_certificate_revocation_list" not in self._stubs: self._stubs[ "update_certificate_revocation_list" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/UpdateCertificateRevocationList", request_serializer=service.UpdateCertificateRevocationListRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -856,7 +949,7 @@ def get_reusable_config( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_reusable_config" not in self._stubs: - self._stubs["get_reusable_config"] = self.grpc_channel.unary_unary( + self._stubs["get_reusable_config"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/GetReusableConfig", request_serializer=service.GetReusableConfigRequest.serialize, response_deserializer=resources.ReusableConfig.deserialize, @@ -886,7 +979,7 @@ def list_reusable_configs( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_reusable_configs" not in self._stubs: - self._stubs["list_reusable_configs"] = self.grpc_channel.unary_unary( + self._stubs["list_reusable_configs"] = self._logged_channel.unary_unary( "/google.cloud.security.privateca.v1beta1.CertificateAuthorityService/ListReusableConfigs", request_serializer=service.ListReusableConfigsRequest.serialize, response_deserializer=service.ListReusableConfigsResponse.deserialize, @@ -1004,7 +1097,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/transports/rest.py b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/transports/rest.py index e73d9027b4f4..3c171c10269a 100644 --- a/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/transports/rest.py +++ b/packages/google-cloud-private-ca/google/cloud/security/privateca_v1beta1/services/certificate_authority_service/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -38,6 +38,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -230,8 +238,11 @@ def post_update_certificate_revocation_list(self, response): def pre_activate_certificate_authority( self, request: service.ActivateCertificateAuthorityRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.ActivateCertificateAuthorityRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.ActivateCertificateAuthorityRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for activate_certificate_authority Override in a subclass to manipulate the request or metadata @@ -253,8 +264,10 @@ def post_activate_certificate_authority( def pre_create_certificate( self, request: service.CreateCertificateRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.CreateCertificateRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.CreateCertificateRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for create_certificate Override in a subclass to manipulate the request or metadata @@ -276,8 +289,11 @@ def post_create_certificate( def pre_create_certificate_authority( self, request: service.CreateCertificateAuthorityRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.CreateCertificateAuthorityRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.CreateCertificateAuthorityRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for create_certificate_authority Override in a subclass to manipulate the request or metadata @@ -299,8 +315,11 @@ def post_create_certificate_authority( def pre_disable_certificate_authority( self, request: service.DisableCertificateAuthorityRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.DisableCertificateAuthorityRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.DisableCertificateAuthorityRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for disable_certificate_authority Override in a subclass to manipulate the request or metadata @@ -322,8 +341,11 @@ def post_disable_certificate_authority( def pre_enable_certificate_authority( self, request: service.EnableCertificateAuthorityRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.EnableCertificateAuthorityRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.EnableCertificateAuthorityRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for enable_certificate_authority Override in a subclass to manipulate the request or metadata @@ -345,8 +367,11 @@ def post_enable_certificate_authority( def pre_fetch_certificate_authority_csr( self, request: service.FetchCertificateAuthorityCsrRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.FetchCertificateAuthorityCsrRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.FetchCertificateAuthorityCsrRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for fetch_certificate_authority_csr Override in a subclass to manipulate the request or metadata @@ -368,8 +393,8 @@ def post_fetch_certificate_authority_csr( def pre_get_certificate( self, request: service.GetCertificateRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.GetCertificateRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[service.GetCertificateRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for get_certificate Override in a subclass to manipulate the request or metadata @@ -391,8 +416,10 @@ def post_get_certificate( def pre_get_certificate_authority( self, request: service.GetCertificateAuthorityRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.GetCertificateAuthorityRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.GetCertificateAuthorityRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_certificate_authority Override in a subclass to manipulate the request or metadata @@ -414,8 +441,11 @@ def post_get_certificate_authority( def pre_get_certificate_revocation_list( self, request: service.GetCertificateRevocationListRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.GetCertificateRevocationListRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.GetCertificateRevocationListRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for get_certificate_revocation_list Override in a subclass to manipulate the request or metadata @@ -437,8 +467,10 @@ def post_get_certificate_revocation_list( def pre_get_reusable_config( self, request: service.GetReusableConfigRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.GetReusableConfigRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.GetReusableConfigRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_reusable_config Override in a subclass to manipulate the request or metadata @@ -460,8 +492,11 @@ def post_get_reusable_config( def pre_list_certificate_authorities( self, request: service.ListCertificateAuthoritiesRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.ListCertificateAuthoritiesRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.ListCertificateAuthoritiesRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for list_certificate_authorities Override in a subclass to manipulate the request or metadata @@ -483,9 +518,10 @@ def post_list_certificate_authorities( def pre_list_certificate_revocation_lists( self, request: service.ListCertificateRevocationListsRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - service.ListCertificateRevocationListsRequest, Sequence[Tuple[str, str]] + service.ListCertificateRevocationListsRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for list_certificate_revocation_lists @@ -508,8 +544,10 @@ def post_list_certificate_revocation_lists( def pre_list_certificates( self, request: service.ListCertificatesRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.ListCertificatesRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.ListCertificatesRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_certificates Override in a subclass to manipulate the request or metadata @@ -531,8 +569,10 @@ def post_list_certificates( def pre_list_reusable_configs( self, request: service.ListReusableConfigsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.ListReusableConfigsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.ListReusableConfigsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_reusable_configs Override in a subclass to manipulate the request or metadata @@ -554,8 +594,11 @@ def post_list_reusable_configs( def pre_restore_certificate_authority( self, request: service.RestoreCertificateAuthorityRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.RestoreCertificateAuthorityRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.RestoreCertificateAuthorityRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for restore_certificate_authority Override in a subclass to manipulate the request or metadata @@ -577,8 +620,10 @@ def post_restore_certificate_authority( def pre_revoke_certificate( self, request: service.RevokeCertificateRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.RevokeCertificateRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.RevokeCertificateRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for revoke_certificate Override in a subclass to manipulate the request or metadata @@ -600,9 +645,10 @@ def post_revoke_certificate( def pre_schedule_delete_certificate_authority( self, request: service.ScheduleDeleteCertificateAuthorityRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - service.ScheduleDeleteCertificateAuthorityRequest, Sequence[Tuple[str, str]] + service.ScheduleDeleteCertificateAuthorityRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for schedule_delete_certificate_authority @@ -625,8 +671,10 @@ def post_schedule_delete_certificate_authority( def pre_update_certificate( self, request: service.UpdateCertificateRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.UpdateCertificateRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.UpdateCertificateRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for update_certificate Override in a subclass to manipulate the request or metadata @@ -648,8 +696,11 @@ def post_update_certificate( def pre_update_certificate_authority( self, request: service.UpdateCertificateAuthorityRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.UpdateCertificateAuthorityRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.UpdateCertificateAuthorityRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for update_certificate_authority Override in a subclass to manipulate the request or metadata @@ -671,9 +722,10 @@ def post_update_certificate_authority( def pre_update_certificate_revocation_list( self, request: service.UpdateCertificateRevocationListRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - service.UpdateCertificateRevocationListRequest, Sequence[Tuple[str, str]] + service.UpdateCertificateRevocationListRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for update_certificate_revocation_list @@ -876,7 +928,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the activate certificate authority method over HTTP. @@ -888,8 +940,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -902,6 +956,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseActivateCertificateAuthority._get_http_options() ) + request, metadata = self._interceptor.pre_activate_certificate_authority( request, metadata ) @@ -918,6 +973,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.ActivateCertificateAuthority", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "ActivateCertificateAuthority", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._ActivateCertificateAuthority._get_response( self._host, @@ -937,7 +1019,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_activate_certificate_authority(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.activate_certificate_authority", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "ActivateCertificateAuthority", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _CreateCertificate( @@ -976,7 +1080,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Call the create certificate method over HTTP. @@ -987,8 +1091,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resources.Certificate: @@ -1002,6 +1108,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseCreateCertificate._get_http_options() ) + request, metadata = self._interceptor.pre_create_certificate( request, metadata ) @@ -1018,6 +1125,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.CreateCertificate", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "CreateCertificate", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._CreateCertificate._get_response( self._host, @@ -1039,7 +1173,29 @@ def __call__( pb_resp = resources.Certificate.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_certificate(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resources.Certificate.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.create_certificate", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "CreateCertificate", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _CreateCertificateAuthority( @@ -1080,7 +1236,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the create certificate authority method over HTTP. @@ -1092,8 +1248,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1106,6 +1264,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseCreateCertificateAuthority._get_http_options() ) + request, metadata = self._interceptor.pre_create_certificate_authority( request, metadata ) @@ -1122,6 +1281,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.CreateCertificateAuthority", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "CreateCertificateAuthority", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._CreateCertificateAuthority._get_response( self._host, @@ -1141,7 +1327,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_certificate_authority(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.create_certificate_authority", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "CreateCertificateAuthority", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DisableCertificateAuthority( @@ -1182,7 +1390,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the disable certificate authority method over HTTP. @@ -1194,8 +1402,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1208,6 +1418,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseDisableCertificateAuthority._get_http_options() ) + request, metadata = self._interceptor.pre_disable_certificate_authority( request, metadata ) @@ -1224,6 +1435,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.DisableCertificateAuthority", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "DisableCertificateAuthority", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._DisableCertificateAuthority._get_response( self._host, @@ -1243,7 +1481,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_disable_certificate_authority(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.disable_certificate_authority", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "DisableCertificateAuthority", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _EnableCertificateAuthority( @@ -1284,7 +1544,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the enable certificate authority method over HTTP. @@ -1296,8 +1556,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1310,6 +1572,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseEnableCertificateAuthority._get_http_options() ) + request, metadata = self._interceptor.pre_enable_certificate_authority( request, metadata ) @@ -1326,6 +1589,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.EnableCertificateAuthority", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "EnableCertificateAuthority", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._EnableCertificateAuthority._get_response( self._host, @@ -1345,7 +1635,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_enable_certificate_authority(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.enable_certificate_authority", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "EnableCertificateAuthority", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _FetchCertificateAuthorityCsr( @@ -1385,7 +1697,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> service.FetchCertificateAuthorityCsrResponse: r"""Call the fetch certificate authority csr method over HTTP. @@ -1397,8 +1709,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.service.FetchCertificateAuthorityCsrResponse: @@ -1410,6 +1724,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseFetchCertificateAuthorityCsr._get_http_options() ) + request, metadata = self._interceptor.pre_fetch_certificate_authority_csr( request, metadata ) @@ -1422,6 +1737,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.FetchCertificateAuthorityCsr", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "FetchCertificateAuthorityCsr", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._FetchCertificateAuthorityCsr._get_response( self._host, @@ -1442,7 +1784,31 @@ def __call__( pb_resp = service.FetchCertificateAuthorityCsrResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_fetch_certificate_authority_csr(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + service.FetchCertificateAuthorityCsrResponse.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.fetch_certificate_authority_csr", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "FetchCertificateAuthorityCsr", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetCertificate( @@ -1480,7 +1846,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Call the get certificate method over HTTP. @@ -1491,8 +1857,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resources.Certificate: @@ -1506,6 +1874,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseGetCertificate._get_http_options() ) + request, metadata = self._interceptor.pre_get_certificate(request, metadata) transcoded_request = _BaseCertificateAuthorityServiceRestTransport._BaseGetCertificate._get_transcoded_request( http_options, request @@ -1516,6 +1885,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.GetCertificate", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "GetCertificate", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( CertificateAuthorityServiceRestTransport._GetCertificate._get_response( @@ -1538,7 +1934,29 @@ def __call__( pb_resp = resources.Certificate.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_certificate(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resources.Certificate.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.get_certificate", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "GetCertificate", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetCertificateAuthority( @@ -1578,7 +1996,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.CertificateAuthority: r"""Call the get certificate authority method over HTTP. @@ -1589,8 +2007,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resources.CertificateAuthority: @@ -1606,6 +2026,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseGetCertificateAuthority._get_http_options() ) + request, metadata = self._interceptor.pre_get_certificate_authority( request, metadata ) @@ -1618,6 +2039,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.GetCertificateAuthority", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "GetCertificateAuthority", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._GetCertificateAuthority._get_response( self._host, @@ -1638,7 +2086,29 @@ def __call__( pb_resp = resources.CertificateAuthority.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_certificate_authority(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resources.CertificateAuthority.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.get_certificate_authority", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "GetCertificateAuthority", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetCertificateRevocationList( @@ -1678,7 +2148,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.CertificateRevocationList: r"""Call the get certificate revocation list method over HTTP. @@ -1690,8 +2160,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resources.CertificateRevocationList: @@ -1706,6 +2178,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseGetCertificateRevocationList._get_http_options() ) + request, metadata = self._interceptor.pre_get_certificate_revocation_list( request, metadata ) @@ -1718,6 +2191,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.GetCertificateRevocationList", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "GetCertificateRevocationList", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._GetCertificateRevocationList._get_response( self._host, @@ -1738,7 +2238,31 @@ def __call__( pb_resp = resources.CertificateRevocationList.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_certificate_revocation_list(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resources.CertificateRevocationList.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.get_certificate_revocation_list", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "GetCertificateRevocationList", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetReusableConfig( @@ -1776,7 +2300,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.ReusableConfig: r"""Call the get reusable config method over HTTP. @@ -1787,8 +2311,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resources.ReusableConfig: @@ -1806,6 +2332,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseGetReusableConfig._get_http_options() ) + request, metadata = self._interceptor.pre_get_reusable_config( request, metadata ) @@ -1818,6 +2345,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.GetReusableConfig", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "GetReusableConfig", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._GetReusableConfig._get_response( self._host, @@ -1838,7 +2392,29 @@ def __call__( pb_resp = resources.ReusableConfig.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_reusable_config(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resources.ReusableConfig.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.get_reusable_config", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "GetReusableConfig", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListCertificateAuthorities( @@ -1878,7 +2454,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> service.ListCertificateAuthoritiesResponse: r"""Call the list certificate authorities method over HTTP. @@ -1890,8 +2466,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.service.ListCertificateAuthoritiesResponse: @@ -1903,6 +2481,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseListCertificateAuthorities._get_http_options() ) + request, metadata = self._interceptor.pre_list_certificate_authorities( request, metadata ) @@ -1915,6 +2494,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.ListCertificateAuthorities", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "ListCertificateAuthorities", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._ListCertificateAuthorities._get_response( self._host, @@ -1935,7 +2541,31 @@ def __call__( pb_resp = service.ListCertificateAuthoritiesResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_certificate_authorities(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + service.ListCertificateAuthoritiesResponse.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.list_certificate_authorities", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "ListCertificateAuthorities", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListCertificateRevocationLists( @@ -1975,7 +2605,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> service.ListCertificateRevocationListsResponse: r"""Call the list certificate revocation lists method over HTTP. @@ -1987,8 +2617,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.service.ListCertificateRevocationListsResponse: @@ -2000,6 +2632,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseListCertificateRevocationLists._get_http_options() ) + request, metadata = self._interceptor.pre_list_certificate_revocation_lists( request, metadata ) @@ -2012,6 +2645,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.ListCertificateRevocationLists", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "ListCertificateRevocationLists", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._ListCertificateRevocationLists._get_response( self._host, @@ -2032,7 +2692,31 @@ def __call__( pb_resp = service.ListCertificateRevocationListsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_certificate_revocation_lists(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + service.ListCertificateRevocationListsResponse.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.list_certificate_revocation_lists", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "ListCertificateRevocationLists", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListCertificates( @@ -2070,7 +2754,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> service.ListCertificatesResponse: r"""Call the list certificates method over HTTP. @@ -2081,8 +2765,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.service.ListCertificatesResponse: @@ -2094,6 +2780,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseListCertificates._get_http_options() ) + request, metadata = self._interceptor.pre_list_certificates( request, metadata ) @@ -2106,6 +2793,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.ListCertificates", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "ListCertificates", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._ListCertificates._get_response( self._host, @@ -2126,7 +2840,31 @@ def __call__( pb_resp = service.ListCertificatesResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_certificates(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = service.ListCertificatesResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.list_certificates", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "ListCertificates", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListReusableConfigs( @@ -2164,7 +2902,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> service.ListReusableConfigsResponse: r"""Call the list reusable configs method over HTTP. @@ -2175,8 +2913,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.service.ListReusableConfigsResponse: @@ -2188,6 +2928,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseListReusableConfigs._get_http_options() ) + request, metadata = self._interceptor.pre_list_reusable_configs( request, metadata ) @@ -2200,6 +2941,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.ListReusableConfigs", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "ListReusableConfigs", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._ListReusableConfigs._get_response( self._host, @@ -2220,7 +2988,31 @@ def __call__( pb_resp = service.ListReusableConfigsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_reusable_configs(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = service.ListReusableConfigsResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.list_reusable_configs", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "ListReusableConfigs", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _RestoreCertificateAuthority( @@ -2261,7 +3053,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the restore certificate authority method over HTTP. @@ -2273,8 +3065,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -2287,6 +3081,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseRestoreCertificateAuthority._get_http_options() ) + request, metadata = self._interceptor.pre_restore_certificate_authority( request, metadata ) @@ -2303,6 +3098,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.RestoreCertificateAuthority", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "RestoreCertificateAuthority", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._RestoreCertificateAuthority._get_response( self._host, @@ -2322,7 +3144,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_restore_certificate_authority(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.restore_certificate_authority", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "RestoreCertificateAuthority", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _RevokeCertificate( @@ -2361,7 +3205,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Call the revoke certificate method over HTTP. @@ -2372,8 +3216,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resources.Certificate: @@ -2387,6 +3233,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseRevokeCertificate._get_http_options() ) + request, metadata = self._interceptor.pre_revoke_certificate( request, metadata ) @@ -2403,6 +3250,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.RevokeCertificate", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "RevokeCertificate", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._RevokeCertificate._get_response( self._host, @@ -2424,7 +3298,29 @@ def __call__( pb_resp = resources.Certificate.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_revoke_certificate(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resources.Certificate.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.revoke_certificate", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "RevokeCertificate", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ScheduleDeleteCertificateAuthority( @@ -2465,7 +3361,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the schedule delete certificate authority method over HTTP. @@ -2477,8 +3373,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -2491,6 +3389,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseScheduleDeleteCertificateAuthority._get_http_options() ) + ( request, metadata, @@ -2510,6 +3409,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.ScheduleDeleteCertificateAuthority", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "ScheduleDeleteCertificateAuthority", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._ScheduleDeleteCertificateAuthority._get_response( self._host, @@ -2529,7 +3455,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_schedule_delete_certificate_authority(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.schedule_delete_certificate_authority", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "ScheduleDeleteCertificateAuthority", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateCertificate( @@ -2568,7 +3516,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.Certificate: r"""Call the update certificate method over HTTP. @@ -2579,8 +3527,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resources.Certificate: @@ -2594,6 +3544,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseUpdateCertificate._get_http_options() ) + request, metadata = self._interceptor.pre_update_certificate( request, metadata ) @@ -2610,6 +3561,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.UpdateCertificate", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "UpdateCertificate", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._UpdateCertificate._get_response( self._host, @@ -2631,7 +3609,29 @@ def __call__( pb_resp = resources.Certificate.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_certificate(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resources.Certificate.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.update_certificate", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "UpdateCertificate", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateCertificateAuthority( @@ -2672,7 +3672,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the update certificate authority method over HTTP. @@ -2684,8 +3684,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -2698,6 +3700,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseUpdateCertificateAuthority._get_http_options() ) + request, metadata = self._interceptor.pre_update_certificate_authority( request, metadata ) @@ -2714,6 +3717,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.UpdateCertificateAuthority", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "UpdateCertificateAuthority", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._UpdateCertificateAuthority._get_response( self._host, @@ -2733,7 +3763,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_certificate_authority(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.update_certificate_authority", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "UpdateCertificateAuthority", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateCertificateRevocationList( @@ -2774,7 +3826,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the update certificate revocation list method over HTTP. @@ -2786,8 +3838,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -2800,6 +3854,7 @@ def __call__( http_options = ( _BaseCertificateAuthorityServiceRestTransport._BaseUpdateCertificateRevocationList._get_http_options() ) + ( request, metadata, @@ -2819,6 +3874,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.UpdateCertificateRevocationList", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "UpdateCertificateRevocationList", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CertificateAuthorityServiceRestTransport._UpdateCertificateRevocationList._get_response( self._host, @@ -2838,7 +3920,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_certificate_revocation_list(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.privateca_v1beta1.CertificateAuthorityServiceClient.update_certificate_revocation_list", + extra={ + "serviceName": "google.cloud.security.privateca.v1beta1.CertificateAuthorityService", + "rpcName": "UpdateCertificateRevocationList", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property diff --git a/packages/google-cloud-private-ca/samples/generated_samples/snippet_metadata_google.cloud.security.privateca.v1.json b/packages/google-cloud-private-ca/samples/generated_samples/snippet_metadata_google.cloud.security.privateca.v1.json index 3f935dd6299b..ca2ab4a8547d 100644 --- a/packages/google-cloud-private-ca/samples/generated_samples/snippet_metadata_google.cloud.security.privateca.v1.json +++ b/packages/google-cloud-private-ca/samples/generated_samples/snippet_metadata_google.cloud.security.privateca.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-private-ca", - "version": "1.13.1" + "version": "0.1.0" }, "snippets": [ { @@ -47,7 +47,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -127,7 +127,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -216,7 +216,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -304,7 +304,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -393,7 +393,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -481,7 +481,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -570,7 +570,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -658,7 +658,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -747,7 +747,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.types.Certificate", @@ -835,7 +835,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.types.Certificate", @@ -916,7 +916,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -996,7 +996,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -1077,7 +1077,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -1157,7 +1157,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -1238,7 +1238,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -1318,7 +1318,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -1399,7 +1399,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -1479,7 +1479,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -1560,7 +1560,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -1640,7 +1640,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -1721,7 +1721,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.types.FetchCaCertsResponse", @@ -1801,7 +1801,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.types.FetchCaCertsResponse", @@ -1882,7 +1882,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.types.FetchCertificateAuthorityCsrResponse", @@ -1962,7 +1962,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.types.FetchCertificateAuthorityCsrResponse", @@ -2043,7 +2043,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.types.CaPool", @@ -2123,7 +2123,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.types.CaPool", @@ -2204,7 +2204,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.types.CertificateAuthority", @@ -2284,7 +2284,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.types.CertificateAuthority", @@ -2365,7 +2365,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.types.CertificateRevocationList", @@ -2445,7 +2445,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.types.CertificateRevocationList", @@ -2526,7 +2526,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.types.CertificateTemplate", @@ -2606,7 +2606,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.types.CertificateTemplate", @@ -2687,7 +2687,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.types.Certificate", @@ -2767,7 +2767,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.types.Certificate", @@ -2848,7 +2848,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.services.certificate_authority_service.pagers.ListCaPoolsAsyncPager", @@ -2928,7 +2928,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.services.certificate_authority_service.pagers.ListCaPoolsPager", @@ -3009,7 +3009,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.services.certificate_authority_service.pagers.ListCertificateAuthoritiesAsyncPager", @@ -3089,7 +3089,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.services.certificate_authority_service.pagers.ListCertificateAuthoritiesPager", @@ -3170,7 +3170,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.services.certificate_authority_service.pagers.ListCertificateRevocationListsAsyncPager", @@ -3250,7 +3250,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.services.certificate_authority_service.pagers.ListCertificateRevocationListsPager", @@ -3331,7 +3331,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.services.certificate_authority_service.pagers.ListCertificateTemplatesAsyncPager", @@ -3411,7 +3411,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.services.certificate_authority_service.pagers.ListCertificateTemplatesPager", @@ -3492,7 +3492,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.services.certificate_authority_service.pagers.ListCertificatesAsyncPager", @@ -3572,7 +3572,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.services.certificate_authority_service.pagers.ListCertificatesPager", @@ -3653,7 +3653,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.types.Certificate", @@ -3733,7 +3733,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.types.Certificate", @@ -3814,7 +3814,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -3894,7 +3894,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -3979,7 +3979,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -4063,7 +4063,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -4148,7 +4148,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -4232,7 +4232,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -4317,7 +4317,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -4401,7 +4401,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -4486,7 +4486,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -4570,7 +4570,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -4655,7 +4655,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.types.Certificate", @@ -4739,7 +4739,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1.types.Certificate", diff --git a/packages/google-cloud-private-ca/samples/generated_samples/snippet_metadata_google.cloud.security.privateca.v1beta1.json b/packages/google-cloud-private-ca/samples/generated_samples/snippet_metadata_google.cloud.security.privateca.v1beta1.json index 649b113e1de2..a2c343c16a72 100644 --- a/packages/google-cloud-private-ca/samples/generated_samples/snippet_metadata_google.cloud.security.privateca.v1beta1.json +++ b/packages/google-cloud-private-ca/samples/generated_samples/snippet_metadata_google.cloud.security.privateca.v1beta1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-private-ca", - "version": "1.13.1" + "version": "0.1.0" }, "snippets": [ { @@ -47,7 +47,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -127,7 +127,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -216,7 +216,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -304,7 +304,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -393,7 +393,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.types.Certificate", @@ -481,7 +481,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.types.Certificate", @@ -562,7 +562,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -642,7 +642,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -723,7 +723,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -803,7 +803,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -884,7 +884,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.types.FetchCertificateAuthorityCsrResponse", @@ -964,7 +964,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.types.FetchCertificateAuthorityCsrResponse", @@ -1045,7 +1045,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.types.CertificateAuthority", @@ -1125,7 +1125,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.types.CertificateAuthority", @@ -1206,7 +1206,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.types.CertificateRevocationList", @@ -1286,7 +1286,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.types.CertificateRevocationList", @@ -1367,7 +1367,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.types.Certificate", @@ -1447,7 +1447,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.types.Certificate", @@ -1528,7 +1528,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.types.ReusableConfig", @@ -1608,7 +1608,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.types.ReusableConfig", @@ -1689,7 +1689,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.services.certificate_authority_service.pagers.ListCertificateAuthoritiesAsyncPager", @@ -1769,7 +1769,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.services.certificate_authority_service.pagers.ListCertificateAuthoritiesPager", @@ -1850,7 +1850,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.services.certificate_authority_service.pagers.ListCertificateRevocationListsAsyncPager", @@ -1930,7 +1930,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.services.certificate_authority_service.pagers.ListCertificateRevocationListsPager", @@ -2011,7 +2011,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.services.certificate_authority_service.pagers.ListCertificatesAsyncPager", @@ -2091,7 +2091,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.services.certificate_authority_service.pagers.ListCertificatesPager", @@ -2172,7 +2172,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.services.certificate_authority_service.pagers.ListReusableConfigsAsyncPager", @@ -2252,7 +2252,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.services.certificate_authority_service.pagers.ListReusableConfigsPager", @@ -2333,7 +2333,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -2413,7 +2413,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -2494,7 +2494,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.types.Certificate", @@ -2574,7 +2574,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.types.Certificate", @@ -2655,7 +2655,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -2735,7 +2735,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -2820,7 +2820,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -2904,7 +2904,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -2989,7 +2989,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -3073,7 +3073,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -3158,7 +3158,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.types.Certificate", @@ -3242,7 +3242,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.privateca_v1beta1.types.Certificate", diff --git a/packages/google-cloud-private-ca/tests/unit/gapic/privateca_v1/test_certificate_authority_service.py b/packages/google-cloud-private-ca/tests/unit/gapic/privateca_v1/test_certificate_authority_service.py index 4389336bf602..d0c66d880a29 100644 --- a/packages/google-cloud-private-ca/tests/unit/gapic/privateca_v1/test_certificate_authority_service.py +++ b/packages/google-cloud-private-ca/tests/unit/gapic/privateca_v1/test_certificate_authority_service.py @@ -12484,6 +12484,7 @@ def test_create_certificate_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_certificate(request) @@ -12548,6 +12549,7 @@ def test_create_certificate_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_certificate(**mock_args) @@ -12681,6 +12683,7 @@ def test_get_certificate_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_certificate(request) @@ -12728,6 +12731,7 @@ def test_get_certificate_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_certificate(**mock_args) @@ -12870,6 +12874,7 @@ def test_list_certificates_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_certificates(request) @@ -12927,6 +12932,7 @@ def test_list_certificates_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_certificates(**mock_args) @@ -13126,6 +13132,7 @@ def test_revoke_certificate_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.revoke_certificate(request) @@ -13181,6 +13188,7 @@ def test_revoke_certificate_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.revoke_certificate(**mock_args) @@ -13319,6 +13327,7 @@ def test_update_certificate_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_certificate(request) @@ -13382,6 +13391,7 @@ def test_update_certificate_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_certificate(**mock_args) @@ -13525,6 +13535,7 @@ def test_activate_certificate_authority_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.activate_certificate_authority(request) @@ -13581,6 +13592,7 @@ def test_activate_certificate_authority_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.activate_certificate_authority(**mock_args) @@ -13738,6 +13750,7 @@ def test_create_certificate_authority_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_certificate_authority(request) @@ -13805,6 +13818,7 @@ def test_create_certificate_authority_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_certificate_authority(**mock_args) @@ -13945,6 +13959,7 @@ def test_disable_certificate_authority_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.disable_certificate_authority(request) @@ -13992,6 +14007,7 @@ def test_disable_certificate_authority_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.disable_certificate_authority(**mock_args) @@ -14130,6 +14146,7 @@ def test_enable_certificate_authority_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.enable_certificate_authority(request) @@ -14175,6 +14192,7 @@ def test_enable_certificate_authority_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.enable_certificate_authority(**mock_args) @@ -14311,6 +14329,7 @@ def test_fetch_certificate_authority_csr_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.fetch_certificate_authority_csr(request) @@ -14360,6 +14379,7 @@ def test_fetch_certificate_authority_csr_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.fetch_certificate_authority_csr(**mock_args) @@ -14496,6 +14516,7 @@ def test_get_certificate_authority_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_certificate_authority(request) @@ -14543,6 +14564,7 @@ def test_get_certificate_authority_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_certificate_authority(**mock_args) @@ -14688,6 +14710,7 @@ def test_list_certificate_authorities_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_certificate_authorities(request) @@ -14745,6 +14768,7 @@ def test_list_certificate_authorities_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_certificate_authorities(**mock_args) @@ -14948,6 +14972,7 @@ def test_undelete_certificate_authority_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.undelete_certificate_authority(request) @@ -14995,6 +15020,7 @@ def test_undelete_certificate_authority_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.undelete_certificate_authority(**mock_args) @@ -15141,6 +15167,7 @@ def test_delete_certificate_authority_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_certificate_authority(request) @@ -15196,6 +15223,7 @@ def test_delete_certificate_authority_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_certificate_authority(**mock_args) @@ -15336,6 +15364,7 @@ def test_update_certificate_authority_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_certificate_authority(request) @@ -15397,6 +15426,7 @@ def test_update_certificate_authority_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_certificate_authority(**mock_args) @@ -15543,6 +15573,7 @@ def test_create_ca_pool_rest_required_fields(request_type=service.CreateCaPoolRe response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_ca_pool(request) @@ -15608,6 +15639,7 @@ def test_create_ca_pool_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_ca_pool(**mock_args) @@ -15742,6 +15774,7 @@ def test_update_ca_pool_rest_required_fields(request_type=service.UpdateCaPoolRe response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_ca_pool(request) @@ -15801,6 +15834,7 @@ def test_update_ca_pool_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_ca_pool(**mock_args) @@ -15931,6 +15965,7 @@ def test_get_ca_pool_rest_required_fields(request_type=service.GetCaPoolRequest) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_ca_pool(request) @@ -15976,6 +16011,7 @@ def test_get_ca_pool_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_ca_pool(**mock_args) @@ -16113,6 +16149,7 @@ def test_list_ca_pools_rest_required_fields(request_type=service.ListCaPoolsRequ response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_ca_pools(request) @@ -16168,6 +16205,7 @@ def test_list_ca_pools_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_ca_pools(**mock_args) @@ -16365,6 +16403,7 @@ def test_delete_ca_pool_rest_required_fields(request_type=service.DeleteCaPoolRe response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_ca_pool(request) @@ -16416,6 +16455,7 @@ def test_delete_ca_pool_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_ca_pool(**mock_args) @@ -16545,6 +16585,7 @@ def test_fetch_ca_certs_rest_required_fields(request_type=service.FetchCaCertsRe response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.fetch_ca_certs(request) @@ -16592,6 +16633,7 @@ def test_fetch_ca_certs_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.fetch_ca_certs(**mock_args) @@ -16728,6 +16770,7 @@ def test_get_certificate_revocation_list_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_certificate_revocation_list(request) @@ -16777,6 +16820,7 @@ def test_get_certificate_revocation_list_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_certificate_revocation_list(**mock_args) @@ -16924,6 +16968,7 @@ def test_list_certificate_revocation_lists_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_certificate_revocation_lists(request) @@ -16983,6 +17028,7 @@ def test_list_certificate_revocation_lists_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_certificate_revocation_lists(**mock_args) @@ -17192,6 +17238,7 @@ def test_update_certificate_revocation_list_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_certificate_revocation_list(request) @@ -17257,6 +17304,7 @@ def test_update_certificate_revocation_list_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_certificate_revocation_list(**mock_args) @@ -17417,6 +17465,7 @@ def test_create_certificate_template_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_certificate_template(request) @@ -17482,6 +17531,7 @@ def test_create_certificate_template_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_certificate_template(**mock_args) @@ -17623,6 +17673,7 @@ def test_delete_certificate_template_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_certificate_template(request) @@ -17668,6 +17719,7 @@ def test_delete_certificate_template_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_certificate_template(**mock_args) @@ -17804,6 +17856,7 @@ def test_get_certificate_template_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_certificate_template(request) @@ -17851,6 +17904,7 @@ def test_get_certificate_template_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_certificate_template(**mock_args) @@ -17996,6 +18050,7 @@ def test_list_certificate_templates_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_certificate_templates(request) @@ -18051,6 +18106,7 @@ def test_list_certificate_templates_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_certificate_templates(**mock_args) @@ -18254,6 +18310,7 @@ def test_update_certificate_template_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_certificate_template(request) @@ -18315,6 +18372,7 @@ def test_update_certificate_template_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_certificate_template(**mock_args) @@ -19980,6 +20038,7 @@ def test_create_certificate_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_certificate(request) @@ -20226,6 +20285,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_certificate(request) # Establish that the response is the type that we expect. @@ -20271,6 +20331,7 @@ def test_create_certificate_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resources.Certificate.to_json(resources.Certificate()) req.return_value.content = return_value @@ -20315,6 +20376,7 @@ def test_get_certificate_rest_bad_request(request_type=service.GetCertificateReq response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_certificate(request) @@ -20358,6 +20420,7 @@ def test_get_certificate_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_certificate(request) # Establish that the response is the type that we expect. @@ -20401,6 +20464,7 @@ def test_get_certificate_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resources.Certificate.to_json(resources.Certificate()) req.return_value.content = return_value @@ -20445,6 +20509,7 @@ def test_list_certificates_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_certificates(request) @@ -20481,6 +20546,7 @@ def test_list_certificates_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_certificates(request) # Establish that the response is the type that we expect. @@ -20522,6 +20588,7 @@ def test_list_certificates_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = service.ListCertificatesResponse.to_json( service.ListCertificatesResponse() ) @@ -20570,6 +20637,7 @@ def test_revoke_certificate_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.revoke_certificate(request) @@ -20613,6 +20681,7 @@ def test_revoke_certificate_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.revoke_certificate(request) # Establish that the response is the type that we expect. @@ -20658,6 +20727,7 @@ def test_revoke_certificate_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resources.Certificate.to_json(resources.Certificate()) req.return_value.content = return_value @@ -20706,6 +20776,7 @@ def test_update_certificate_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_certificate(request) @@ -20956,6 +21027,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_certificate(request) # Establish that the response is the type that we expect. @@ -21001,6 +21073,7 @@ def test_update_certificate_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resources.Certificate.to_json(resources.Certificate()) req.return_value.content = return_value @@ -21047,6 +21120,7 @@ def test_activate_certificate_authority_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.activate_certificate_authority(request) @@ -21079,6 +21153,7 @@ def test_activate_certificate_authority_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.activate_certificate_authority(request) # Establish that the response is the type that we expect. @@ -21122,6 +21197,7 @@ def test_activate_certificate_authority_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -21166,6 +21242,7 @@ def test_create_certificate_authority_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_certificate_authority(request) @@ -21421,6 +21498,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_certificate_authority(request) # Establish that the response is the type that we expect. @@ -21464,6 +21542,7 @@ def test_create_certificate_authority_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -21510,6 +21589,7 @@ def test_disable_certificate_authority_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.disable_certificate_authority(request) @@ -21542,6 +21622,7 @@ def test_disable_certificate_authority_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.disable_certificate_authority(request) # Establish that the response is the type that we expect. @@ -21585,6 +21666,7 @@ def test_disable_certificate_authority_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -21631,6 +21713,7 @@ def test_enable_certificate_authority_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.enable_certificate_authority(request) @@ -21663,6 +21746,7 @@ def test_enable_certificate_authority_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.enable_certificate_authority(request) # Establish that the response is the type that we expect. @@ -21706,6 +21790,7 @@ def test_enable_certificate_authority_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -21752,6 +21837,7 @@ def test_fetch_certificate_authority_csr_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.fetch_certificate_authority_csr(request) @@ -21789,6 +21875,7 @@ def test_fetch_certificate_authority_csr_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.fetch_certificate_authority_csr(request) # Establish that the response is the type that we expect. @@ -21831,6 +21918,7 @@ def test_fetch_certificate_authority_csr_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = service.FetchCertificateAuthorityCsrResponse.to_json( service.FetchCertificateAuthorityCsrResponse() ) @@ -21879,6 +21967,7 @@ def test_get_certificate_authority_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_certificate_authority(request) @@ -21921,6 +22010,7 @@ def test_get_certificate_authority_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_certificate_authority(request) # Establish that the response is the type that we expect. @@ -21968,6 +22058,7 @@ def test_get_certificate_authority_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resources.CertificateAuthority.to_json( resources.CertificateAuthority() ) @@ -22014,6 +22105,7 @@ def test_list_certificate_authorities_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_certificate_authorities(request) @@ -22050,6 +22142,7 @@ def test_list_certificate_authorities_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_certificate_authorities(request) # Establish that the response is the type that we expect. @@ -22093,6 +22186,7 @@ def test_list_certificate_authorities_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = service.ListCertificateAuthoritiesResponse.to_json( service.ListCertificateAuthoritiesResponse() ) @@ -22141,6 +22235,7 @@ def test_undelete_certificate_authority_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.undelete_certificate_authority(request) @@ -22173,6 +22268,7 @@ def test_undelete_certificate_authority_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.undelete_certificate_authority(request) # Establish that the response is the type that we expect. @@ -22216,6 +22312,7 @@ def test_undelete_certificate_authority_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -22262,6 +22359,7 @@ def test_delete_certificate_authority_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_certificate_authority(request) @@ -22294,6 +22392,7 @@ def test_delete_certificate_authority_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_certificate_authority(request) # Establish that the response is the type that we expect. @@ -22337,6 +22436,7 @@ def test_delete_certificate_authority_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -22385,6 +22485,7 @@ def test_update_certificate_authority_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_certificate_authority(request) @@ -22644,6 +22745,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_certificate_authority(request) # Establish that the response is the type that we expect. @@ -22687,6 +22789,7 @@ def test_update_certificate_authority_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -22729,6 +22832,7 @@ def test_create_ca_pool_rest_bad_request(request_type=service.CreateCaPoolReques response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_ca_pool(request) @@ -22928,6 +23032,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_ca_pool(request) # Establish that the response is the type that we expect. @@ -22967,6 +23072,7 @@ def test_create_ca_pool_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -23011,6 +23117,7 @@ def test_update_ca_pool_rest_bad_request(request_type=service.UpdateCaPoolReques response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_ca_pool(request) @@ -23212,6 +23319,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_ca_pool(request) # Establish that the response is the type that we expect. @@ -23251,6 +23359,7 @@ def test_update_ca_pool_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -23293,6 +23402,7 @@ def test_get_ca_pool_rest_bad_request(request_type=service.GetCaPoolRequest): response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_ca_pool(request) @@ -23329,6 +23439,7 @@ def test_get_ca_pool_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_ca_pool(request) # Establish that the response is the type that we expect. @@ -23368,6 +23479,7 @@ def test_get_ca_pool_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resources.CaPool.to_json(resources.CaPool()) req.return_value.content = return_value @@ -23410,6 +23522,7 @@ def test_list_ca_pools_rest_bad_request(request_type=service.ListCaPoolsRequest) response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_ca_pools(request) @@ -23446,6 +23559,7 @@ def test_list_ca_pools_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_ca_pools(request) # Establish that the response is the type that we expect. @@ -23485,6 +23599,7 @@ def test_list_ca_pools_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = service.ListCaPoolsResponse.to_json( service.ListCaPoolsResponse() ) @@ -23529,6 +23644,7 @@ def test_delete_ca_pool_rest_bad_request(request_type=service.DeleteCaPoolReques response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_ca_pool(request) @@ -23559,6 +23675,7 @@ def test_delete_ca_pool_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_ca_pool(request) # Establish that the response is the type that we expect. @@ -23598,6 +23715,7 @@ def test_delete_ca_pool_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -23640,6 +23758,7 @@ def test_fetch_ca_certs_rest_bad_request(request_type=service.FetchCaCertsReques response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.fetch_ca_certs(request) @@ -23673,6 +23792,7 @@ def test_fetch_ca_certs_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.fetch_ca_certs(request) # Establish that the response is the type that we expect. @@ -23710,6 +23830,7 @@ def test_fetch_ca_certs_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = service.FetchCaCertsResponse.to_json( service.FetchCaCertsResponse() ) @@ -23758,6 +23879,7 @@ def test_get_certificate_revocation_list_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_certificate_revocation_list(request) @@ -23800,6 +23922,7 @@ def test_get_certificate_revocation_list_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_certificate_revocation_list(request) # Establish that the response is the type that we expect. @@ -23847,6 +23970,7 @@ def test_get_certificate_revocation_list_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resources.CertificateRevocationList.to_json( resources.CertificateRevocationList() ) @@ -23895,6 +24019,7 @@ def test_list_certificate_revocation_lists_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_certificate_revocation_lists(request) @@ -23933,6 +24058,7 @@ def test_list_certificate_revocation_lists_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_certificate_revocation_lists(request) # Establish that the response is the type that we expect. @@ -23976,6 +24102,7 @@ def test_list_certificate_revocation_lists_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = service.ListCertificateRevocationListsResponse.to_json( service.ListCertificateRevocationListsResponse() ) @@ -24026,6 +24153,7 @@ def test_update_certificate_revocation_list_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_certificate_revocation_list(request) @@ -24151,6 +24279,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_certificate_revocation_list(request) # Establish that the response is the type that we expect. @@ -24194,6 +24323,7 @@ def test_update_certificate_revocation_list_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -24238,6 +24368,7 @@ def test_create_certificate_template_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_certificate_template(request) @@ -24420,6 +24551,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_certificate_template(request) # Establish that the response is the type that we expect. @@ -24463,6 +24595,7 @@ def test_create_certificate_template_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -24509,6 +24642,7 @@ def test_delete_certificate_template_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_certificate_template(request) @@ -24541,6 +24675,7 @@ def test_delete_certificate_template_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_certificate_template(request) # Establish that the response is the type that we expect. @@ -24584,6 +24719,7 @@ def test_delete_certificate_template_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -24630,6 +24766,7 @@ def test_get_certificate_template_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_certificate_template(request) @@ -24668,6 +24805,7 @@ def test_get_certificate_template_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_certificate_template(request) # Establish that the response is the type that we expect. @@ -24711,6 +24849,7 @@ def test_get_certificate_template_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resources.CertificateTemplate.to_json( resources.CertificateTemplate() ) @@ -24757,6 +24896,7 @@ def test_list_certificate_templates_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_certificate_templates(request) @@ -24793,6 +24933,7 @@ def test_list_certificate_templates_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_certificate_templates(request) # Establish that the response is the type that we expect. @@ -24836,6 +24977,7 @@ def test_list_certificate_templates_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = service.ListCertificateTemplatesResponse.to_json( service.ListCertificateTemplatesResponse() ) @@ -24886,6 +25028,7 @@ def test_update_certificate_template_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_certificate_template(request) @@ -25072,6 +25215,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_certificate_template(request) # Establish that the response is the type that we expect. @@ -25115,6 +25259,7 @@ def test_update_certificate_template_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -25159,6 +25304,7 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_location(request) @@ -25189,6 +25335,7 @@ def test_get_location_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_location(request) @@ -25217,6 +25364,7 @@ def test_list_locations_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_locations(request) @@ -25247,6 +25395,7 @@ def test_list_locations_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_locations(request) @@ -25277,6 +25426,7 @@ def test_get_iam_policy_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_iam_policy(request) @@ -25307,6 +25457,7 @@ def test_get_iam_policy_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_iam_policy(request) @@ -25337,6 +25488,7 @@ def test_set_iam_policy_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.set_iam_policy(request) @@ -25367,6 +25519,7 @@ def test_set_iam_policy_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.set_iam_policy(request) @@ -25397,6 +25550,7 @@ def test_test_iam_permissions_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.test_iam_permissions(request) @@ -25427,6 +25581,7 @@ def test_test_iam_permissions_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.test_iam_permissions(request) @@ -25457,6 +25612,7 @@ def test_cancel_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.cancel_operation(request) @@ -25487,6 +25643,7 @@ def test_cancel_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.cancel_operation(request) @@ -25517,6 +25674,7 @@ def test_delete_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_operation(request) @@ -25547,6 +25705,7 @@ def test_delete_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_operation(request) @@ -25577,6 +25736,7 @@ def test_get_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_operation(request) @@ -25607,6 +25767,7 @@ def test_get_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_operation(request) @@ -25637,6 +25798,7 @@ def test_list_operations_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_operations(request) @@ -25667,6 +25829,7 @@ def test_list_operations_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_operations(request) diff --git a/packages/google-cloud-private-ca/tests/unit/gapic/privateca_v1beta1/test_certificate_authority_service.py b/packages/google-cloud-private-ca/tests/unit/gapic/privateca_v1beta1/test_certificate_authority_service.py index 10e9b00d8635..6cb3ffdafd03 100644 --- a/packages/google-cloud-private-ca/tests/unit/gapic/privateca_v1beta1/test_certificate_authority_service.py +++ b/packages/google-cloud-private-ca/tests/unit/gapic/privateca_v1beta1/test_certificate_authority_service.py @@ -9156,6 +9156,7 @@ def test_create_certificate_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_certificate(request) @@ -9218,6 +9219,7 @@ def test_create_certificate_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_certificate(**mock_args) @@ -9351,6 +9353,7 @@ def test_get_certificate_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_certificate(request) @@ -9398,6 +9401,7 @@ def test_get_certificate_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_certificate(**mock_args) @@ -9540,6 +9544,7 @@ def test_list_certificates_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_certificates(request) @@ -9597,6 +9602,7 @@ def test_list_certificates_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_certificates(**mock_args) @@ -9796,6 +9802,7 @@ def test_revoke_certificate_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.revoke_certificate(request) @@ -9851,6 +9858,7 @@ def test_revoke_certificate_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.revoke_certificate(**mock_args) @@ -9989,6 +9997,7 @@ def test_update_certificate_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_certificate(request) @@ -10052,6 +10061,7 @@ def test_update_certificate_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_certificate(**mock_args) @@ -10195,6 +10205,7 @@ def test_activate_certificate_authority_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.activate_certificate_authority(request) @@ -10251,6 +10262,7 @@ def test_activate_certificate_authority_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.activate_certificate_authority(**mock_args) @@ -10408,6 +10420,7 @@ def test_create_certificate_authority_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_certificate_authority(request) @@ -10473,6 +10486,7 @@ def test_create_certificate_authority_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_certificate_authority(**mock_args) @@ -10613,6 +10627,7 @@ def test_disable_certificate_authority_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.disable_certificate_authority(request) @@ -10660,6 +10675,7 @@ def test_disable_certificate_authority_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.disable_certificate_authority(**mock_args) @@ -10798,6 +10814,7 @@ def test_enable_certificate_authority_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.enable_certificate_authority(request) @@ -10843,6 +10860,7 @@ def test_enable_certificate_authority_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.enable_certificate_authority(**mock_args) @@ -10979,6 +10997,7 @@ def test_fetch_certificate_authority_csr_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.fetch_certificate_authority_csr(request) @@ -11028,6 +11047,7 @@ def test_fetch_certificate_authority_csr_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.fetch_certificate_authority_csr(**mock_args) @@ -11164,6 +11184,7 @@ def test_get_certificate_authority_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_certificate_authority(request) @@ -11211,6 +11232,7 @@ def test_get_certificate_authority_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_certificate_authority(**mock_args) @@ -11356,6 +11378,7 @@ def test_list_certificate_authorities_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_certificate_authorities(request) @@ -11411,6 +11434,7 @@ def test_list_certificate_authorities_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_certificate_authorities(**mock_args) @@ -11612,6 +11636,7 @@ def test_restore_certificate_authority_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.restore_certificate_authority(request) @@ -11659,6 +11684,7 @@ def test_restore_certificate_authority_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.restore_certificate_authority(**mock_args) @@ -11801,6 +11827,7 @@ def test_schedule_delete_certificate_authority_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.schedule_delete_certificate_authority(request) @@ -11848,6 +11875,7 @@ def test_schedule_delete_certificate_authority_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.schedule_delete_certificate_authority(**mock_args) @@ -11990,6 +12018,7 @@ def test_update_certificate_authority_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_certificate_authority(request) @@ -12051,6 +12080,7 @@ def test_update_certificate_authority_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_certificate_authority(**mock_args) @@ -12188,6 +12218,7 @@ def test_get_certificate_revocation_list_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_certificate_revocation_list(request) @@ -12237,6 +12268,7 @@ def test_get_certificate_revocation_list_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_certificate_revocation_list(**mock_args) @@ -12384,6 +12416,7 @@ def test_list_certificate_revocation_lists_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_certificate_revocation_lists(request) @@ -12443,6 +12476,7 @@ def test_list_certificate_revocation_lists_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_certificate_revocation_lists(**mock_args) @@ -12652,6 +12686,7 @@ def test_update_certificate_revocation_list_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_certificate_revocation_list(request) @@ -12717,6 +12752,7 @@ def test_update_certificate_revocation_list_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_certificate_revocation_list(**mock_args) @@ -12857,6 +12893,7 @@ def test_get_reusable_config_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_reusable_config(request) @@ -12904,6 +12941,7 @@ def test_get_reusable_config_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_reusable_config(**mock_args) @@ -13049,6 +13087,7 @@ def test_list_reusable_configs_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_reusable_configs(request) @@ -13104,6 +13143,7 @@ def test_list_reusable_configs_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_reusable_configs(**mock_args) @@ -14388,6 +14428,7 @@ def test_create_certificate_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_certificate(request) @@ -14604,6 +14645,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_certificate(request) # Establish that the response is the type that we expect. @@ -14646,6 +14688,7 @@ def test_create_certificate_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resources.Certificate.to_json(resources.Certificate()) req.return_value.content = return_value @@ -14690,6 +14733,7 @@ def test_get_certificate_rest_bad_request(request_type=service.GetCertificateReq response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_certificate(request) @@ -14730,6 +14774,7 @@ def test_get_certificate_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_certificate(request) # Establish that the response is the type that we expect. @@ -14770,6 +14815,7 @@ def test_get_certificate_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resources.Certificate.to_json(resources.Certificate()) req.return_value.content = return_value @@ -14816,6 +14862,7 @@ def test_list_certificates_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_certificates(request) @@ -14854,6 +14901,7 @@ def test_list_certificates_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_certificates(request) # Establish that the response is the type that we expect. @@ -14895,6 +14943,7 @@ def test_list_certificates_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = service.ListCertificatesResponse.to_json( service.ListCertificatesResponse() ) @@ -14943,6 +14992,7 @@ def test_revoke_certificate_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.revoke_certificate(request) @@ -14983,6 +15033,7 @@ def test_revoke_certificate_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.revoke_certificate(request) # Establish that the response is the type that we expect. @@ -15025,6 +15076,7 @@ def test_revoke_certificate_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resources.Certificate.to_json(resources.Certificate()) req.return_value.content = return_value @@ -15073,6 +15125,7 @@ def test_update_certificate_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_certificate(request) @@ -15291,6 +15344,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_certificate(request) # Establish that the response is the type that we expect. @@ -15333,6 +15387,7 @@ def test_update_certificate_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resources.Certificate.to_json(resources.Certificate()) req.return_value.content = return_value @@ -15379,6 +15434,7 @@ def test_activate_certificate_authority_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.activate_certificate_authority(request) @@ -15411,6 +15467,7 @@ def test_activate_certificate_authority_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.activate_certificate_authority(request) # Establish that the response is the type that we expect. @@ -15454,6 +15511,7 @@ def test_activate_certificate_authority_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -15498,6 +15556,7 @@ def test_create_certificate_authority_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_certificate_authority(request) @@ -15758,6 +15817,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_certificate_authority(request) # Establish that the response is the type that we expect. @@ -15801,6 +15861,7 @@ def test_create_certificate_authority_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -15847,6 +15908,7 @@ def test_disable_certificate_authority_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.disable_certificate_authority(request) @@ -15879,6 +15941,7 @@ def test_disable_certificate_authority_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.disable_certificate_authority(request) # Establish that the response is the type that we expect. @@ -15922,6 +15985,7 @@ def test_disable_certificate_authority_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -15968,6 +16032,7 @@ def test_enable_certificate_authority_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.enable_certificate_authority(request) @@ -16000,6 +16065,7 @@ def test_enable_certificate_authority_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.enable_certificate_authority(request) # Establish that the response is the type that we expect. @@ -16043,6 +16109,7 @@ def test_enable_certificate_authority_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -16089,6 +16156,7 @@ def test_fetch_certificate_authority_csr_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.fetch_certificate_authority_csr(request) @@ -16126,6 +16194,7 @@ def test_fetch_certificate_authority_csr_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.fetch_certificate_authority_csr(request) # Establish that the response is the type that we expect. @@ -16168,6 +16237,7 @@ def test_fetch_certificate_authority_csr_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = service.FetchCertificateAuthorityCsrResponse.to_json( service.FetchCertificateAuthorityCsrResponse() ) @@ -16216,6 +16286,7 @@ def test_get_certificate_authority_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_certificate_authority(request) @@ -16258,6 +16329,7 @@ def test_get_certificate_authority_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_certificate_authority(request) # Establish that the response is the type that we expect. @@ -16305,6 +16377,7 @@ def test_get_certificate_authority_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resources.CertificateAuthority.to_json( resources.CertificateAuthority() ) @@ -16351,6 +16424,7 @@ def test_list_certificate_authorities_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_certificate_authorities(request) @@ -16387,6 +16461,7 @@ def test_list_certificate_authorities_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_certificate_authorities(request) # Establish that the response is the type that we expect. @@ -16430,6 +16505,7 @@ def test_list_certificate_authorities_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = service.ListCertificateAuthoritiesResponse.to_json( service.ListCertificateAuthoritiesResponse() ) @@ -16478,6 +16554,7 @@ def test_restore_certificate_authority_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.restore_certificate_authority(request) @@ -16510,6 +16587,7 @@ def test_restore_certificate_authority_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.restore_certificate_authority(request) # Establish that the response is the type that we expect. @@ -16553,6 +16631,7 @@ def test_restore_certificate_authority_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -16599,6 +16678,7 @@ def test_schedule_delete_certificate_authority_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.schedule_delete_certificate_authority(request) @@ -16631,6 +16711,7 @@ def test_schedule_delete_certificate_authority_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.schedule_delete_certificate_authority(request) # Establish that the response is the type that we expect. @@ -16674,6 +16755,7 @@ def test_schedule_delete_certificate_authority_rest_interceptors(null_intercepto req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -16722,6 +16804,7 @@ def test_update_certificate_authority_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_certificate_authority(request) @@ -16986,6 +17069,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_certificate_authority(request) # Establish that the response is the type that we expect. @@ -17029,6 +17113,7 @@ def test_update_certificate_authority_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -17075,6 +17160,7 @@ def test_get_certificate_revocation_list_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_certificate_revocation_list(request) @@ -17116,6 +17202,7 @@ def test_get_certificate_revocation_list_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_certificate_revocation_list(request) # Establish that the response is the type that we expect. @@ -17162,6 +17249,7 @@ def test_get_certificate_revocation_list_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resources.CertificateRevocationList.to_json( resources.CertificateRevocationList() ) @@ -17210,6 +17298,7 @@ def test_list_certificate_revocation_lists_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_certificate_revocation_lists(request) @@ -17248,6 +17337,7 @@ def test_list_certificate_revocation_lists_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_certificate_revocation_lists(request) # Establish that the response is the type that we expect. @@ -17291,6 +17381,7 @@ def test_list_certificate_revocation_lists_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = service.ListCertificateRevocationListsResponse.to_json( service.ListCertificateRevocationListsResponse() ) @@ -17341,6 +17432,7 @@ def test_update_certificate_revocation_list_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_certificate_revocation_list(request) @@ -17465,6 +17557,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_certificate_revocation_list(request) # Establish that the response is the type that we expect. @@ -17508,6 +17601,7 @@ def test_update_certificate_revocation_list_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -17554,6 +17648,7 @@ def test_get_reusable_config_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_reusable_config(request) @@ -17592,6 +17687,7 @@ def test_get_reusable_config_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_reusable_config(request) # Establish that the response is the type that we expect. @@ -17634,6 +17730,7 @@ def test_get_reusable_config_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resources.ReusableConfig.to_json(resources.ReusableConfig()) req.return_value.content = return_value @@ -17678,6 +17775,7 @@ def test_list_reusable_configs_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_reusable_configs(request) @@ -17714,6 +17812,7 @@ def test_list_reusable_configs_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_reusable_configs(request) # Establish that the response is the type that we expect. @@ -17757,6 +17856,7 @@ def test_list_reusable_configs_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = service.ListReusableConfigsResponse.to_json( service.ListReusableConfigsResponse() ) diff --git a/packages/google-cloud-private-catalog/google/cloud/privatecatalog/gapic_version.py b/packages/google-cloud-private-catalog/google/cloud/privatecatalog/gapic_version.py index f8e3c3e8278e..558c8aab67c5 100644 --- a/packages/google-cloud-private-catalog/google/cloud/privatecatalog/gapic_version.py +++ b/packages/google-cloud-private-catalog/google/cloud/privatecatalog/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.9.13" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/gapic_version.py b/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/gapic_version.py index f8e3c3e8278e..558c8aab67c5 100644 --- a/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/gapic_version.py +++ b/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.9.13" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/async_client.py b/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/async_client.py index 2521b1a30e1e..e8cbbc64d5d3 100644 --- a/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/async_client.py +++ b/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -49,6 +50,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, PrivateCatalogTransport from .transports.grpc_asyncio import PrivateCatalogGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class PrivateCatalogAsyncClient: """``PrivateCatalog`` allows catalog consumers to retrieve ``Catalog``, @@ -280,13 +290,35 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.privatecatalog_v1beta1.PrivateCatalogAsyncClient`.", + extra={ + "serviceName": "google.cloud.privatecatalog.v1beta1.PrivateCatalog", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.privatecatalog.v1beta1.PrivateCatalog", + "credentialsType": None, + }, + ) + async def search_catalogs( self, request: Optional[Union[private_catalog.SearchCatalogsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.SearchCatalogsAsyncPager: r"""Search [Catalog][google.cloud.privatecatalog.v1beta1.Catalog] resources that consumers have access to, within the scope of the @@ -326,8 +358,10 @@ async def sample_search_catalogs(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privatecatalog_v1beta1.services.private_catalog.pagers.SearchCatalogsAsyncPager: @@ -387,7 +421,7 @@ async def search_products( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.SearchProductsAsyncPager: r"""Search [Product][google.cloud.privatecatalog.v1beta1.Product] resources that consumers have access to, within the scope of the @@ -427,8 +461,10 @@ async def sample_search_products(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privatecatalog_v1beta1.services.private_catalog.pagers.SearchProductsAsyncPager: @@ -488,7 +524,7 @@ async def search_versions( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.SearchVersionsAsyncPager: r"""Search [Version][google.cloud.privatecatalog.v1beta1.Version] resources that consumers have access to, within the scope of the @@ -529,8 +565,10 @@ async def sample_search_versions(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privatecatalog_v1beta1.services.private_catalog.pagers.SearchVersionsAsyncPager: diff --git a/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/client.py b/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/client.py index 38082d58d008..e73aecb00d01 100644 --- a/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/client.py +++ b/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.cloud.privatecatalog_v1beta1.services.private_catalog import pagers from google.cloud.privatecatalog_v1beta1.types import private_catalog @@ -630,6 +640,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -695,13 +709,36 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.privatecatalog_v1beta1.PrivateCatalogClient`.", + extra={ + "serviceName": "google.cloud.privatecatalog.v1beta1.PrivateCatalog", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.privatecatalog.v1beta1.PrivateCatalog", + "credentialsType": None, + }, + ) + def search_catalogs( self, request: Optional[Union[private_catalog.SearchCatalogsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.SearchCatalogsPager: r"""Search [Catalog][google.cloud.privatecatalog.v1beta1.Catalog] resources that consumers have access to, within the scope of the @@ -741,8 +778,10 @@ def sample_search_catalogs(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privatecatalog_v1beta1.services.private_catalog.pagers.SearchCatalogsPager: @@ -800,7 +839,7 @@ def search_products( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.SearchProductsPager: r"""Search [Product][google.cloud.privatecatalog.v1beta1.Product] resources that consumers have access to, within the scope of the @@ -840,8 +879,10 @@ def sample_search_products(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privatecatalog_v1beta1.services.private_catalog.pagers.SearchProductsPager: @@ -899,7 +940,7 @@ def search_versions( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.SearchVersionsPager: r"""Search [Version][google.cloud.privatecatalog.v1beta1.Version] resources that consumers have access to, within the scope of the @@ -940,8 +981,10 @@ def sample_search_versions(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privatecatalog_v1beta1.services.private_catalog.pagers.SearchVersionsPager: diff --git a/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/pagers.py b/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/pagers.py index 28b20da2509d..2dd9fedeb7bc 100644 --- a/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/pagers.py +++ b/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -81,8 +81,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = private_catalog.SearchCatalogsRequest(request) @@ -141,7 +143,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -155,8 +157,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = private_catalog.SearchCatalogsRequest(request) @@ -219,7 +223,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -233,8 +237,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = private_catalog.SearchProductsRequest(request) @@ -293,7 +299,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -307,8 +313,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = private_catalog.SearchProductsRequest(request) @@ -371,7 +379,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -385,8 +393,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = private_catalog.SearchVersionsRequest(request) @@ -445,7 +455,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -459,8 +469,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = private_catalog.SearchVersionsRequest(request) diff --git a/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/transports/grpc.py b/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/transports/grpc.py index 5a588074064a..2d23cb8e4f69 100644 --- a/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/transports/grpc.py +++ b/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -20,12 +23,90 @@ import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.privatecatalog_v1beta1.types import private_catalog from .base import DEFAULT_CLIENT_INFO, PrivateCatalogTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.privatecatalog.v1beta1.PrivateCatalog", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.privatecatalog.v1beta1.PrivateCatalog", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class PrivateCatalogGrpcTransport(PrivateCatalogTransport): """gRPC backend transport for PrivateCatalog. @@ -200,7 +281,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -278,7 +364,7 @@ def search_catalogs( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "search_catalogs" not in self._stubs: - self._stubs["search_catalogs"] = self.grpc_channel.unary_unary( + self._stubs["search_catalogs"] = self._logged_channel.unary_unary( "/google.cloud.privatecatalog.v1beta1.PrivateCatalog/SearchCatalogs", request_serializer=private_catalog.SearchCatalogsRequest.serialize, response_deserializer=private_catalog.SearchCatalogsResponse.deserialize, @@ -308,7 +394,7 @@ def search_products( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "search_products" not in self._stubs: - self._stubs["search_products"] = self.grpc_channel.unary_unary( + self._stubs["search_products"] = self._logged_channel.unary_unary( "/google.cloud.privatecatalog.v1beta1.PrivateCatalog/SearchProducts", request_serializer=private_catalog.SearchProductsRequest.serialize, response_deserializer=private_catalog.SearchProductsResponse.deserialize, @@ -338,7 +424,7 @@ def search_versions( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "search_versions" not in self._stubs: - self._stubs["search_versions"] = self.grpc_channel.unary_unary( + self._stubs["search_versions"] = self._logged_channel.unary_unary( "/google.cloud.privatecatalog.v1beta1.PrivateCatalog/SearchVersions", request_serializer=private_catalog.SearchVersionsRequest.serialize, response_deserializer=private_catalog.SearchVersionsResponse.deserialize, @@ -346,7 +432,7 @@ def search_versions( return self._stubs["search_versions"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/transports/grpc_asyncio.py b/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/transports/grpc_asyncio.py index 3359304fff03..2c21edfcc329 100644 --- a/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/transports/grpc_asyncio.py +++ b/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -22,14 +25,93 @@ from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.privatecatalog_v1beta1.types import private_catalog from .base import DEFAULT_CLIENT_INFO, PrivateCatalogTransport from .grpc import PrivateCatalogGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.privatecatalog.v1beta1.PrivateCatalog", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.privatecatalog.v1beta1.PrivateCatalog", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class PrivateCatalogGrpcAsyncIOTransport(PrivateCatalogTransport): """gRPC AsyncIO backend transport for PrivateCatalog. @@ -247,10 +329,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -287,7 +372,7 @@ def search_catalogs( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "search_catalogs" not in self._stubs: - self._stubs["search_catalogs"] = self.grpc_channel.unary_unary( + self._stubs["search_catalogs"] = self._logged_channel.unary_unary( "/google.cloud.privatecatalog.v1beta1.PrivateCatalog/SearchCatalogs", request_serializer=private_catalog.SearchCatalogsRequest.serialize, response_deserializer=private_catalog.SearchCatalogsResponse.deserialize, @@ -318,7 +403,7 @@ def search_products( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "search_products" not in self._stubs: - self._stubs["search_products"] = self.grpc_channel.unary_unary( + self._stubs["search_products"] = self._logged_channel.unary_unary( "/google.cloud.privatecatalog.v1beta1.PrivateCatalog/SearchProducts", request_serializer=private_catalog.SearchProductsRequest.serialize, response_deserializer=private_catalog.SearchProductsResponse.deserialize, @@ -349,7 +434,7 @@ def search_versions( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "search_versions" not in self._stubs: - self._stubs["search_versions"] = self.grpc_channel.unary_unary( + self._stubs["search_versions"] = self._logged_channel.unary_unary( "/google.cloud.privatecatalog.v1beta1.PrivateCatalog/SearchVersions", request_serializer=private_catalog.SearchVersionsRequest.serialize, response_deserializer=private_catalog.SearchVersionsResponse.deserialize, @@ -382,7 +467,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/transports/rest.py b/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/transports/rest.py index effab20c4006..98facb8d06c7 100644 --- a/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/transports/rest.py +++ b/packages/google-cloud-private-catalog/google/cloud/privatecatalog_v1beta1/services/private_catalog/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -37,6 +37,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -93,8 +101,10 @@ def post_search_versions(self, response): def pre_search_catalogs( self, request: private_catalog.SearchCatalogsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[private_catalog.SearchCatalogsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + private_catalog.SearchCatalogsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for search_catalogs Override in a subclass to manipulate the request or metadata @@ -116,8 +126,10 @@ def post_search_catalogs( def pre_search_products( self, request: private_catalog.SearchProductsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[private_catalog.SearchProductsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + private_catalog.SearchProductsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for search_products Override in a subclass to manipulate the request or metadata @@ -139,8 +151,10 @@ def post_search_products( def pre_search_versions( self, request: private_catalog.SearchVersionsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[private_catalog.SearchVersionsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + private_catalog.SearchVersionsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for search_versions Override in a subclass to manipulate the request or metadata @@ -301,7 +315,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> private_catalog.SearchCatalogsResponse: r"""Call the search catalogs method over HTTP. @@ -312,8 +326,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.private_catalog.SearchCatalogsResponse: @@ -325,6 +341,7 @@ def __call__( http_options = ( _BasePrivateCatalogRestTransport._BaseSearchCatalogs._get_http_options() ) + request, metadata = self._interceptor.pre_search_catalogs(request, metadata) transcoded_request = _BasePrivateCatalogRestTransport._BaseSearchCatalogs._get_transcoded_request( http_options, request @@ -335,6 +352,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.privatecatalog_v1beta1.PrivateCatalogClient.SearchCatalogs", + extra={ + "serviceName": "google.cloud.privatecatalog.v1beta1.PrivateCatalog", + "rpcName": "SearchCatalogs", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = PrivateCatalogRestTransport._SearchCatalogs._get_response( self._host, @@ -355,7 +399,31 @@ def __call__( pb_resp = private_catalog.SearchCatalogsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_search_catalogs(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = private_catalog.SearchCatalogsResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.privatecatalog_v1beta1.PrivateCatalogClient.search_catalogs", + extra={ + "serviceName": "google.cloud.privatecatalog.v1beta1.PrivateCatalog", + "rpcName": "SearchCatalogs", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _SearchProducts( @@ -392,7 +460,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> private_catalog.SearchProductsResponse: r"""Call the search products method over HTTP. @@ -403,8 +471,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.private_catalog.SearchProductsResponse: @@ -416,6 +486,7 @@ def __call__( http_options = ( _BasePrivateCatalogRestTransport._BaseSearchProducts._get_http_options() ) + request, metadata = self._interceptor.pre_search_products(request, metadata) transcoded_request = _BasePrivateCatalogRestTransport._BaseSearchProducts._get_transcoded_request( http_options, request @@ -426,6 +497,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.privatecatalog_v1beta1.PrivateCatalogClient.SearchProducts", + extra={ + "serviceName": "google.cloud.privatecatalog.v1beta1.PrivateCatalog", + "rpcName": "SearchProducts", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = PrivateCatalogRestTransport._SearchProducts._get_response( self._host, @@ -446,7 +544,31 @@ def __call__( pb_resp = private_catalog.SearchProductsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_search_products(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = private_catalog.SearchProductsResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.privatecatalog_v1beta1.PrivateCatalogClient.search_products", + extra={ + "serviceName": "google.cloud.privatecatalog.v1beta1.PrivateCatalog", + "rpcName": "SearchProducts", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _SearchVersions( @@ -483,7 +605,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> private_catalog.SearchVersionsResponse: r"""Call the search versions method over HTTP. @@ -494,8 +616,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.private_catalog.SearchVersionsResponse: @@ -507,6 +631,7 @@ def __call__( http_options = ( _BasePrivateCatalogRestTransport._BaseSearchVersions._get_http_options() ) + request, metadata = self._interceptor.pre_search_versions(request, metadata) transcoded_request = _BasePrivateCatalogRestTransport._BaseSearchVersions._get_transcoded_request( http_options, request @@ -517,6 +642,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.privatecatalog_v1beta1.PrivateCatalogClient.SearchVersions", + extra={ + "serviceName": "google.cloud.privatecatalog.v1beta1.PrivateCatalog", + "rpcName": "SearchVersions", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = PrivateCatalogRestTransport._SearchVersions._get_response( self._host, @@ -537,7 +689,31 @@ def __call__( pb_resp = private_catalog.SearchVersionsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_search_versions(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = private_catalog.SearchVersionsResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.privatecatalog_v1beta1.PrivateCatalogClient.search_versions", + extra={ + "serviceName": "google.cloud.privatecatalog.v1beta1.PrivateCatalog", + "rpcName": "SearchVersions", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property diff --git a/packages/google-cloud-private-catalog/samples/generated_samples/snippet_metadata_google.cloud.privatecatalog.v1beta1.json b/packages/google-cloud-private-catalog/samples/generated_samples/snippet_metadata_google.cloud.privatecatalog.v1beta1.json index 480debfe6e4a..acf623a1683e 100644 --- a/packages/google-cloud-private-catalog/samples/generated_samples/snippet_metadata_google.cloud.privatecatalog.v1beta1.json +++ b/packages/google-cloud-private-catalog/samples/generated_samples/snippet_metadata_google.cloud.privatecatalog.v1beta1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-private-catalog", - "version": "0.9.13" + "version": "0.1.0" }, "snippets": [ { @@ -43,7 +43,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privatecatalog_v1beta1.services.private_catalog.pagers.SearchCatalogsAsyncPager", @@ -119,7 +119,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privatecatalog_v1beta1.services.private_catalog.pagers.SearchCatalogsPager", @@ -196,7 +196,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privatecatalog_v1beta1.services.private_catalog.pagers.SearchProductsAsyncPager", @@ -272,7 +272,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privatecatalog_v1beta1.services.private_catalog.pagers.SearchProductsPager", @@ -349,7 +349,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privatecatalog_v1beta1.services.private_catalog.pagers.SearchVersionsAsyncPager", @@ -425,7 +425,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privatecatalog_v1beta1.services.private_catalog.pagers.SearchVersionsPager", diff --git a/packages/google-cloud-private-catalog/tests/unit/gapic/privatecatalog_v1beta1/test_private_catalog.py b/packages/google-cloud-private-catalog/tests/unit/gapic/privatecatalog_v1beta1/test_private_catalog.py index 06ff194fc972..10d0faf6f767 100644 --- a/packages/google-cloud-private-catalog/tests/unit/gapic/privatecatalog_v1beta1/test_private_catalog.py +++ b/packages/google-cloud-private-catalog/tests/unit/gapic/privatecatalog_v1beta1/test_private_catalog.py @@ -2487,6 +2487,7 @@ def test_search_catalogs_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.search_catalogs(request) @@ -2686,6 +2687,7 @@ def test_search_products_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.search_products(request) @@ -2892,6 +2894,7 @@ def test_search_versions_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.search_versions(request) @@ -3284,6 +3287,7 @@ def test_search_catalogs_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.search_catalogs(request) @@ -3319,6 +3323,7 @@ def test_search_catalogs_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.search_catalogs(request) # Establish that the response is the type that we expect. @@ -3359,6 +3364,7 @@ def test_search_catalogs_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = private_catalog.SearchCatalogsResponse.to_json( private_catalog.SearchCatalogsResponse() ) @@ -3405,6 +3411,7 @@ def test_search_products_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.search_products(request) @@ -3440,6 +3447,7 @@ def test_search_products_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.search_products(request) # Establish that the response is the type that we expect. @@ -3480,6 +3488,7 @@ def test_search_products_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = private_catalog.SearchProductsResponse.to_json( private_catalog.SearchProductsResponse() ) @@ -3526,6 +3535,7 @@ def test_search_versions_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.search_versions(request) @@ -3561,6 +3571,7 @@ def test_search_versions_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.search_versions(request) # Establish that the response is the type that we expect. @@ -3601,6 +3612,7 @@ def test_search_versions_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = private_catalog.SearchVersionsResponse.to_json( private_catalog.SearchVersionsResponse() ) diff --git a/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager/gapic_version.py b/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager/gapic_version.py index 937ede8823ef..558c8aab67c5 100644 --- a/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager/gapic_version.py +++ b/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.1.4" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/gapic_version.py b/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/gapic_version.py index 937ede8823ef..558c8aab67c5 100644 --- a/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/gapic_version.py +++ b/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.1.4" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/async_client.py b/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/async_client.py index fe11286a0ab3..f72b26c64834 100644 --- a/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/async_client.py +++ b/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -59,6 +60,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, PrivilegedAccessManagerTransport from .transports.grpc_asyncio import PrivilegedAccessManagerGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class PrivilegedAccessManagerAsyncClient: """This API allows customers to manage temporary, request based @@ -301,6 +311,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerAsyncClient`.", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "credentialsType": None, + }, + ) + async def check_onboarding_status( self, request: Optional[ @@ -309,7 +341,7 @@ async def check_onboarding_status( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> privilegedaccessmanager.CheckOnboardingStatusResponse: r"""``CheckOnboardingStatus`` reports the onboarding status for a project/folder/organization. Any findings reported by this API @@ -347,8 +379,10 @@ async def sample_check_onboarding_status(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privilegedaccessmanager_v1.types.CheckOnboardingStatusResponse: @@ -397,7 +431,7 @@ async def list_entitlements( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListEntitlementsAsyncPager: r"""Lists entitlements in a given project/folder/organization and location. @@ -443,8 +477,10 @@ async def sample_list_entitlements(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privilegedaccessmanager_v1.services.privileged_access_manager.pagers.ListEntitlementsAsyncPager: @@ -520,7 +556,7 @@ async def search_entitlements( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.SearchEntitlementsAsyncPager: r"""``SearchEntitlements`` returns entitlements on which the caller has the specified access. @@ -559,8 +595,10 @@ async def sample_search_entitlements(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privilegedaccessmanager_v1.services.privileged_access_manager.pagers.SearchEntitlementsAsyncPager: @@ -622,7 +660,7 @@ async def get_entitlement( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> privilegedaccessmanager.Entitlement: r"""Gets details of a single entitlement. @@ -663,8 +701,10 @@ async def sample_get_entitlement(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privilegedaccessmanager_v1.types.Entitlement: @@ -732,7 +772,7 @@ async def create_entitlement( entitlement_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Creates a new entitlement in a given project/folder/organization and location. @@ -804,8 +844,10 @@ async def sample_create_entitlement(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -883,7 +925,7 @@ async def delete_entitlement( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a single entitlement. This method can only be called when there are no in-progress @@ -931,8 +973,10 @@ async def sample_delete_entitlement(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1007,7 +1051,7 @@ async def update_entitlement( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Updates the entitlement specified in the request. Updated fields in the entitlement need to be specified in an update mask. The @@ -1090,8 +1134,10 @@ async def sample_update_entitlement(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1169,7 +1215,7 @@ async def list_grants( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListGrantsAsyncPager: r"""Lists grants for a given entitlement. @@ -1214,8 +1260,10 @@ async def sample_list_grants(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privilegedaccessmanager_v1.services.privileged_access_manager.pagers.ListGrantsAsyncPager: @@ -1291,7 +1339,7 @@ async def search_grants( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.SearchGrantsAsyncPager: r"""``SearchGrants`` returns grants that are related to the calling user in the specified way. @@ -1330,8 +1378,10 @@ async def sample_search_grants(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privilegedaccessmanager_v1.services.privileged_access_manager.pagers.SearchGrantsAsyncPager: @@ -1391,7 +1441,7 @@ async def get_grant( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> privilegedaccessmanager.Grant: r"""Get details of a single grant. @@ -1432,8 +1482,10 @@ async def sample_get_grant(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privilegedaccessmanager_v1.types.Grant: @@ -1498,7 +1550,7 @@ async def create_grant( grant: Optional[privilegedaccessmanager.Grant] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> privilegedaccessmanager.Grant: r"""Creates a new grant in a given project/folder/organization and location. @@ -1548,8 +1600,10 @@ async def sample_create_grant(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privilegedaccessmanager_v1.types.Grant: @@ -1614,7 +1668,7 @@ async def approve_grant( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> privilegedaccessmanager.Grant: r"""``ApproveGrant`` is used to approve a grant. This method can only be called on a grant when it's in the ``APPROVAL_AWAITED`` @@ -1652,8 +1706,10 @@ async def sample_approve_grant(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privilegedaccessmanager_v1.types.Grant: @@ -1700,7 +1756,7 @@ async def deny_grant( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> privilegedaccessmanager.Grant: r"""``DenyGrant`` is used to deny a grant. This method can only be called on a grant when it's in the ``APPROVAL_AWAITED`` state. @@ -1738,8 +1794,10 @@ async def sample_deny_grant(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privilegedaccessmanager_v1.types.Grant: @@ -1788,7 +1846,7 @@ async def revoke_grant( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""``RevokeGrant`` is used to immediately revoke access for a grant. This method can be called when the grant is in a @@ -1830,8 +1888,10 @@ async def sample_revoke_grant(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1887,7 +1947,7 @@ async def list_operations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Lists operations that match the specified filter in the request. @@ -1898,8 +1958,10 @@ async def list_operations( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.ListOperationsResponse: Response message for ``ListOperations`` method. @@ -1940,7 +2002,7 @@ async def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -1951,8 +2013,10 @@ async def get_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. @@ -1993,7 +2057,7 @@ async def delete_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Deletes a long-running operation. @@ -2009,8 +2073,10 @@ async def delete_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: None """ @@ -2047,7 +2113,7 @@ async def get_location( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.Location: r"""Gets information about a location. @@ -2058,8 +2124,10 @@ async def get_location( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.Location: Location object. @@ -2100,7 +2168,7 @@ async def list_locations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.ListLocationsResponse: r"""Lists information about the supported locations for this service. @@ -2111,8 +2179,10 @@ async def list_locations( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.ListLocationsResponse: Response message for ``ListLocations`` method. diff --git a/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/client.py b/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/client.py index dddf395d20a8..ab170cc3e144 100644 --- a/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/client.py +++ b/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.location import locations_pb2 # type: ignore @@ -645,6 +655,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -711,6 +725,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient`.", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "credentialsType": None, + }, + ) + def check_onboarding_status( self, request: Optional[ @@ -719,7 +756,7 @@ def check_onboarding_status( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> privilegedaccessmanager.CheckOnboardingStatusResponse: r"""``CheckOnboardingStatus`` reports the onboarding status for a project/folder/organization. Any findings reported by this API @@ -757,8 +794,10 @@ def sample_check_onboarding_status(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privilegedaccessmanager_v1.types.CheckOnboardingStatusResponse: @@ -805,7 +844,7 @@ def list_entitlements( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListEntitlementsPager: r"""Lists entitlements in a given project/folder/organization and location. @@ -851,8 +890,10 @@ def sample_list_entitlements(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privilegedaccessmanager_v1.services.privileged_access_manager.pagers.ListEntitlementsPager: @@ -925,7 +966,7 @@ def search_entitlements( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.SearchEntitlementsPager: r"""``SearchEntitlements`` returns entitlements on which the caller has the specified access. @@ -964,8 +1005,10 @@ def sample_search_entitlements(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privilegedaccessmanager_v1.services.privileged_access_manager.pagers.SearchEntitlementsPager: @@ -1025,7 +1068,7 @@ def get_entitlement( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> privilegedaccessmanager.Entitlement: r"""Gets details of a single entitlement. @@ -1066,8 +1109,10 @@ def sample_get_entitlement(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privilegedaccessmanager_v1.types.Entitlement: @@ -1132,7 +1177,7 @@ def create_entitlement( entitlement_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Creates a new entitlement in a given project/folder/organization and location. @@ -1204,8 +1249,10 @@ def sample_create_entitlement(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1280,7 +1327,7 @@ def delete_entitlement( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Deletes a single entitlement. This method can only be called when there are no in-progress @@ -1328,8 +1375,10 @@ def sample_delete_entitlement(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1401,7 +1450,7 @@ def update_entitlement( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Updates the entitlement specified in the request. Updated fields in the entitlement need to be specified in an update mask. The @@ -1484,8 +1533,10 @@ def sample_update_entitlement(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1560,7 +1611,7 @@ def list_grants( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListGrantsPager: r"""Lists grants for a given entitlement. @@ -1605,8 +1656,10 @@ def sample_list_grants(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privilegedaccessmanager_v1.services.privileged_access_manager.pagers.ListGrantsPager: @@ -1679,7 +1732,7 @@ def search_grants( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.SearchGrantsPager: r"""``SearchGrants`` returns grants that are related to the calling user in the specified way. @@ -1718,8 +1771,10 @@ def sample_search_grants(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privilegedaccessmanager_v1.services.privileged_access_manager.pagers.SearchGrantsPager: @@ -1777,7 +1832,7 @@ def get_grant( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> privilegedaccessmanager.Grant: r"""Get details of a single grant. @@ -1818,8 +1873,10 @@ def sample_get_grant(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privilegedaccessmanager_v1.types.Grant: @@ -1881,7 +1938,7 @@ def create_grant( grant: Optional[privilegedaccessmanager.Grant] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> privilegedaccessmanager.Grant: r"""Creates a new grant in a given project/folder/organization and location. @@ -1931,8 +1988,10 @@ def sample_create_grant(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privilegedaccessmanager_v1.types.Grant: @@ -1994,7 +2053,7 @@ def approve_grant( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> privilegedaccessmanager.Grant: r"""``ApproveGrant`` is used to approve a grant. This method can only be called on a grant when it's in the ``APPROVAL_AWAITED`` @@ -2032,8 +2091,10 @@ def sample_approve_grant(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privilegedaccessmanager_v1.types.Grant: @@ -2078,7 +2139,7 @@ def deny_grant( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> privilegedaccessmanager.Grant: r"""``DenyGrant`` is used to deny a grant. This method can only be called on a grant when it's in the ``APPROVAL_AWAITED`` state. @@ -2116,8 +2177,10 @@ def sample_deny_grant(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.privilegedaccessmanager_v1.types.Grant: @@ -2164,7 +2227,7 @@ def revoke_grant( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""``RevokeGrant`` is used to immediately revoke access for a grant. This method can be called when the grant is in a @@ -2206,8 +2269,10 @@ def sample_revoke_grant(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -2274,7 +2339,7 @@ def list_operations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Lists operations that match the specified filter in the request. @@ -2285,8 +2350,10 @@ def list_operations( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.ListOperationsResponse: Response message for ``ListOperations`` method. @@ -2327,7 +2394,7 @@ def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -2338,8 +2405,10 @@ def get_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. @@ -2380,7 +2449,7 @@ def delete_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Deletes a long-running operation. @@ -2396,8 +2465,10 @@ def delete_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: None """ @@ -2434,7 +2505,7 @@ def get_location( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.Location: r"""Gets information about a location. @@ -2445,8 +2516,10 @@ def get_location( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.Location: Location object. @@ -2487,7 +2560,7 @@ def list_locations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.ListLocationsResponse: r"""Lists information about the supported locations for this service. @@ -2498,8 +2571,10 @@ def list_locations( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.ListLocationsResponse: Response message for ``ListLocations`` method. diff --git a/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/pagers.py b/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/pagers.py index 4b0d782a15bb..b96b4c1a4b65 100644 --- a/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/pagers.py +++ b/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -81,8 +81,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = privilegedaccessmanager.ListEntitlementsRequest(request) @@ -143,7 +145,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -157,8 +159,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = privilegedaccessmanager.ListEntitlementsRequest(request) @@ -223,7 +227,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -237,8 +241,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = privilegedaccessmanager.SearchEntitlementsRequest(request) @@ -299,7 +305,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -313,8 +319,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = privilegedaccessmanager.SearchEntitlementsRequest(request) @@ -379,7 +387,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -393,8 +401,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = privilegedaccessmanager.ListGrantsRequest(request) @@ -453,7 +463,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -467,8 +477,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = privilegedaccessmanager.ListGrantsRequest(request) @@ -531,7 +543,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -545,8 +557,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = privilegedaccessmanager.SearchGrantsRequest(request) @@ -605,7 +619,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -619,8 +633,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = privilegedaccessmanager.SearchGrantsRequest(request) diff --git a/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/transports/grpc.py b/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/transports/grpc.py index 3fe00b3da1c7..deb639053d46 100644 --- a/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/transports/grpc.py +++ b/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -22,12 +25,90 @@ from google.auth.transport.grpc import SslCredentials # type: ignore from google.cloud.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.privilegedaccessmanager_v1.types import privilegedaccessmanager from .base import DEFAULT_CLIENT_INFO, PrivilegedAccessManagerTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class PrivilegedAccessManagerGrpcTransport(PrivilegedAccessManagerTransport): """gRPC backend transport for PrivilegedAccessManager. @@ -204,7 +285,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -268,7 +354,9 @@ def operations_client(self) -> operations_v1.OperationsClient: """ # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + self._operations_client = operations_v1.OperationsClient( + self._logged_channel + ) # Return the client from cache. return self._operations_client @@ -297,7 +385,7 @@ def check_onboarding_status( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "check_onboarding_status" not in self._stubs: - self._stubs["check_onboarding_status"] = self.grpc_channel.unary_unary( + self._stubs["check_onboarding_status"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/CheckOnboardingStatus", request_serializer=privilegedaccessmanager.CheckOnboardingStatusRequest.serialize, response_deserializer=privilegedaccessmanager.CheckOnboardingStatusResponse.deserialize, @@ -327,7 +415,7 @@ def list_entitlements( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_entitlements" not in self._stubs: - self._stubs["list_entitlements"] = self.grpc_channel.unary_unary( + self._stubs["list_entitlements"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/ListEntitlements", request_serializer=privilegedaccessmanager.ListEntitlementsRequest.serialize, response_deserializer=privilegedaccessmanager.ListEntitlementsResponse.deserialize, @@ -357,7 +445,7 @@ def search_entitlements( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "search_entitlements" not in self._stubs: - self._stubs["search_entitlements"] = self.grpc_channel.unary_unary( + self._stubs["search_entitlements"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/SearchEntitlements", request_serializer=privilegedaccessmanager.SearchEntitlementsRequest.serialize, response_deserializer=privilegedaccessmanager.SearchEntitlementsResponse.deserialize, @@ -386,7 +474,7 @@ def get_entitlement( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_entitlement" not in self._stubs: - self._stubs["get_entitlement"] = self.grpc_channel.unary_unary( + self._stubs["get_entitlement"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/GetEntitlement", request_serializer=privilegedaccessmanager.GetEntitlementRequest.serialize, response_deserializer=privilegedaccessmanager.Entitlement.deserialize, @@ -415,7 +503,7 @@ def create_entitlement( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_entitlement" not in self._stubs: - self._stubs["create_entitlement"] = self.grpc_channel.unary_unary( + self._stubs["create_entitlement"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/CreateEntitlement", request_serializer=privilegedaccessmanager.CreateEntitlementRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -446,7 +534,7 @@ def delete_entitlement( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_entitlement" not in self._stubs: - self._stubs["delete_entitlement"] = self.grpc_channel.unary_unary( + self._stubs["delete_entitlement"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/DeleteEntitlement", request_serializer=privilegedaccessmanager.DeleteEntitlementRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -494,7 +582,7 @@ def update_entitlement( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_entitlement" not in self._stubs: - self._stubs["update_entitlement"] = self.grpc_channel.unary_unary( + self._stubs["update_entitlement"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/UpdateEntitlement", request_serializer=privilegedaccessmanager.UpdateEntitlementRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -523,7 +611,7 @@ def list_grants( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_grants" not in self._stubs: - self._stubs["list_grants"] = self.grpc_channel.unary_unary( + self._stubs["list_grants"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/ListGrants", request_serializer=privilegedaccessmanager.ListGrantsRequest.serialize, response_deserializer=privilegedaccessmanager.ListGrantsResponse.deserialize, @@ -553,7 +641,7 @@ def search_grants( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "search_grants" not in self._stubs: - self._stubs["search_grants"] = self.grpc_channel.unary_unary( + self._stubs["search_grants"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/SearchGrants", request_serializer=privilegedaccessmanager.SearchGrantsRequest.serialize, response_deserializer=privilegedaccessmanager.SearchGrantsResponse.deserialize, @@ -581,7 +669,7 @@ def get_grant( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_grant" not in self._stubs: - self._stubs["get_grant"] = self.grpc_channel.unary_unary( + self._stubs["get_grant"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/GetGrant", request_serializer=privilegedaccessmanager.GetGrantRequest.serialize, response_deserializer=privilegedaccessmanager.Grant.deserialize, @@ -610,7 +698,7 @@ def create_grant( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_grant" not in self._stubs: - self._stubs["create_grant"] = self.grpc_channel.unary_unary( + self._stubs["create_grant"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/CreateGrant", request_serializer=privilegedaccessmanager.CreateGrantRequest.serialize, response_deserializer=privilegedaccessmanager.Grant.deserialize, @@ -640,7 +728,7 @@ def approve_grant( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "approve_grant" not in self._stubs: - self._stubs["approve_grant"] = self.grpc_channel.unary_unary( + self._stubs["approve_grant"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/ApproveGrant", request_serializer=privilegedaccessmanager.ApproveGrantRequest.serialize, response_deserializer=privilegedaccessmanager.Grant.deserialize, @@ -670,7 +758,7 @@ def deny_grant( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "deny_grant" not in self._stubs: - self._stubs["deny_grant"] = self.grpc_channel.unary_unary( + self._stubs["deny_grant"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/DenyGrant", request_serializer=privilegedaccessmanager.DenyGrantRequest.serialize, response_deserializer=privilegedaccessmanager.Grant.deserialize, @@ -700,7 +788,7 @@ def revoke_grant( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "revoke_grant" not in self._stubs: - self._stubs["revoke_grant"] = self.grpc_channel.unary_unary( + self._stubs["revoke_grant"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/RevokeGrant", request_serializer=privilegedaccessmanager.RevokeGrantRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -708,7 +796,7 @@ def revoke_grant( return self._stubs["revoke_grant"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def delete_operation( @@ -720,7 +808,7 @@ def delete_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_operation" not in self._stubs: - self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + self._stubs["delete_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/DeleteOperation", request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, response_deserializer=None, @@ -737,7 +825,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, @@ -756,7 +844,7 @@ def list_operations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_operations" not in self._stubs: - self._stubs["list_operations"] = self.grpc_channel.unary_unary( + self._stubs["list_operations"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/ListOperations", request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, response_deserializer=operations_pb2.ListOperationsResponse.FromString, @@ -775,7 +863,7 @@ def list_locations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_locations" not in self._stubs: - self._stubs["list_locations"] = self.grpc_channel.unary_unary( + self._stubs["list_locations"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/ListLocations", request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, response_deserializer=locations_pb2.ListLocationsResponse.FromString, @@ -792,7 +880,7 @@ def get_location( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_location" not in self._stubs: - self._stubs["get_location"] = self.grpc_channel.unary_unary( + self._stubs["get_location"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/GetLocation", request_serializer=locations_pb2.GetLocationRequest.SerializeToString, response_deserializer=locations_pb2.Location.FromString, diff --git a/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/transports/grpc_asyncio.py b/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/transports/grpc_asyncio.py index 45e3939dc27a..5ffad918023e 100644 --- a/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/transports/grpc_asyncio.py +++ b/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -24,14 +27,93 @@ from google.auth.transport.grpc import SslCredentials # type: ignore from google.cloud.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.privilegedaccessmanager_v1.types import privilegedaccessmanager from .base import DEFAULT_CLIENT_INFO, PrivilegedAccessManagerTransport from .grpc import PrivilegedAccessManagerGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class PrivilegedAccessManagerGrpcAsyncIOTransport(PrivilegedAccessManagerTransport): """gRPC AsyncIO backend transport for PrivilegedAccessManager. @@ -251,10 +333,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -277,7 +362,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel + self._logged_channel ) # Return the client from cache. @@ -307,7 +392,7 @@ def check_onboarding_status( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "check_onboarding_status" not in self._stubs: - self._stubs["check_onboarding_status"] = self.grpc_channel.unary_unary( + self._stubs["check_onboarding_status"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/CheckOnboardingStatus", request_serializer=privilegedaccessmanager.CheckOnboardingStatusRequest.serialize, response_deserializer=privilegedaccessmanager.CheckOnboardingStatusResponse.deserialize, @@ -337,7 +422,7 @@ def list_entitlements( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_entitlements" not in self._stubs: - self._stubs["list_entitlements"] = self.grpc_channel.unary_unary( + self._stubs["list_entitlements"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/ListEntitlements", request_serializer=privilegedaccessmanager.ListEntitlementsRequest.serialize, response_deserializer=privilegedaccessmanager.ListEntitlementsResponse.deserialize, @@ -367,7 +452,7 @@ def search_entitlements( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "search_entitlements" not in self._stubs: - self._stubs["search_entitlements"] = self.grpc_channel.unary_unary( + self._stubs["search_entitlements"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/SearchEntitlements", request_serializer=privilegedaccessmanager.SearchEntitlementsRequest.serialize, response_deserializer=privilegedaccessmanager.SearchEntitlementsResponse.deserialize, @@ -396,7 +481,7 @@ def get_entitlement( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_entitlement" not in self._stubs: - self._stubs["get_entitlement"] = self.grpc_channel.unary_unary( + self._stubs["get_entitlement"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/GetEntitlement", request_serializer=privilegedaccessmanager.GetEntitlementRequest.serialize, response_deserializer=privilegedaccessmanager.Entitlement.deserialize, @@ -426,7 +511,7 @@ def create_entitlement( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_entitlement" not in self._stubs: - self._stubs["create_entitlement"] = self.grpc_channel.unary_unary( + self._stubs["create_entitlement"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/CreateEntitlement", request_serializer=privilegedaccessmanager.CreateEntitlementRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -458,7 +543,7 @@ def delete_entitlement( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_entitlement" not in self._stubs: - self._stubs["delete_entitlement"] = self.grpc_channel.unary_unary( + self._stubs["delete_entitlement"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/DeleteEntitlement", request_serializer=privilegedaccessmanager.DeleteEntitlementRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -507,7 +592,7 @@ def update_entitlement( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_entitlement" not in self._stubs: - self._stubs["update_entitlement"] = self.grpc_channel.unary_unary( + self._stubs["update_entitlement"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/UpdateEntitlement", request_serializer=privilegedaccessmanager.UpdateEntitlementRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -536,7 +621,7 @@ def list_grants( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_grants" not in self._stubs: - self._stubs["list_grants"] = self.grpc_channel.unary_unary( + self._stubs["list_grants"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/ListGrants", request_serializer=privilegedaccessmanager.ListGrantsRequest.serialize, response_deserializer=privilegedaccessmanager.ListGrantsResponse.deserialize, @@ -566,7 +651,7 @@ def search_grants( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "search_grants" not in self._stubs: - self._stubs["search_grants"] = self.grpc_channel.unary_unary( + self._stubs["search_grants"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/SearchGrants", request_serializer=privilegedaccessmanager.SearchGrantsRequest.serialize, response_deserializer=privilegedaccessmanager.SearchGrantsResponse.deserialize, @@ -595,7 +680,7 @@ def get_grant( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_grant" not in self._stubs: - self._stubs["get_grant"] = self.grpc_channel.unary_unary( + self._stubs["get_grant"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/GetGrant", request_serializer=privilegedaccessmanager.GetGrantRequest.serialize, response_deserializer=privilegedaccessmanager.Grant.deserialize, @@ -625,7 +710,7 @@ def create_grant( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_grant" not in self._stubs: - self._stubs["create_grant"] = self.grpc_channel.unary_unary( + self._stubs["create_grant"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/CreateGrant", request_serializer=privilegedaccessmanager.CreateGrantRequest.serialize, response_deserializer=privilegedaccessmanager.Grant.deserialize, @@ -656,7 +741,7 @@ def approve_grant( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "approve_grant" not in self._stubs: - self._stubs["approve_grant"] = self.grpc_channel.unary_unary( + self._stubs["approve_grant"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/ApproveGrant", request_serializer=privilegedaccessmanager.ApproveGrantRequest.serialize, response_deserializer=privilegedaccessmanager.Grant.deserialize, @@ -687,7 +772,7 @@ def deny_grant( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "deny_grant" not in self._stubs: - self._stubs["deny_grant"] = self.grpc_channel.unary_unary( + self._stubs["deny_grant"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/DenyGrant", request_serializer=privilegedaccessmanager.DenyGrantRequest.serialize, response_deserializer=privilegedaccessmanager.Grant.deserialize, @@ -718,7 +803,7 @@ def revoke_grant( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "revoke_grant" not in self._stubs: - self._stubs["revoke_grant"] = self.grpc_channel.unary_unary( + self._stubs["revoke_grant"] = self._logged_channel.unary_unary( "/google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager/RevokeGrant", request_serializer=privilegedaccessmanager.RevokeGrantRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -831,7 +916,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: @@ -847,7 +932,7 @@ def delete_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_operation" not in self._stubs: - self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + self._stubs["delete_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/DeleteOperation", request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, response_deserializer=None, @@ -864,7 +949,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, @@ -883,7 +968,7 @@ def list_operations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_operations" not in self._stubs: - self._stubs["list_operations"] = self.grpc_channel.unary_unary( + self._stubs["list_operations"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/ListOperations", request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, response_deserializer=operations_pb2.ListOperationsResponse.FromString, @@ -902,7 +987,7 @@ def list_locations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_locations" not in self._stubs: - self._stubs["list_locations"] = self.grpc_channel.unary_unary( + self._stubs["list_locations"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/ListLocations", request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, response_deserializer=locations_pb2.ListLocationsResponse.FromString, @@ -919,7 +1004,7 @@ def get_location( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_location" not in self._stubs: - self._stubs["get_location"] = self.grpc_channel.unary_unary( + self._stubs["get_location"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/GetLocation", request_serializer=locations_pb2.GetLocationRequest.SerializeToString, response_deserializer=locations_pb2.Location.FromString, diff --git a/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/transports/rest.py b/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/transports/rest.py index 24e42650091b..2b62bc33daac 100644 --- a/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/transports/rest.py +++ b/packages/google-cloud-privilegedaccessmanager/google/cloud/privilegedaccessmanager_v1/services/privileged_access_manager/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -39,6 +39,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -183,8 +191,11 @@ def post_update_entitlement(self, response): def pre_approve_grant( self, request: privilegedaccessmanager.ApproveGrantRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[privilegedaccessmanager.ApproveGrantRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + privilegedaccessmanager.ApproveGrantRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for approve_grant Override in a subclass to manipulate the request or metadata @@ -206,9 +217,10 @@ def post_approve_grant( def pre_check_onboarding_status( self, request: privilegedaccessmanager.CheckOnboardingStatusRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - privilegedaccessmanager.CheckOnboardingStatusRequest, Sequence[Tuple[str, str]] + privilegedaccessmanager.CheckOnboardingStatusRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for check_onboarding_status @@ -231,9 +243,10 @@ def post_check_onboarding_status( def pre_create_entitlement( self, request: privilegedaccessmanager.CreateEntitlementRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - privilegedaccessmanager.CreateEntitlementRequest, Sequence[Tuple[str, str]] + privilegedaccessmanager.CreateEntitlementRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for create_entitlement @@ -256,8 +269,11 @@ def post_create_entitlement( def pre_create_grant( self, request: privilegedaccessmanager.CreateGrantRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[privilegedaccessmanager.CreateGrantRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + privilegedaccessmanager.CreateGrantRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for create_grant Override in a subclass to manipulate the request or metadata @@ -279,9 +295,10 @@ def post_create_grant( def pre_delete_entitlement( self, request: privilegedaccessmanager.DeleteEntitlementRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - privilegedaccessmanager.DeleteEntitlementRequest, Sequence[Tuple[str, str]] + privilegedaccessmanager.DeleteEntitlementRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for delete_entitlement @@ -304,8 +321,11 @@ def post_delete_entitlement( def pre_deny_grant( self, request: privilegedaccessmanager.DenyGrantRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[privilegedaccessmanager.DenyGrantRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + privilegedaccessmanager.DenyGrantRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for deny_grant Override in a subclass to manipulate the request or metadata @@ -327,9 +347,10 @@ def post_deny_grant( def pre_get_entitlement( self, request: privilegedaccessmanager.GetEntitlementRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - privilegedaccessmanager.GetEntitlementRequest, Sequence[Tuple[str, str]] + privilegedaccessmanager.GetEntitlementRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for get_entitlement @@ -352,8 +373,10 @@ def post_get_entitlement( def pre_get_grant( self, request: privilegedaccessmanager.GetGrantRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[privilegedaccessmanager.GetGrantRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + privilegedaccessmanager.GetGrantRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_grant Override in a subclass to manipulate the request or metadata @@ -375,9 +398,10 @@ def post_get_grant( def pre_list_entitlements( self, request: privilegedaccessmanager.ListEntitlementsRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - privilegedaccessmanager.ListEntitlementsRequest, Sequence[Tuple[str, str]] + privilegedaccessmanager.ListEntitlementsRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for list_entitlements @@ -400,8 +424,11 @@ def post_list_entitlements( def pre_list_grants( self, request: privilegedaccessmanager.ListGrantsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[privilegedaccessmanager.ListGrantsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + privilegedaccessmanager.ListGrantsRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for list_grants Override in a subclass to manipulate the request or metadata @@ -423,8 +450,11 @@ def post_list_grants( def pre_revoke_grant( self, request: privilegedaccessmanager.RevokeGrantRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[privilegedaccessmanager.RevokeGrantRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + privilegedaccessmanager.RevokeGrantRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for revoke_grant Override in a subclass to manipulate the request or metadata @@ -446,9 +476,10 @@ def post_revoke_grant( def pre_search_entitlements( self, request: privilegedaccessmanager.SearchEntitlementsRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - privilegedaccessmanager.SearchEntitlementsRequest, Sequence[Tuple[str, str]] + privilegedaccessmanager.SearchEntitlementsRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for search_entitlements @@ -471,8 +502,11 @@ def post_search_entitlements( def pre_search_grants( self, request: privilegedaccessmanager.SearchGrantsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[privilegedaccessmanager.SearchGrantsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + privilegedaccessmanager.SearchGrantsRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for search_grants Override in a subclass to manipulate the request or metadata @@ -494,9 +528,10 @@ def post_search_grants( def pre_update_entitlement( self, request: privilegedaccessmanager.UpdateEntitlementRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - privilegedaccessmanager.UpdateEntitlementRequest, Sequence[Tuple[str, str]] + privilegedaccessmanager.UpdateEntitlementRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for update_entitlement @@ -519,8 +554,10 @@ def post_update_entitlement( def pre_get_location( self, request: locations_pb2.GetLocationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[locations_pb2.GetLocationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + locations_pb2.GetLocationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_location Override in a subclass to manipulate the request or metadata @@ -542,8 +579,10 @@ def post_get_location( def pre_list_locations( self, request: locations_pb2.ListLocationsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[locations_pb2.ListLocationsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + locations_pb2.ListLocationsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_locations Override in a subclass to manipulate the request or metadata @@ -565,8 +604,10 @@ def post_list_locations( def pre_delete_operation( self, request: operations_pb2.DeleteOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.DeleteOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.DeleteOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for delete_operation Override in a subclass to manipulate the request or metadata @@ -586,8 +627,10 @@ def post_delete_operation(self, response: None) -> None: def pre_get_operation( self, request: operations_pb2.GetOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.GetOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.GetOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_operation Override in a subclass to manipulate the request or metadata @@ -609,8 +652,10 @@ def post_get_operation( def pre_list_operations( self, request: operations_pb2.ListOperationsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.ListOperationsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.ListOperationsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_operations Override in a subclass to manipulate the request or metadata @@ -845,7 +890,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> privilegedaccessmanager.Grant: r"""Call the approve grant method over HTTP. @@ -855,8 +900,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.privilegedaccessmanager.Grant: @@ -869,6 +916,7 @@ def __call__( http_options = ( _BasePrivilegedAccessManagerRestTransport._BaseApproveGrant._get_http_options() ) + request, metadata = self._interceptor.pre_approve_grant(request, metadata) transcoded_request = _BasePrivilegedAccessManagerRestTransport._BaseApproveGrant._get_transcoded_request( http_options, request @@ -883,6 +931,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.ApproveGrant", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "ApproveGrant", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = PrivilegedAccessManagerRestTransport._ApproveGrant._get_response( self._host, @@ -904,7 +979,29 @@ def __call__( pb_resp = privilegedaccessmanager.Grant.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_approve_grant(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = privilegedaccessmanager.Grant.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.approve_grant", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "ApproveGrant", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _CheckOnboardingStatus( @@ -942,7 +1039,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> privilegedaccessmanager.CheckOnboardingStatusResponse: r"""Call the check onboarding status method over HTTP. @@ -952,8 +1049,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.privilegedaccessmanager.CheckOnboardingStatusResponse: @@ -963,6 +1062,7 @@ def __call__( http_options = ( _BasePrivilegedAccessManagerRestTransport._BaseCheckOnboardingStatus._get_http_options() ) + request, metadata = self._interceptor.pre_check_onboarding_status( request, metadata ) @@ -975,6 +1075,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.CheckOnboardingStatus", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "CheckOnboardingStatus", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = PrivilegedAccessManagerRestTransport._CheckOnboardingStatus._get_response( self._host, @@ -995,7 +1122,33 @@ def __call__( pb_resp = privilegedaccessmanager.CheckOnboardingStatusResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_check_onboarding_status(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + privilegedaccessmanager.CheckOnboardingStatusResponse.to_json( + response + ) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.check_onboarding_status", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "CheckOnboardingStatus", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _CreateEntitlement( @@ -1034,7 +1187,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the create entitlement method over HTTP. @@ -1044,8 +1197,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1058,6 +1213,7 @@ def __call__( http_options = ( _BasePrivilegedAccessManagerRestTransport._BaseCreateEntitlement._get_http_options() ) + request, metadata = self._interceptor.pre_create_entitlement( request, metadata ) @@ -1074,6 +1230,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.CreateEntitlement", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "CreateEntitlement", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( PrivilegedAccessManagerRestTransport._CreateEntitlement._get_response( @@ -1095,7 +1278,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_entitlement(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.create_entitlement", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "CreateEntitlement", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _CreateGrant( @@ -1134,7 +1339,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> privilegedaccessmanager.Grant: r"""Call the create grant method over HTTP. @@ -1144,8 +1349,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.privilegedaccessmanager.Grant: @@ -1158,6 +1365,7 @@ def __call__( http_options = ( _BasePrivilegedAccessManagerRestTransport._BaseCreateGrant._get_http_options() ) + request, metadata = self._interceptor.pre_create_grant(request, metadata) transcoded_request = _BasePrivilegedAccessManagerRestTransport._BaseCreateGrant._get_transcoded_request( http_options, request @@ -1172,6 +1380,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.CreateGrant", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "CreateGrant", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = PrivilegedAccessManagerRestTransport._CreateGrant._get_response( self._host, @@ -1193,7 +1428,29 @@ def __call__( pb_resp = privilegedaccessmanager.Grant.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_grant(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = privilegedaccessmanager.Grant.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.create_grant", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "CreateGrant", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DeleteEntitlement( @@ -1231,7 +1488,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the delete entitlement method over HTTP. @@ -1241,8 +1498,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1255,6 +1514,7 @@ def __call__( http_options = ( _BasePrivilegedAccessManagerRestTransport._BaseDeleteEntitlement._get_http_options() ) + request, metadata = self._interceptor.pre_delete_entitlement( request, metadata ) @@ -1267,6 +1527,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.DeleteEntitlement", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "DeleteEntitlement", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( PrivilegedAccessManagerRestTransport._DeleteEntitlement._get_response( @@ -1287,7 +1574,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_delete_entitlement(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.delete_entitlement", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "DeleteEntitlement", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DenyGrant( @@ -1326,7 +1635,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> privilegedaccessmanager.Grant: r"""Call the deny grant method over HTTP. @@ -1336,8 +1645,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.privilegedaccessmanager.Grant: @@ -1350,6 +1661,7 @@ def __call__( http_options = ( _BasePrivilegedAccessManagerRestTransport._BaseDenyGrant._get_http_options() ) + request, metadata = self._interceptor.pre_deny_grant(request, metadata) transcoded_request = _BasePrivilegedAccessManagerRestTransport._BaseDenyGrant._get_transcoded_request( http_options, request @@ -1364,6 +1676,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.DenyGrant", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "DenyGrant", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = PrivilegedAccessManagerRestTransport._DenyGrant._get_response( self._host, @@ -1385,7 +1724,29 @@ def __call__( pb_resp = privilegedaccessmanager.Grant.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_deny_grant(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = privilegedaccessmanager.Grant.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.deny_grant", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "DenyGrant", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetEntitlement( @@ -1423,7 +1784,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> privilegedaccessmanager.Entitlement: r"""Call the get entitlement method over HTTP. @@ -1433,8 +1794,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.privilegedaccessmanager.Entitlement: @@ -1449,6 +1812,7 @@ def __call__( http_options = ( _BasePrivilegedAccessManagerRestTransport._BaseGetEntitlement._get_http_options() ) + request, metadata = self._interceptor.pre_get_entitlement(request, metadata) transcoded_request = _BasePrivilegedAccessManagerRestTransport._BaseGetEntitlement._get_transcoded_request( http_options, request @@ -1459,6 +1823,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.GetEntitlement", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "GetEntitlement", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( PrivilegedAccessManagerRestTransport._GetEntitlement._get_response( @@ -1481,7 +1872,31 @@ def __call__( pb_resp = privilegedaccessmanager.Entitlement.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_entitlement(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = privilegedaccessmanager.Entitlement.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.get_entitlement", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "GetEntitlement", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetGrant( @@ -1519,7 +1934,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> privilegedaccessmanager.Grant: r"""Call the get grant method over HTTP. @@ -1529,8 +1944,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.privilegedaccessmanager.Grant: @@ -1543,6 +1960,7 @@ def __call__( http_options = ( _BasePrivilegedAccessManagerRestTransport._BaseGetGrant._get_http_options() ) + request, metadata = self._interceptor.pre_get_grant(request, metadata) transcoded_request = _BasePrivilegedAccessManagerRestTransport._BaseGetGrant._get_transcoded_request( http_options, request @@ -1553,6 +1971,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.GetGrant", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "GetGrant", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = PrivilegedAccessManagerRestTransport._GetGrant._get_response( self._host, @@ -1573,7 +2018,29 @@ def __call__( pb_resp = privilegedaccessmanager.Grant.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_grant(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = privilegedaccessmanager.Grant.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.get_grant", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "GetGrant", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListEntitlements( @@ -1611,7 +2078,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> privilegedaccessmanager.ListEntitlementsResponse: r"""Call the list entitlements method over HTTP. @@ -1622,8 +2089,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.privilegedaccessmanager.ListEntitlementsResponse: @@ -1635,6 +2104,7 @@ def __call__( http_options = ( _BasePrivilegedAccessManagerRestTransport._BaseListEntitlements._get_http_options() ) + request, metadata = self._interceptor.pre_list_entitlements( request, metadata ) @@ -1647,6 +2117,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.ListEntitlements", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "ListEntitlements", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( PrivilegedAccessManagerRestTransport._ListEntitlements._get_response( @@ -1669,7 +2166,33 @@ def __call__( pb_resp = privilegedaccessmanager.ListEntitlementsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_entitlements(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + privilegedaccessmanager.ListEntitlementsResponse.to_json( + response + ) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.list_entitlements", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "ListEntitlements", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListGrants( @@ -1707,7 +2230,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> privilegedaccessmanager.ListGrantsResponse: r"""Call the list grants method over HTTP. @@ -1718,8 +2241,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.privilegedaccessmanager.ListGrantsResponse: @@ -1731,6 +2256,7 @@ def __call__( http_options = ( _BasePrivilegedAccessManagerRestTransport._BaseListGrants._get_http_options() ) + request, metadata = self._interceptor.pre_list_grants(request, metadata) transcoded_request = _BasePrivilegedAccessManagerRestTransport._BaseListGrants._get_transcoded_request( http_options, request @@ -1741,6 +2267,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.ListGrants", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "ListGrants", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = PrivilegedAccessManagerRestTransport._ListGrants._get_response( self._host, @@ -1761,7 +2314,31 @@ def __call__( pb_resp = privilegedaccessmanager.ListGrantsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_grants(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + privilegedaccessmanager.ListGrantsResponse.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.list_grants", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "ListGrants", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _RevokeGrant( @@ -1800,7 +2377,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the revoke grant method over HTTP. @@ -1810,8 +2387,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1824,6 +2403,7 @@ def __call__( http_options = ( _BasePrivilegedAccessManagerRestTransport._BaseRevokeGrant._get_http_options() ) + request, metadata = self._interceptor.pre_revoke_grant(request, metadata) transcoded_request = _BasePrivilegedAccessManagerRestTransport._BaseRevokeGrant._get_transcoded_request( http_options, request @@ -1838,6 +2418,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.RevokeGrant", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "RevokeGrant", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = PrivilegedAccessManagerRestTransport._RevokeGrant._get_response( self._host, @@ -1857,7 +2464,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_revoke_grant(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.revoke_grant", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "RevokeGrant", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _SearchEntitlements( @@ -1895,7 +2524,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> privilegedaccessmanager.SearchEntitlementsResponse: r"""Call the search entitlements method over HTTP. @@ -1905,8 +2534,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.privilegedaccessmanager.SearchEntitlementsResponse: @@ -1916,6 +2547,7 @@ def __call__( http_options = ( _BasePrivilegedAccessManagerRestTransport._BaseSearchEntitlements._get_http_options() ) + request, metadata = self._interceptor.pre_search_entitlements( request, metadata ) @@ -1928,6 +2560,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.SearchEntitlements", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "SearchEntitlements", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( PrivilegedAccessManagerRestTransport._SearchEntitlements._get_response( @@ -1950,7 +2609,33 @@ def __call__( pb_resp = privilegedaccessmanager.SearchEntitlementsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_search_entitlements(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + privilegedaccessmanager.SearchEntitlementsResponse.to_json( + response + ) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.search_entitlements", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "SearchEntitlements", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _SearchGrants( @@ -1988,7 +2673,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> privilegedaccessmanager.SearchGrantsResponse: r"""Call the search grants method over HTTP. @@ -1998,8 +2683,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.privilegedaccessmanager.SearchGrantsResponse: @@ -2009,6 +2696,7 @@ def __call__( http_options = ( _BasePrivilegedAccessManagerRestTransport._BaseSearchGrants._get_http_options() ) + request, metadata = self._interceptor.pre_search_grants(request, metadata) transcoded_request = _BasePrivilegedAccessManagerRestTransport._BaseSearchGrants._get_transcoded_request( http_options, request @@ -2019,6 +2707,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.SearchGrants", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "SearchGrants", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = PrivilegedAccessManagerRestTransport._SearchGrants._get_response( self._host, @@ -2039,7 +2754,31 @@ def __call__( pb_resp = privilegedaccessmanager.SearchGrantsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_search_grants(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + privilegedaccessmanager.SearchGrantsResponse.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.search_grants", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "SearchGrants", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateEntitlement( @@ -2078,7 +2817,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the update entitlement method over HTTP. @@ -2088,8 +2827,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -2102,6 +2843,7 @@ def __call__( http_options = ( _BasePrivilegedAccessManagerRestTransport._BaseUpdateEntitlement._get_http_options() ) + request, metadata = self._interceptor.pre_update_entitlement( request, metadata ) @@ -2118,6 +2860,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.UpdateEntitlement", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "UpdateEntitlement", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( PrivilegedAccessManagerRestTransport._UpdateEntitlement._get_response( @@ -2139,7 +2908,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_entitlement(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.update_entitlement", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "UpdateEntitlement", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property @@ -2327,7 +3118,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.Location: r"""Call the get location method over HTTP. @@ -2337,8 +3128,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: locations_pb2.Location: Response from GetLocation method. @@ -2347,6 +3140,7 @@ def __call__( http_options = ( _BasePrivilegedAccessManagerRestTransport._BaseGetLocation._get_http_options() ) + request, metadata = self._interceptor.pre_get_location(request, metadata) transcoded_request = _BasePrivilegedAccessManagerRestTransport._BaseGetLocation._get_transcoded_request( http_options, request @@ -2357,6 +3151,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.GetLocation", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "GetLocation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = PrivilegedAccessManagerRestTransport._GetLocation._get_response( self._host, @@ -2376,6 +3197,27 @@ def __call__( resp = locations_pb2.Location() resp = json_format.Parse(content, resp) resp = self._interceptor.post_get_location(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerAsyncClient.GetLocation", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "GetLocation", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property @@ -2417,7 +3259,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.ListLocationsResponse: r"""Call the list locations method over HTTP. @@ -2427,8 +3269,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: locations_pb2.ListLocationsResponse: Response from ListLocations method. @@ -2437,6 +3281,7 @@ def __call__( http_options = ( _BasePrivilegedAccessManagerRestTransport._BaseListLocations._get_http_options() ) + request, metadata = self._interceptor.pre_list_locations(request, metadata) transcoded_request = _BasePrivilegedAccessManagerRestTransport._BaseListLocations._get_transcoded_request( http_options, request @@ -2447,6 +3292,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.ListLocations", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "ListLocations", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( PrivilegedAccessManagerRestTransport._ListLocations._get_response( @@ -2468,6 +3340,27 @@ def __call__( resp = locations_pb2.ListLocationsResponse() resp = json_format.Parse(content, resp) resp = self._interceptor.post_list_locations(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerAsyncClient.ListLocations", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "ListLocations", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property @@ -2509,7 +3402,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Call the delete operation method over HTTP. @@ -2519,13 +3412,16 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ http_options = ( _BasePrivilegedAccessManagerRestTransport._BaseDeleteOperation._get_http_options() ) + request, metadata = self._interceptor.pre_delete_operation( request, metadata ) @@ -2538,6 +3434,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.DeleteOperation", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "DeleteOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( PrivilegedAccessManagerRestTransport._DeleteOperation._get_response( @@ -2596,7 +3519,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the get operation method over HTTP. @@ -2606,8 +3529,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: operations_pb2.Operation: Response from GetOperation method. @@ -2616,6 +3541,7 @@ def __call__( http_options = ( _BasePrivilegedAccessManagerRestTransport._BaseGetOperation._get_http_options() ) + request, metadata = self._interceptor.pre_get_operation(request, metadata) transcoded_request = _BasePrivilegedAccessManagerRestTransport._BaseGetOperation._get_transcoded_request( http_options, request @@ -2626,6 +3552,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.GetOperation", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "GetOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = PrivilegedAccessManagerRestTransport._GetOperation._get_response( self._host, @@ -2645,6 +3598,27 @@ def __call__( resp = operations_pb2.Operation() resp = json_format.Parse(content, resp) resp = self._interceptor.post_get_operation(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerAsyncClient.GetOperation", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "GetOperation", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property @@ -2686,7 +3660,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Call the list operations method over HTTP. @@ -2696,8 +3670,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: operations_pb2.ListOperationsResponse: Response from ListOperations method. @@ -2706,6 +3682,7 @@ def __call__( http_options = ( _BasePrivilegedAccessManagerRestTransport._BaseListOperations._get_http_options() ) + request, metadata = self._interceptor.pre_list_operations(request, metadata) transcoded_request = _BasePrivilegedAccessManagerRestTransport._BaseListOperations._get_transcoded_request( http_options, request @@ -2716,6 +3693,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerClient.ListOperations", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "ListOperations", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( PrivilegedAccessManagerRestTransport._ListOperations._get_response( @@ -2737,6 +3741,27 @@ def __call__( resp = operations_pb2.ListOperationsResponse() resp = json_format.Parse(content, resp) resp = self._interceptor.post_list_operations(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.privilegedaccessmanager_v1.PrivilegedAccessManagerAsyncClient.ListOperations", + extra={ + "serviceName": "google.cloud.privilegedaccessmanager.v1.PrivilegedAccessManager", + "rpcName": "ListOperations", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property diff --git a/packages/google-cloud-privilegedaccessmanager/samples/generated_samples/snippet_metadata_google.cloud.privilegedaccessmanager.v1.json b/packages/google-cloud-privilegedaccessmanager/samples/generated_samples/snippet_metadata_google.cloud.privilegedaccessmanager.v1.json index d0669a1a26be..ec4443c5cbc9 100644 --- a/packages/google-cloud-privilegedaccessmanager/samples/generated_samples/snippet_metadata_google.cloud.privilegedaccessmanager.v1.json +++ b/packages/google-cloud-privilegedaccessmanager/samples/generated_samples/snippet_metadata_google.cloud.privilegedaccessmanager.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-privilegedaccessmanager", - "version": "0.1.4" + "version": "0.1.0" }, "snippets": [ { @@ -43,7 +43,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privilegedaccessmanager_v1.types.Grant", @@ -119,7 +119,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privilegedaccessmanager_v1.types.Grant", @@ -196,7 +196,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privilegedaccessmanager_v1.types.CheckOnboardingStatusResponse", @@ -272,7 +272,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privilegedaccessmanager_v1.types.CheckOnboardingStatusResponse", @@ -361,7 +361,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -449,7 +449,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -534,7 +534,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privilegedaccessmanager_v1.types.Grant", @@ -618,7 +618,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privilegedaccessmanager_v1.types.Grant", @@ -699,7 +699,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -779,7 +779,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -856,7 +856,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privilegedaccessmanager_v1.types.Grant", @@ -932,7 +932,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privilegedaccessmanager_v1.types.Grant", @@ -1013,7 +1013,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privilegedaccessmanager_v1.types.Entitlement", @@ -1093,7 +1093,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privilegedaccessmanager_v1.types.Entitlement", @@ -1174,7 +1174,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privilegedaccessmanager_v1.types.Grant", @@ -1254,7 +1254,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privilegedaccessmanager_v1.types.Grant", @@ -1335,7 +1335,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privilegedaccessmanager_v1.services.privileged_access_manager.pagers.ListEntitlementsAsyncPager", @@ -1415,7 +1415,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privilegedaccessmanager_v1.services.privileged_access_manager.pagers.ListEntitlementsPager", @@ -1496,7 +1496,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privilegedaccessmanager_v1.services.privileged_access_manager.pagers.ListGrantsAsyncPager", @@ -1576,7 +1576,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privilegedaccessmanager_v1.services.privileged_access_manager.pagers.ListGrantsPager", @@ -1653,7 +1653,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -1729,7 +1729,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -1806,7 +1806,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privilegedaccessmanager_v1.services.privileged_access_manager.pagers.SearchEntitlementsAsyncPager", @@ -1882,7 +1882,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privilegedaccessmanager_v1.services.privileged_access_manager.pagers.SearchEntitlementsPager", @@ -1959,7 +1959,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privilegedaccessmanager_v1.services.privileged_access_manager.pagers.SearchGrantsAsyncPager", @@ -2035,7 +2035,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.privilegedaccessmanager_v1.services.privileged_access_manager.pagers.SearchGrantsPager", @@ -2120,7 +2120,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -2204,7 +2204,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", diff --git a/packages/google-cloud-privilegedaccessmanager/tests/unit/gapic/privilegedaccessmanager_v1/test_privileged_access_manager.py b/packages/google-cloud-privilegedaccessmanager/tests/unit/gapic/privilegedaccessmanager_v1/test_privileged_access_manager.py index 177fb1aafa84..b1aad649ba00 100644 --- a/packages/google-cloud-privilegedaccessmanager/tests/unit/gapic/privilegedaccessmanager_v1/test_privileged_access_manager.py +++ b/packages/google-cloud-privilegedaccessmanager/tests/unit/gapic/privilegedaccessmanager_v1/test_privileged_access_manager.py @@ -6350,6 +6350,7 @@ def test_check_onboarding_status_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.check_onboarding_status(request) @@ -6482,6 +6483,7 @@ def test_list_entitlements_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_entitlements(request) @@ -6537,6 +6539,7 @@ def test_list_entitlements_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_entitlements(**mock_args) @@ -6747,6 +6750,7 @@ def test_search_entitlements_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.search_entitlements(request) @@ -6945,6 +6949,7 @@ def test_get_entitlement_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_entitlement(request) @@ -6992,6 +6997,7 @@ def test_get_entitlement_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_entitlement(**mock_args) @@ -7143,6 +7149,7 @@ def test_create_entitlement_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_entitlement(request) @@ -7208,6 +7215,7 @@ def test_create_entitlement_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_entitlement(**mock_args) @@ -7353,6 +7361,7 @@ def test_delete_entitlement_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_entitlement(request) @@ -7406,6 +7415,7 @@ def test_delete_entitlement_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_entitlement(**mock_args) @@ -7540,6 +7550,7 @@ def test_update_entitlement_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_entitlement(request) @@ -7596,6 +7607,7 @@ def test_update_entitlement_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_entitlement(**mock_args) @@ -7737,6 +7749,7 @@ def test_list_grants_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_grants(request) @@ -7794,6 +7807,7 @@ def test_list_grants_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_grants(**mock_args) @@ -7999,6 +8013,7 @@ def test_search_grants_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.search_grants(request) @@ -8198,6 +8213,7 @@ def test_get_grant_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_grant(request) @@ -8245,6 +8261,7 @@ def test_get_grant_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_grant(**mock_args) @@ -8379,6 +8396,7 @@ def test_create_grant_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_grant(request) @@ -8435,6 +8453,7 @@ def test_create_grant_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_grant(**mock_args) @@ -8568,6 +8587,7 @@ def test_approve_grant_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.approve_grant(request) @@ -8688,6 +8708,7 @@ def test_deny_grant_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.deny_grant(request) @@ -8809,6 +8830,7 @@ def test_revoke_grant_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.revoke_grant(request) @@ -9682,6 +9704,7 @@ def test_check_onboarding_status_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.check_onboarding_status(request) @@ -9719,6 +9742,7 @@ def test_check_onboarding_status_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.check_onboarding_status(request) # Establish that the response is the type that we expect. @@ -9760,6 +9784,7 @@ def test_check_onboarding_status_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = privilegedaccessmanager.CheckOnboardingStatusResponse.to_json( privilegedaccessmanager.CheckOnboardingStatusResponse() ) @@ -9806,6 +9831,7 @@ def test_list_entitlements_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_entitlements(request) @@ -9842,6 +9868,7 @@ def test_list_entitlements_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_entitlements(request) # Establish that the response is the type that we expect. @@ -9883,6 +9910,7 @@ def test_list_entitlements_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = privilegedaccessmanager.ListEntitlementsResponse.to_json( privilegedaccessmanager.ListEntitlementsResponse() ) @@ -9929,6 +9957,7 @@ def test_search_entitlements_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.search_entitlements(request) @@ -9966,6 +9995,7 @@ def test_search_entitlements_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.search_entitlements(request) # Establish that the response is the type that we expect. @@ -10006,6 +10036,7 @@ def test_search_entitlements_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = privilegedaccessmanager.SearchEntitlementsResponse.to_json( privilegedaccessmanager.SearchEntitlementsResponse() ) @@ -10052,6 +10083,7 @@ def test_get_entitlement_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_entitlement(request) @@ -10089,6 +10121,7 @@ def test_get_entitlement_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_entitlement(request) # Establish that the response is the type that we expect. @@ -10131,6 +10164,7 @@ def test_get_entitlement_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = privilegedaccessmanager.Entitlement.to_json( privilegedaccessmanager.Entitlement() ) @@ -10177,6 +10211,7 @@ def test_create_entitlement_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_entitlement(request) @@ -10323,6 +10358,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_entitlement(request) # Establish that the response is the type that we expect. @@ -10364,6 +10400,7 @@ def test_create_entitlement_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -10408,6 +10445,7 @@ def test_delete_entitlement_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_entitlement(request) @@ -10438,6 +10476,7 @@ def test_delete_entitlement_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_entitlement(request) # Establish that the response is the type that we expect. @@ -10479,6 +10518,7 @@ def test_delete_entitlement_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -10527,6 +10567,7 @@ def test_update_entitlement_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_entitlement(request) @@ -10677,6 +10718,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_entitlement(request) # Establish that the response is the type that we expect. @@ -10718,6 +10760,7 @@ def test_update_entitlement_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -10762,6 +10805,7 @@ def test_list_grants_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_grants(request) @@ -10798,6 +10842,7 @@ def test_list_grants_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_grants(request) # Establish that the response is the type that we expect. @@ -10839,6 +10884,7 @@ def test_list_grants_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = privilegedaccessmanager.ListGrantsResponse.to_json( privilegedaccessmanager.ListGrantsResponse() ) @@ -10885,6 +10931,7 @@ def test_search_grants_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.search_grants(request) @@ -10920,6 +10967,7 @@ def test_search_grants_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.search_grants(request) # Establish that the response is the type that we expect. @@ -10960,6 +11008,7 @@ def test_search_grants_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = privilegedaccessmanager.SearchGrantsResponse.to_json( privilegedaccessmanager.SearchGrantsResponse() ) @@ -11008,6 +11057,7 @@ def test_get_grant_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_grant(request) @@ -11049,6 +11099,7 @@ def test_get_grant_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_grant(request) # Establish that the response is the type that we expect. @@ -11093,6 +11144,7 @@ def test_get_grant_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = privilegedaccessmanager.Grant.to_json( privilegedaccessmanager.Grant() ) @@ -11139,6 +11191,7 @@ def test_create_grant_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_grant(request) @@ -11302,6 +11355,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_grant(request) # Establish that the response is the type that we expect. @@ -11346,6 +11400,7 @@ def test_create_grant_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = privilegedaccessmanager.Grant.to_json( privilegedaccessmanager.Grant() ) @@ -11394,6 +11449,7 @@ def test_approve_grant_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.approve_grant(request) @@ -11435,6 +11491,7 @@ def test_approve_grant_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.approve_grant(request) # Establish that the response is the type that we expect. @@ -11479,6 +11536,7 @@ def test_approve_grant_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = privilegedaccessmanager.Grant.to_json( privilegedaccessmanager.Grant() ) @@ -11527,6 +11585,7 @@ def test_deny_grant_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.deny_grant(request) @@ -11568,6 +11627,7 @@ def test_deny_grant_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.deny_grant(request) # Establish that the response is the type that we expect. @@ -11612,6 +11672,7 @@ def test_deny_grant_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = privilegedaccessmanager.Grant.to_json( privilegedaccessmanager.Grant() ) @@ -11660,6 +11721,7 @@ def test_revoke_grant_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.revoke_grant(request) @@ -11692,6 +11754,7 @@ def test_revoke_grant_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.revoke_grant(request) # Establish that the response is the type that we expect. @@ -11733,6 +11796,7 @@ def test_revoke_grant_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -11777,6 +11841,7 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_location(request) @@ -11807,6 +11872,7 @@ def test_get_location_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_location(request) @@ -11835,6 +11901,7 @@ def test_list_locations_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_locations(request) @@ -11865,6 +11932,7 @@ def test_list_locations_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_locations(request) @@ -11895,6 +11963,7 @@ def test_delete_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_operation(request) @@ -11925,6 +11994,7 @@ def test_delete_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_operation(request) @@ -11955,6 +12025,7 @@ def test_get_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_operation(request) @@ -11985,6 +12056,7 @@ def test_get_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_operation(request) @@ -12015,6 +12087,7 @@ def test_list_operations_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_operations(request) @@ -12045,6 +12118,7 @@ def test_list_operations_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_operations(request) diff --git a/packages/google-cloud-public-ca/google/cloud/security/publicca/gapic_version.py b/packages/google-cloud-public-ca/google/cloud/security/publicca/gapic_version.py index 0106eadcd8d9..558c8aab67c5 100644 --- a/packages/google-cloud-public-ca/google/cloud/security/publicca/gapic_version.py +++ b/packages/google-cloud-public-ca/google/cloud/security/publicca/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.3.14" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/gapic_version.py b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/gapic_version.py index 0106eadcd8d9..558c8aab67c5 100644 --- a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/gapic_version.py +++ b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.3.14" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/services/public_certificate_authority_service/async_client.py b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/services/public_certificate_authority_service/async_client.py index 3952f79569de..fd3a698d969f 100644 --- a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/services/public_certificate_authority_service/async_client.py +++ b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/services/public_certificate_authority_service/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -53,6 +54,15 @@ PublicCertificateAuthorityServiceGrpcAsyncIOTransport, ) +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class PublicCertificateAuthorityServiceAsyncClient: """Manages the resources required for ACME `external account @@ -279,6 +289,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.security.publicca_v1.PublicCertificateAuthorityServiceAsyncClient`.", + extra={ + "serviceName": "google.cloud.security.publicca.v1.PublicCertificateAuthorityService", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.security.publicca.v1.PublicCertificateAuthorityService", + "credentialsType": None, + }, + ) + async def create_external_account_key( self, request: Optional[Union[service.CreateExternalAccountKeyRequest, dict]] = None, @@ -287,7 +319,7 @@ async def create_external_account_key( external_account_key: Optional[resources.ExternalAccountKey] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.ExternalAccountKey: r"""Creates a new [ExternalAccountKey][google.cloud.security.publicca.v1.ExternalAccountKey] @@ -349,8 +381,10 @@ async def sample_create_external_account_key(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.publicca_v1.types.ExternalAccountKey: diff --git a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/services/public_certificate_authority_service/client.py b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/services/public_certificate_authority_service/client.py index 5b8c64e886cc..704e6d8b1ac4 100644 --- a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/services/public_certificate_authority_service/client.py +++ b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/services/public_certificate_authority_service/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.cloud.security.publicca_v1.types import resources, service from .transports.base import ( @@ -599,6 +609,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -671,6 +685,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.security.publicca_v1.PublicCertificateAuthorityServiceClient`.", + extra={ + "serviceName": "google.cloud.security.publicca.v1.PublicCertificateAuthorityService", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.security.publicca.v1.PublicCertificateAuthorityService", + "credentialsType": None, + }, + ) + def create_external_account_key( self, request: Optional[Union[service.CreateExternalAccountKeyRequest, dict]] = None, @@ -679,7 +716,7 @@ def create_external_account_key( external_account_key: Optional[resources.ExternalAccountKey] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.ExternalAccountKey: r"""Creates a new [ExternalAccountKey][google.cloud.security.publicca.v1.ExternalAccountKey] @@ -741,8 +778,10 @@ def sample_create_external_account_key(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.publicca_v1.types.ExternalAccountKey: diff --git a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/services/public_certificate_authority_service/transports/grpc.py b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/services/public_certificate_authority_service/transports/grpc.py index 5d2e89cf2619..474ea91c5eb8 100644 --- a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/services/public_certificate_authority_service/transports/grpc.py +++ b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/services/public_certificate_authority_service/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -20,12 +23,90 @@ import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.security.publicca_v1.types import resources, service from .base import DEFAULT_CLIENT_INFO, PublicCertificateAuthorityServiceTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.security.publicca.v1.PublicCertificateAuthorityService", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.security.publicca.v1.PublicCertificateAuthorityService", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class PublicCertificateAuthorityServiceGrpcTransport( PublicCertificateAuthorityServiceTransport @@ -183,7 +264,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -261,7 +347,9 @@ def create_external_account_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_external_account_key" not in self._stubs: - self._stubs["create_external_account_key"] = self.grpc_channel.unary_unary( + self._stubs[ + "create_external_account_key" + ] = self._logged_channel.unary_unary( "/google.cloud.security.publicca.v1.PublicCertificateAuthorityService/CreateExternalAccountKey", request_serializer=service.CreateExternalAccountKeyRequest.serialize, response_deserializer=resources.ExternalAccountKey.deserialize, @@ -269,7 +357,7 @@ def create_external_account_key( return self._stubs["create_external_account_key"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/services/public_certificate_authority_service/transports/grpc_asyncio.py b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/services/public_certificate_authority_service/transports/grpc_asyncio.py index 6232b617e963..30211074d64a 100644 --- a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/services/public_certificate_authority_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/services/public_certificate_authority_service/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -22,14 +25,93 @@ from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.security.publicca_v1.types import resources, service from .base import DEFAULT_CLIENT_INFO, PublicCertificateAuthorityServiceTransport from .grpc import PublicCertificateAuthorityServiceGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.security.publicca.v1.PublicCertificateAuthorityService", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.security.publicca.v1.PublicCertificateAuthorityService", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class PublicCertificateAuthorityServiceGrpcAsyncIOTransport( PublicCertificateAuthorityServiceTransport @@ -230,10 +312,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -270,7 +355,9 @@ def create_external_account_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_external_account_key" not in self._stubs: - self._stubs["create_external_account_key"] = self.grpc_channel.unary_unary( + self._stubs[ + "create_external_account_key" + ] = self._logged_channel.unary_unary( "/google.cloud.security.publicca.v1.PublicCertificateAuthorityService/CreateExternalAccountKey", request_serializer=service.CreateExternalAccountKeyRequest.serialize, response_deserializer=resources.ExternalAccountKey.deserialize, @@ -293,7 +380,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/services/public_certificate_authority_service/transports/rest.py b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/services/public_certificate_authority_service/transports/rest.py index dd71b008b368..9630069457c7 100644 --- a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/services/public_certificate_authority_service/transports/rest.py +++ b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1/services/public_certificate_authority_service/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -37,6 +37,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -77,8 +85,10 @@ def post_create_external_account_key(self, response): def pre_create_external_account_key( self, request: service.CreateExternalAccountKeyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.CreateExternalAccountKeyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.CreateExternalAccountKeyRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for create_external_account_key Override in a subclass to manipulate the request or metadata @@ -228,7 +238,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.ExternalAccountKey: r"""Call the create external account key method over HTTP. @@ -241,8 +251,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resources.ExternalAccountKey: @@ -256,6 +268,7 @@ def __call__( http_options = ( _BasePublicCertificateAuthorityServiceRestTransport._BaseCreateExternalAccountKey._get_http_options() ) + request, metadata = self._interceptor.pre_create_external_account_key( request, metadata ) @@ -272,6 +285,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.publicca_v1.PublicCertificateAuthorityServiceClient.CreateExternalAccountKey", + extra={ + "serviceName": "google.cloud.security.publicca.v1.PublicCertificateAuthorityService", + "rpcName": "CreateExternalAccountKey", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = PublicCertificateAuthorityServiceRestTransport._CreateExternalAccountKey._get_response( self._host, @@ -293,7 +333,29 @@ def __call__( pb_resp = resources.ExternalAccountKey.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_external_account_key(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resources.ExternalAccountKey.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.publicca_v1.PublicCertificateAuthorityServiceClient.create_external_account_key", + extra={ + "serviceName": "google.cloud.security.publicca.v1.PublicCertificateAuthorityService", + "rpcName": "CreateExternalAccountKey", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property diff --git a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/gapic_version.py b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/gapic_version.py index 0106eadcd8d9..558c8aab67c5 100644 --- a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/gapic_version.py +++ b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.3.14" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/services/public_certificate_authority_service/async_client.py b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/services/public_certificate_authority_service/async_client.py index 4238b0da97aa..fc28bac84eda 100644 --- a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/services/public_certificate_authority_service/async_client.py +++ b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/services/public_certificate_authority_service/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -53,6 +54,15 @@ PublicCertificateAuthorityServiceGrpcAsyncIOTransport, ) +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class PublicCertificateAuthorityServiceAsyncClient: """Manages the resources required for ACME `external account @@ -279,6 +289,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.security.publicca_v1beta1.PublicCertificateAuthorityServiceAsyncClient`.", + extra={ + "serviceName": "google.cloud.security.publicca.v1beta1.PublicCertificateAuthorityService", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.security.publicca.v1beta1.PublicCertificateAuthorityService", + "credentialsType": None, + }, + ) + async def create_external_account_key( self, request: Optional[Union[service.CreateExternalAccountKeyRequest, dict]] = None, @@ -287,7 +319,7 @@ async def create_external_account_key( external_account_key: Optional[resources.ExternalAccountKey] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.ExternalAccountKey: r"""Creates a new [ExternalAccountKey][google.cloud.security.publicca.v1beta1.ExternalAccountKey] @@ -349,8 +381,10 @@ async def sample_create_external_account_key(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.publicca_v1beta1.types.ExternalAccountKey: diff --git a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/services/public_certificate_authority_service/client.py b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/services/public_certificate_authority_service/client.py index a0bfb9029f54..09bf779aa68b 100644 --- a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/services/public_certificate_authority_service/client.py +++ b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/services/public_certificate_authority_service/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.cloud.security.publicca_v1beta1.types import resources, service from .transports.base import ( @@ -599,6 +609,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -671,6 +685,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.security.publicca_v1beta1.PublicCertificateAuthorityServiceClient`.", + extra={ + "serviceName": "google.cloud.security.publicca.v1beta1.PublicCertificateAuthorityService", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.security.publicca.v1beta1.PublicCertificateAuthorityService", + "credentialsType": None, + }, + ) + def create_external_account_key( self, request: Optional[Union[service.CreateExternalAccountKeyRequest, dict]] = None, @@ -679,7 +716,7 @@ def create_external_account_key( external_account_key: Optional[resources.ExternalAccountKey] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.ExternalAccountKey: r"""Creates a new [ExternalAccountKey][google.cloud.security.publicca.v1beta1.ExternalAccountKey] @@ -741,8 +778,10 @@ def sample_create_external_account_key(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.security.publicca_v1beta1.types.ExternalAccountKey: diff --git a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/services/public_certificate_authority_service/transports/grpc.py b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/services/public_certificate_authority_service/transports/grpc.py index 7f3329c34327..a144465a9fa6 100644 --- a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/services/public_certificate_authority_service/transports/grpc.py +++ b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/services/public_certificate_authority_service/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -20,12 +23,90 @@ import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.security.publicca_v1beta1.types import resources, service from .base import DEFAULT_CLIENT_INFO, PublicCertificateAuthorityServiceTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.security.publicca.v1beta1.PublicCertificateAuthorityService", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.security.publicca.v1beta1.PublicCertificateAuthorityService", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class PublicCertificateAuthorityServiceGrpcTransport( PublicCertificateAuthorityServiceTransport @@ -183,7 +264,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -261,7 +347,9 @@ def create_external_account_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_external_account_key" not in self._stubs: - self._stubs["create_external_account_key"] = self.grpc_channel.unary_unary( + self._stubs[ + "create_external_account_key" + ] = self._logged_channel.unary_unary( "/google.cloud.security.publicca.v1beta1.PublicCertificateAuthorityService/CreateExternalAccountKey", request_serializer=service.CreateExternalAccountKeyRequest.serialize, response_deserializer=resources.ExternalAccountKey.deserialize, @@ -269,7 +357,7 @@ def create_external_account_key( return self._stubs["create_external_account_key"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/services/public_certificate_authority_service/transports/grpc_asyncio.py b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/services/public_certificate_authority_service/transports/grpc_asyncio.py index 5ff69f91ef04..b24fa2e549e0 100644 --- a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/services/public_certificate_authority_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/services/public_certificate_authority_service/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -22,14 +25,93 @@ from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.security.publicca_v1beta1.types import resources, service from .base import DEFAULT_CLIENT_INFO, PublicCertificateAuthorityServiceTransport from .grpc import PublicCertificateAuthorityServiceGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.security.publicca.v1beta1.PublicCertificateAuthorityService", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.security.publicca.v1beta1.PublicCertificateAuthorityService", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class PublicCertificateAuthorityServiceGrpcAsyncIOTransport( PublicCertificateAuthorityServiceTransport @@ -230,10 +312,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -270,7 +355,9 @@ def create_external_account_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_external_account_key" not in self._stubs: - self._stubs["create_external_account_key"] = self.grpc_channel.unary_unary( + self._stubs[ + "create_external_account_key" + ] = self._logged_channel.unary_unary( "/google.cloud.security.publicca.v1beta1.PublicCertificateAuthorityService/CreateExternalAccountKey", request_serializer=service.CreateExternalAccountKeyRequest.serialize, response_deserializer=resources.ExternalAccountKey.deserialize, @@ -293,7 +380,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/services/public_certificate_authority_service/transports/rest.py b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/services/public_certificate_authority_service/transports/rest.py index eb19aded3f8f..74951c6c5f53 100644 --- a/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/services/public_certificate_authority_service/transports/rest.py +++ b/packages/google-cloud-public-ca/google/cloud/security/publicca_v1beta1/services/public_certificate_authority_service/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -37,6 +37,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -77,8 +85,10 @@ def post_create_external_account_key(self, response): def pre_create_external_account_key( self, request: service.CreateExternalAccountKeyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[service.CreateExternalAccountKeyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + service.CreateExternalAccountKeyRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for create_external_account_key Override in a subclass to manipulate the request or metadata @@ -228,7 +238,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.ExternalAccountKey: r"""Call the create external account key method over HTTP. @@ -241,8 +251,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resources.ExternalAccountKey: @@ -256,6 +268,7 @@ def __call__( http_options = ( _BasePublicCertificateAuthorityServiceRestTransport._BaseCreateExternalAccountKey._get_http_options() ) + request, metadata = self._interceptor.pre_create_external_account_key( request, metadata ) @@ -272,6 +285,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.security.publicca_v1beta1.PublicCertificateAuthorityServiceClient.CreateExternalAccountKey", + extra={ + "serviceName": "google.cloud.security.publicca.v1beta1.PublicCertificateAuthorityService", + "rpcName": "CreateExternalAccountKey", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = PublicCertificateAuthorityServiceRestTransport._CreateExternalAccountKey._get_response( self._host, @@ -293,7 +333,29 @@ def __call__( pb_resp = resources.ExternalAccountKey.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_external_account_key(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resources.ExternalAccountKey.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.security.publicca_v1beta1.PublicCertificateAuthorityServiceClient.create_external_account_key", + extra={ + "serviceName": "google.cloud.security.publicca.v1beta1.PublicCertificateAuthorityService", + "rpcName": "CreateExternalAccountKey", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property diff --git a/packages/google-cloud-public-ca/samples/generated_samples/snippet_metadata_google.cloud.security.publicca.v1.json b/packages/google-cloud-public-ca/samples/generated_samples/snippet_metadata_google.cloud.security.publicca.v1.json index 9229f3c3f426..0e5cae8caf1b 100644 --- a/packages/google-cloud-public-ca/samples/generated_samples/snippet_metadata_google.cloud.security.publicca.v1.json +++ b/packages/google-cloud-public-ca/samples/generated_samples/snippet_metadata_google.cloud.security.publicca.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-security-publicca", - "version": "0.3.14" + "version": "0.1.0" }, "snippets": [ { @@ -51,7 +51,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.publicca_v1.types.ExternalAccountKey", @@ -135,7 +135,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.publicca_v1.types.ExternalAccountKey", diff --git a/packages/google-cloud-public-ca/samples/generated_samples/snippet_metadata_google.cloud.security.publicca.v1beta1.json b/packages/google-cloud-public-ca/samples/generated_samples/snippet_metadata_google.cloud.security.publicca.v1beta1.json index 75d2b46127b3..5871e5024384 100644 --- a/packages/google-cloud-public-ca/samples/generated_samples/snippet_metadata_google.cloud.security.publicca.v1beta1.json +++ b/packages/google-cloud-public-ca/samples/generated_samples/snippet_metadata_google.cloud.security.publicca.v1beta1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-public-ca", - "version": "0.3.14" + "version": "0.1.0" }, "snippets": [ { @@ -51,7 +51,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.publicca_v1beta1.types.ExternalAccountKey", @@ -135,7 +135,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.security.publicca_v1beta1.types.ExternalAccountKey", diff --git a/packages/google-cloud-public-ca/tests/unit/gapic/publicca_v1/test_public_certificate_authority_service.py b/packages/google-cloud-public-ca/tests/unit/gapic/publicca_v1/test_public_certificate_authority_service.py index cfc08c73f6fe..51755be9ebeb 100644 --- a/packages/google-cloud-public-ca/tests/unit/gapic/publicca_v1/test_public_certificate_authority_service.py +++ b/packages/google-cloud-public-ca/tests/unit/gapic/publicca_v1/test_public_certificate_authority_service.py @@ -1626,6 +1626,7 @@ def test_create_external_account_key_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_external_account_key(request) @@ -1680,6 +1681,7 @@ def test_create_external_account_key_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_external_account_key(**mock_args) @@ -1912,6 +1914,7 @@ def test_create_external_account_key_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_external_account_key(request) @@ -2025,6 +2028,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_external_account_key(request) # Establish that the response is the type that we expect. @@ -2069,6 +2073,7 @@ def test_create_external_account_key_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resources.ExternalAccountKey.to_json( resources.ExternalAccountKey() ) diff --git a/packages/google-cloud-public-ca/tests/unit/gapic/publicca_v1beta1/test_public_certificate_authority_service.py b/packages/google-cloud-public-ca/tests/unit/gapic/publicca_v1beta1/test_public_certificate_authority_service.py index c0bfb18e40e4..a48bf32dac87 100644 --- a/packages/google-cloud-public-ca/tests/unit/gapic/publicca_v1beta1/test_public_certificate_authority_service.py +++ b/packages/google-cloud-public-ca/tests/unit/gapic/publicca_v1beta1/test_public_certificate_authority_service.py @@ -1626,6 +1626,7 @@ def test_create_external_account_key_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_external_account_key(request) @@ -1680,6 +1681,7 @@ def test_create_external_account_key_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_external_account_key(**mock_args) @@ -1912,6 +1914,7 @@ def test_create_external_account_key_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_external_account_key(request) @@ -2025,6 +2028,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_external_account_key(request) # Establish that the response is the type that we expect. @@ -2069,6 +2073,7 @@ def test_create_external_account_key_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resources.ExternalAccountKey.to_json( resources.ExternalAccountKey() ) diff --git a/packages/google-cloud-quotas/google/cloud/cloudquotas/gapic_version.py b/packages/google-cloud-quotas/google/cloud/cloudquotas/gapic_version.py index 7daf9a1dd221..558c8aab67c5 100644 --- a/packages/google-cloud-quotas/google/cloud/cloudquotas/gapic_version.py +++ b/packages/google-cloud-quotas/google/cloud/cloudquotas/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.1.13" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/gapic_version.py b/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/gapic_version.py index 7daf9a1dd221..558c8aab67c5 100644 --- a/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/gapic_version.py +++ b/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.1.13" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/async_client.py b/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/async_client.py index 80a6fb9730a7..16b0b081a602 100644 --- a/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/async_client.py +++ b/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -52,6 +53,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, CloudQuotasTransport from .transports.grpc_asyncio import CloudQuotasGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class CloudQuotasAsyncClient: """The Cloud Quotas API is an infrastructure service for Google @@ -267,6 +277,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.api.cloudquotas_v1.CloudQuotasAsyncClient`.", + extra={ + "serviceName": "google.api.cloudquotas.v1.CloudQuotas", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.api.cloudquotas.v1.CloudQuotas", + "credentialsType": None, + }, + ) + async def list_quota_infos( self, request: Optional[Union[cloudquotas.ListQuotaInfosRequest, dict]] = None, @@ -274,7 +306,7 @@ async def list_quota_infos( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListQuotaInfosAsyncPager: r"""Lists QuotaInfos of all quotas for a given project, folder or organization. @@ -326,8 +358,10 @@ async def sample_list_quota_infos(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.cloudquotas_v1.services.cloud_quotas.pagers.ListQuotaInfosAsyncPager: @@ -402,7 +436,7 @@ async def get_quota_info( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.QuotaInfo: r"""Retrieve the QuotaInfo of a quota for a project, folder or organization. @@ -448,8 +482,10 @@ async def sample_get_quota_info(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.cloudquotas_v1.types.QuotaInfo: @@ -511,7 +547,7 @@ async def list_quota_preferences( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListQuotaPreferencesAsyncPager: r"""Lists QuotaPreferences in a given project, folder or organization. @@ -565,8 +601,10 @@ async def sample_list_quota_preferences(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.cloudquotas_v1.services.cloud_quotas.pagers.ListQuotaPreferencesAsyncPager: @@ -641,7 +679,7 @@ async def get_quota_preference( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.QuotaPreference: r"""Gets details of a single QuotaPreference. @@ -686,8 +724,10 @@ async def sample_get_quota_preference(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.cloudquotas_v1.types.QuotaPreference: @@ -754,7 +794,7 @@ async def create_quota_preference( quota_preference_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.QuotaPreference: r"""Creates a new QuotaPreference that declares the desired value for a quota. @@ -820,8 +860,10 @@ async def sample_create_quota_preference(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.cloudquotas_v1.types.QuotaPreference: @@ -891,7 +933,7 @@ async def update_quota_preference( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.QuotaPreference: r"""Updates the parameters of a single QuotaPreference. It can updates the config in any states, not just the @@ -952,8 +994,10 @@ async def sample_update_quota_preference(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.cloudquotas_v1.types.QuotaPreference: diff --git a/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/client.py b/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/client.py index 5dfd44f40594..90b364da2069 100644 --- a/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/client.py +++ b/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -613,6 +623,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -675,6 +689,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.api.cloudquotas_v1.CloudQuotasClient`.", + extra={ + "serviceName": "google.api.cloudquotas.v1.CloudQuotas", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.api.cloudquotas.v1.CloudQuotas", + "credentialsType": None, + }, + ) + def list_quota_infos( self, request: Optional[Union[cloudquotas.ListQuotaInfosRequest, dict]] = None, @@ -682,7 +719,7 @@ def list_quota_infos( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListQuotaInfosPager: r"""Lists QuotaInfos of all quotas for a given project, folder or organization. @@ -734,8 +771,10 @@ def sample_list_quota_infos(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.cloudquotas_v1.services.cloud_quotas.pagers.ListQuotaInfosPager: @@ -807,7 +846,7 @@ def get_quota_info( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.QuotaInfo: r"""Retrieve the QuotaInfo of a quota for a project, folder or organization. @@ -853,8 +892,10 @@ def sample_get_quota_info(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.cloudquotas_v1.types.QuotaInfo: @@ -913,7 +954,7 @@ def list_quota_preferences( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListQuotaPreferencesPager: r"""Lists QuotaPreferences in a given project, folder or organization. @@ -967,8 +1008,10 @@ def sample_list_quota_preferences(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.cloudquotas_v1.services.cloud_quotas.pagers.ListQuotaPreferencesPager: @@ -1040,7 +1083,7 @@ def get_quota_preference( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.QuotaPreference: r"""Gets details of a single QuotaPreference. @@ -1085,8 +1128,10 @@ def sample_get_quota_preference(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.cloudquotas_v1.types.QuotaPreference: @@ -1150,7 +1195,7 @@ def create_quota_preference( quota_preference_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.QuotaPreference: r"""Creates a new QuotaPreference that declares the desired value for a quota. @@ -1216,8 +1261,10 @@ def sample_create_quota_preference(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.cloudquotas_v1.types.QuotaPreference: @@ -1284,7 +1331,7 @@ def update_quota_preference( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.QuotaPreference: r"""Updates the parameters of a single QuotaPreference. It can updates the config in any states, not just the @@ -1345,8 +1392,10 @@ def sample_update_quota_preference(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.cloudquotas_v1.types.QuotaPreference: diff --git a/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/pagers.py b/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/pagers.py index c49b27f83afb..57c1842b4f42 100644 --- a/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/pagers.py +++ b/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -81,8 +81,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = cloudquotas.ListQuotaInfosRequest(request) @@ -141,7 +143,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -155,8 +157,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = cloudquotas.ListQuotaInfosRequest(request) @@ -219,7 +223,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -233,8 +237,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = cloudquotas.ListQuotaPreferencesRequest(request) @@ -293,7 +299,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -307,8 +313,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = cloudquotas.ListQuotaPreferencesRequest(request) diff --git a/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/transports/grpc.py b/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/transports/grpc.py index 599bd90756a8..2bfac2b72336 100644 --- a/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/transports/grpc.py +++ b/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -20,12 +23,90 @@ import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.cloudquotas_v1.types import cloudquotas, resources from .base import DEFAULT_CLIENT_INFO, CloudQuotasTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.api.cloudquotas.v1.CloudQuotas", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.api.cloudquotas.v1.CloudQuotas", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class CloudQuotasGrpcTransport(CloudQuotasTransport): """gRPC backend transport for CloudQuotas. @@ -188,7 +269,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -265,7 +351,7 @@ def list_quota_infos( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_quota_infos" not in self._stubs: - self._stubs["list_quota_infos"] = self.grpc_channel.unary_unary( + self._stubs["list_quota_infos"] = self._logged_channel.unary_unary( "/google.api.cloudquotas.v1.CloudQuotas/ListQuotaInfos", request_serializer=cloudquotas.ListQuotaInfosRequest.serialize, response_deserializer=cloudquotas.ListQuotaInfosResponse.deserialize, @@ -292,7 +378,7 @@ def get_quota_info( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_quota_info" not in self._stubs: - self._stubs["get_quota_info"] = self.grpc_channel.unary_unary( + self._stubs["get_quota_info"] = self._logged_channel.unary_unary( "/google.api.cloudquotas.v1.CloudQuotas/GetQuotaInfo", request_serializer=cloudquotas.GetQuotaInfoRequest.serialize, response_deserializer=resources.QuotaInfo.deserialize, @@ -322,7 +408,7 @@ def list_quota_preferences( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_quota_preferences" not in self._stubs: - self._stubs["list_quota_preferences"] = self.grpc_channel.unary_unary( + self._stubs["list_quota_preferences"] = self._logged_channel.unary_unary( "/google.api.cloudquotas.v1.CloudQuotas/ListQuotaPreferences", request_serializer=cloudquotas.ListQuotaPreferencesRequest.serialize, response_deserializer=cloudquotas.ListQuotaPreferencesResponse.deserialize, @@ -348,7 +434,7 @@ def get_quota_preference( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_quota_preference" not in self._stubs: - self._stubs["get_quota_preference"] = self.grpc_channel.unary_unary( + self._stubs["get_quota_preference"] = self._logged_channel.unary_unary( "/google.api.cloudquotas.v1.CloudQuotas/GetQuotaPreference", request_serializer=cloudquotas.GetQuotaPreferenceRequest.serialize, response_deserializer=resources.QuotaPreference.deserialize, @@ -377,7 +463,7 @@ def create_quota_preference( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_quota_preference" not in self._stubs: - self._stubs["create_quota_preference"] = self.grpc_channel.unary_unary( + self._stubs["create_quota_preference"] = self._logged_channel.unary_unary( "/google.api.cloudquotas.v1.CloudQuotas/CreateQuotaPreference", request_serializer=cloudquotas.CreateQuotaPreferenceRequest.serialize, response_deserializer=resources.QuotaPreference.deserialize, @@ -407,7 +493,7 @@ def update_quota_preference( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_quota_preference" not in self._stubs: - self._stubs["update_quota_preference"] = self.grpc_channel.unary_unary( + self._stubs["update_quota_preference"] = self._logged_channel.unary_unary( "/google.api.cloudquotas.v1.CloudQuotas/UpdateQuotaPreference", request_serializer=cloudquotas.UpdateQuotaPreferenceRequest.serialize, response_deserializer=resources.QuotaPreference.deserialize, @@ -415,7 +501,7 @@ def update_quota_preference( return self._stubs["update_quota_preference"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/transports/grpc_asyncio.py b/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/transports/grpc_asyncio.py index 475d3a35c05a..61dfaac40f99 100644 --- a/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/transports/grpc_asyncio.py +++ b/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -22,14 +25,93 @@ from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.cloudquotas_v1.types import cloudquotas, resources from .base import DEFAULT_CLIENT_INFO, CloudQuotasTransport from .grpc import CloudQuotasGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.api.cloudquotas.v1.CloudQuotas", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.api.cloudquotas.v1.CloudQuotas", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class CloudQuotasGrpcAsyncIOTransport(CloudQuotasTransport): """gRPC AsyncIO backend transport for CloudQuotas. @@ -235,10 +317,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -274,7 +359,7 @@ def list_quota_infos( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_quota_infos" not in self._stubs: - self._stubs["list_quota_infos"] = self.grpc_channel.unary_unary( + self._stubs["list_quota_infos"] = self._logged_channel.unary_unary( "/google.api.cloudquotas.v1.CloudQuotas/ListQuotaInfos", request_serializer=cloudquotas.ListQuotaInfosRequest.serialize, response_deserializer=cloudquotas.ListQuotaInfosResponse.deserialize, @@ -301,7 +386,7 @@ def get_quota_info( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_quota_info" not in self._stubs: - self._stubs["get_quota_info"] = self.grpc_channel.unary_unary( + self._stubs["get_quota_info"] = self._logged_channel.unary_unary( "/google.api.cloudquotas.v1.CloudQuotas/GetQuotaInfo", request_serializer=cloudquotas.GetQuotaInfoRequest.serialize, response_deserializer=resources.QuotaInfo.deserialize, @@ -331,7 +416,7 @@ def list_quota_preferences( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_quota_preferences" not in self._stubs: - self._stubs["list_quota_preferences"] = self.grpc_channel.unary_unary( + self._stubs["list_quota_preferences"] = self._logged_channel.unary_unary( "/google.api.cloudquotas.v1.CloudQuotas/ListQuotaPreferences", request_serializer=cloudquotas.ListQuotaPreferencesRequest.serialize, response_deserializer=cloudquotas.ListQuotaPreferencesResponse.deserialize, @@ -359,7 +444,7 @@ def get_quota_preference( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_quota_preference" not in self._stubs: - self._stubs["get_quota_preference"] = self.grpc_channel.unary_unary( + self._stubs["get_quota_preference"] = self._logged_channel.unary_unary( "/google.api.cloudquotas.v1.CloudQuotas/GetQuotaPreference", request_serializer=cloudquotas.GetQuotaPreferenceRequest.serialize, response_deserializer=resources.QuotaPreference.deserialize, @@ -388,7 +473,7 @@ def create_quota_preference( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_quota_preference" not in self._stubs: - self._stubs["create_quota_preference"] = self.grpc_channel.unary_unary( + self._stubs["create_quota_preference"] = self._logged_channel.unary_unary( "/google.api.cloudquotas.v1.CloudQuotas/CreateQuotaPreference", request_serializer=cloudquotas.CreateQuotaPreferenceRequest.serialize, response_deserializer=resources.QuotaPreference.deserialize, @@ -418,7 +503,7 @@ def update_quota_preference( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_quota_preference" not in self._stubs: - self._stubs["update_quota_preference"] = self.grpc_channel.unary_unary( + self._stubs["update_quota_preference"] = self._logged_channel.unary_unary( "/google.api.cloudquotas.v1.CloudQuotas/UpdateQuotaPreference", request_serializer=cloudquotas.UpdateQuotaPreferenceRequest.serialize, response_deserializer=resources.QuotaPreference.deserialize, @@ -520,7 +605,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/transports/rest.py b/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/transports/rest.py index b67b5bbdf7bd..353af1a39cf1 100644 --- a/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/transports/rest.py +++ b/packages/google-cloud-quotas/google/cloud/cloudquotas_v1/services/cloud_quotas/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -37,6 +37,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -117,8 +125,11 @@ def post_update_quota_preference(self, response): def pre_create_quota_preference( self, request: cloudquotas.CreateQuotaPreferenceRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloudquotas.CreateQuotaPreferenceRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloudquotas.CreateQuotaPreferenceRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for create_quota_preference Override in a subclass to manipulate the request or metadata @@ -140,8 +151,10 @@ def post_create_quota_preference( def pre_get_quota_info( self, request: cloudquotas.GetQuotaInfoRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloudquotas.GetQuotaInfoRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloudquotas.GetQuotaInfoRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_quota_info Override in a subclass to manipulate the request or metadata @@ -161,8 +174,10 @@ def post_get_quota_info(self, response: resources.QuotaInfo) -> resources.QuotaI def pre_get_quota_preference( self, request: cloudquotas.GetQuotaPreferenceRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloudquotas.GetQuotaPreferenceRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloudquotas.GetQuotaPreferenceRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_quota_preference Override in a subclass to manipulate the request or metadata @@ -184,8 +199,10 @@ def post_get_quota_preference( def pre_list_quota_infos( self, request: cloudquotas.ListQuotaInfosRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloudquotas.ListQuotaInfosRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloudquotas.ListQuotaInfosRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_quota_infos Override in a subclass to manipulate the request or metadata @@ -207,8 +224,10 @@ def post_list_quota_infos( def pre_list_quota_preferences( self, request: cloudquotas.ListQuotaPreferencesRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloudquotas.ListQuotaPreferencesRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloudquotas.ListQuotaPreferencesRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_quota_preferences Override in a subclass to manipulate the request or metadata @@ -230,8 +249,11 @@ def post_list_quota_preferences( def pre_update_quota_preference( self, request: cloudquotas.UpdateQuotaPreferenceRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloudquotas.UpdateQuotaPreferenceRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloudquotas.UpdateQuotaPreferenceRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for update_quota_preference Override in a subclass to manipulate the request or metadata @@ -381,7 +403,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.QuotaPreference: r"""Call the create quota preference method over HTTP. @@ -392,8 +414,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resources.QuotaPreference: @@ -409,6 +433,7 @@ def __call__( http_options = ( _BaseCloudQuotasRestTransport._BaseCreateQuotaPreference._get_http_options() ) + request, metadata = self._interceptor.pre_create_quota_preference( request, metadata ) @@ -425,6 +450,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.api.cloudquotas_v1.CloudQuotasClient.CreateQuotaPreference", + extra={ + "serviceName": "google.api.cloudquotas.v1.CloudQuotas", + "rpcName": "CreateQuotaPreference", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudQuotasRestTransport._CreateQuotaPreference._get_response( self._host, @@ -446,7 +498,29 @@ def __call__( pb_resp = resources.QuotaPreference.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_quota_preference(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resources.QuotaPreference.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.api.cloudquotas_v1.CloudQuotasClient.create_quota_preference", + extra={ + "serviceName": "google.api.cloudquotas.v1.CloudQuotas", + "rpcName": "CreateQuotaPreference", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetQuotaInfo( @@ -483,7 +557,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.QuotaInfo: r"""Call the get quota info method over HTTP. @@ -493,8 +567,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resources.QuotaInfo: @@ -507,6 +583,7 @@ def __call__( http_options = ( _BaseCloudQuotasRestTransport._BaseGetQuotaInfo._get_http_options() ) + request, metadata = self._interceptor.pre_get_quota_info(request, metadata) transcoded_request = ( _BaseCloudQuotasRestTransport._BaseGetQuotaInfo._get_transcoded_request( @@ -521,6 +598,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.api.cloudquotas_v1.CloudQuotasClient.GetQuotaInfo", + extra={ + "serviceName": "google.api.cloudquotas.v1.CloudQuotas", + "rpcName": "GetQuotaInfo", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudQuotasRestTransport._GetQuotaInfo._get_response( self._host, @@ -541,7 +645,29 @@ def __call__( pb_resp = resources.QuotaInfo.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_quota_info(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resources.QuotaInfo.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.api.cloudquotas_v1.CloudQuotasClient.get_quota_info", + extra={ + "serviceName": "google.api.cloudquotas.v1.CloudQuotas", + "rpcName": "GetQuotaInfo", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetQuotaPreference( @@ -578,7 +704,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.QuotaPreference: r"""Call the get quota preference method over HTTP. @@ -588,8 +714,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resources.QuotaPreference: @@ -605,6 +733,7 @@ def __call__( http_options = ( _BaseCloudQuotasRestTransport._BaseGetQuotaPreference._get_http_options() ) + request, metadata = self._interceptor.pre_get_quota_preference( request, metadata ) @@ -617,6 +746,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.api.cloudquotas_v1.CloudQuotasClient.GetQuotaPreference", + extra={ + "serviceName": "google.api.cloudquotas.v1.CloudQuotas", + "rpcName": "GetQuotaPreference", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudQuotasRestTransport._GetQuotaPreference._get_response( self._host, @@ -637,7 +793,29 @@ def __call__( pb_resp = resources.QuotaPreference.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_quota_preference(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resources.QuotaPreference.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.api.cloudquotas_v1.CloudQuotasClient.get_quota_preference", + extra={ + "serviceName": "google.api.cloudquotas.v1.CloudQuotas", + "rpcName": "GetQuotaPreference", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListQuotaInfos( @@ -674,7 +852,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloudquotas.ListQuotaInfosResponse: r"""Call the list quota infos method over HTTP. @@ -685,8 +863,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.cloudquotas.ListQuotaInfosResponse: @@ -698,6 +878,7 @@ def __call__( http_options = ( _BaseCloudQuotasRestTransport._BaseListQuotaInfos._get_http_options() ) + request, metadata = self._interceptor.pre_list_quota_infos( request, metadata ) @@ -710,6 +891,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.api.cloudquotas_v1.CloudQuotasClient.ListQuotaInfos", + extra={ + "serviceName": "google.api.cloudquotas.v1.CloudQuotas", + "rpcName": "ListQuotaInfos", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudQuotasRestTransport._ListQuotaInfos._get_response( self._host, @@ -730,7 +938,31 @@ def __call__( pb_resp = cloudquotas.ListQuotaInfosResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_quota_infos(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = cloudquotas.ListQuotaInfosResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.api.cloudquotas_v1.CloudQuotasClient.list_quota_infos", + extra={ + "serviceName": "google.api.cloudquotas.v1.CloudQuotas", + "rpcName": "ListQuotaInfos", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListQuotaPreferences( @@ -767,7 +999,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloudquotas.ListQuotaPreferencesResponse: r"""Call the list quota preferences method over HTTP. @@ -778,8 +1010,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.cloudquotas.ListQuotaPreferencesResponse: @@ -791,6 +1025,7 @@ def __call__( http_options = ( _BaseCloudQuotasRestTransport._BaseListQuotaPreferences._get_http_options() ) + request, metadata = self._interceptor.pre_list_quota_preferences( request, metadata ) @@ -803,6 +1038,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.api.cloudquotas_v1.CloudQuotasClient.ListQuotaPreferences", + extra={ + "serviceName": "google.api.cloudquotas.v1.CloudQuotas", + "rpcName": "ListQuotaPreferences", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudQuotasRestTransport._ListQuotaPreferences._get_response( self._host, @@ -823,7 +1085,31 @@ def __call__( pb_resp = cloudquotas.ListQuotaPreferencesResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_quota_preferences(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = cloudquotas.ListQuotaPreferencesResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.api.cloudquotas_v1.CloudQuotasClient.list_quota_preferences", + extra={ + "serviceName": "google.api.cloudquotas.v1.CloudQuotas", + "rpcName": "ListQuotaPreferences", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateQuotaPreference( @@ -861,7 +1147,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resources.QuotaPreference: r"""Call the update quota preference method over HTTP. @@ -872,8 +1158,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resources.QuotaPreference: @@ -889,6 +1177,7 @@ def __call__( http_options = ( _BaseCloudQuotasRestTransport._BaseUpdateQuotaPreference._get_http_options() ) + request, metadata = self._interceptor.pre_update_quota_preference( request, metadata ) @@ -905,6 +1194,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.api.cloudquotas_v1.CloudQuotasClient.UpdateQuotaPreference", + extra={ + "serviceName": "google.api.cloudquotas.v1.CloudQuotas", + "rpcName": "UpdateQuotaPreference", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudQuotasRestTransport._UpdateQuotaPreference._get_response( self._host, @@ -926,7 +1242,29 @@ def __call__( pb_resp = resources.QuotaPreference.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_quota_preference(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resources.QuotaPreference.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.api.cloudquotas_v1.CloudQuotasClient.update_quota_preference", + extra={ + "serviceName": "google.api.cloudquotas.v1.CloudQuotas", + "rpcName": "UpdateQuotaPreference", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property diff --git a/packages/google-cloud-quotas/samples/generated_samples/snippet_metadata_google.api.cloudquotas.v1.json b/packages/google-cloud-quotas/samples/generated_samples/snippet_metadata_google.api.cloudquotas.v1.json index 698cfddccb39..5c9d0867f7f3 100644 --- a/packages/google-cloud-quotas/samples/generated_samples/snippet_metadata_google.api.cloudquotas.v1.json +++ b/packages/google-cloud-quotas/samples/generated_samples/snippet_metadata_google.api.cloudquotas.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-quotas", - "version": "0.1.13" + "version": "0.1.0" }, "snippets": [ { @@ -55,7 +55,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.cloudquotas_v1.types.QuotaPreference", @@ -143,7 +143,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.cloudquotas_v1.types.QuotaPreference", @@ -224,7 +224,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.cloudquotas_v1.types.QuotaInfo", @@ -304,7 +304,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.cloudquotas_v1.types.QuotaInfo", @@ -385,7 +385,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.cloudquotas_v1.types.QuotaPreference", @@ -465,7 +465,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.cloudquotas_v1.types.QuotaPreference", @@ -546,7 +546,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.cloudquotas_v1.services.cloud_quotas.pagers.ListQuotaInfosAsyncPager", @@ -626,7 +626,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.cloudquotas_v1.services.cloud_quotas.pagers.ListQuotaInfosPager", @@ -707,7 +707,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.cloudquotas_v1.services.cloud_quotas.pagers.ListQuotaPreferencesAsyncPager", @@ -787,7 +787,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.cloudquotas_v1.services.cloud_quotas.pagers.ListQuotaPreferencesPager", @@ -872,7 +872,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.cloudquotas_v1.types.QuotaPreference", @@ -956,7 +956,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.cloudquotas_v1.types.QuotaPreference", diff --git a/packages/google-cloud-quotas/tests/unit/gapic/cloudquotas_v1/test_cloud_quotas.py b/packages/google-cloud-quotas/tests/unit/gapic/cloudquotas_v1/test_cloud_quotas.py index 789a5a86bafe..9e5844a0259d 100644 --- a/packages/google-cloud-quotas/tests/unit/gapic/cloudquotas_v1/test_cloud_quotas.py +++ b/packages/google-cloud-quotas/tests/unit/gapic/cloudquotas_v1/test_cloud_quotas.py @@ -3711,6 +3711,7 @@ def test_list_quota_infos_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_quota_infos(request) @@ -3766,6 +3767,7 @@ def test_list_quota_infos_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_quota_infos(**mock_args) @@ -3962,6 +3964,7 @@ def test_get_quota_info_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_quota_info(request) @@ -4009,6 +4012,7 @@ def test_get_quota_info_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_quota_info(**mock_args) @@ -4154,6 +4158,7 @@ def test_list_quota_preferences_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_quota_preferences(request) @@ -4209,6 +4214,7 @@ def test_list_quota_preferences_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_quota_preferences(**mock_args) @@ -4407,6 +4413,7 @@ def test_get_quota_preference_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_quota_preference(request) @@ -4454,6 +4461,7 @@ def test_get_quota_preference_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_quota_preference(**mock_args) @@ -4598,6 +4606,7 @@ def test_create_quota_preference_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_quota_preference(request) @@ -4658,6 +4667,7 @@ def test_create_quota_preference_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_quota_preference(**mock_args) @@ -4801,6 +4811,7 @@ def test_update_quota_preference_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_quota_preference(request) @@ -4861,6 +4872,7 @@ def test_update_quota_preference_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_quota_preference(**mock_args) @@ -5375,6 +5387,7 @@ def test_list_quota_infos_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_quota_infos(request) @@ -5410,6 +5423,7 @@ def test_list_quota_infos_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_quota_infos(request) # Establish that the response is the type that we expect. @@ -5450,6 +5464,7 @@ def test_list_quota_infos_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = cloudquotas.ListQuotaInfosResponse.to_json( cloudquotas.ListQuotaInfosResponse() ) @@ -5496,6 +5511,7 @@ def test_get_quota_info_rest_bad_request(request_type=cloudquotas.GetQuotaInfoRe response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_quota_info(request) @@ -5546,6 +5562,7 @@ def test_get_quota_info_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_quota_info(request) # Establish that the response is the type that we expect. @@ -5599,6 +5616,7 @@ def test_get_quota_info_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resources.QuotaInfo.to_json(resources.QuotaInfo()) req.return_value.content = return_value @@ -5643,6 +5661,7 @@ def test_list_quota_preferences_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_quota_preferences(request) @@ -5679,6 +5698,7 @@ def test_list_quota_preferences_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_quota_preferences(request) # Establish that the response is the type that we expect. @@ -5720,6 +5740,7 @@ def test_list_quota_preferences_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = cloudquotas.ListQuotaPreferencesResponse.to_json( cloudquotas.ListQuotaPreferencesResponse() ) @@ -5768,6 +5789,7 @@ def test_get_quota_preference_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_quota_preference(request) @@ -5811,6 +5833,7 @@ def test_get_quota_preference_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_quota_preference(request) # Establish that the response is the type that we expect. @@ -5857,6 +5880,7 @@ def test_get_quota_preference_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resources.QuotaPreference.to_json(resources.QuotaPreference()) req.return_value.content = return_value @@ -5901,6 +5925,7 @@ def test_create_quota_preference_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_quota_preference(request) @@ -6031,6 +6056,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_quota_preference(request) # Establish that the response is the type that we expect. @@ -6077,6 +6103,7 @@ def test_create_quota_preference_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resources.QuotaPreference.to_json(resources.QuotaPreference()) req.return_value.content = return_value @@ -6125,6 +6152,7 @@ def test_update_quota_preference_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_quota_preference(request) @@ -6259,6 +6287,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_quota_preference(request) # Establish that the response is the type that we expect. @@ -6305,6 +6334,7 @@ def test_update_quota_preference_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resources.QuotaPreference.to_json(resources.QuotaPreference()) req.return_value.content = return_value diff --git a/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment/gapic_version.py b/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment/gapic_version.py index 4b834789ba9e..558c8aab67c5 100644 --- a/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment/gapic_version.py +++ b/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.1.11" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/gapic_version.py b/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/gapic_version.py index 4b834789ba9e..558c8aab67c5 100644 --- a/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/gapic_version.py +++ b/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.1.11" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/async_client.py b/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/async_client.py index acc50adbcd0a..2dabb4ba32ea 100644 --- a/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/async_client.py +++ b/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -61,6 +62,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, RapidMigrationAssessmentTransport from .transports.grpc_asyncio import RapidMigrationAssessmentGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class RapidMigrationAssessmentAsyncClient: """Service describing handlers for resources.""" @@ -282,6 +292,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentAsyncClient`.", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "credentialsType": None, + }, + ) + async def create_collector( self, request: Optional[ @@ -293,7 +325,7 @@ async def create_collector( collector_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Create a Collector to manage the on-prem appliance which collects information about Customer assets. @@ -354,8 +386,10 @@ async def sample_create_collector(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -434,7 +468,7 @@ async def create_annotation( annotation: Optional[api_entities.Annotation] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Creates an Annotation @@ -486,8 +520,10 @@ async def sample_create_annotation(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -563,7 +599,7 @@ async def get_annotation( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> api_entities.Annotation: r"""Gets details of a single Annotation. @@ -605,8 +641,10 @@ async def sample_get_annotation(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.rapidmigrationassessment_v1.types.Annotation: @@ -667,7 +705,7 @@ async def list_collectors( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListCollectorsAsyncPager: r"""Lists Collectors in a given project and location. @@ -712,8 +750,10 @@ async def sample_list_collectors(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.rapidmigrationassessment_v1.services.rapid_migration_assessment.pagers.ListCollectorsAsyncPager: @@ -790,7 +830,7 @@ async def get_collector( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> api_entities.Collector: r"""Gets details of a single Collector. @@ -832,8 +872,10 @@ async def sample_get_collector(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.rapidmigrationassessment_v1.types.Collector: @@ -895,7 +937,7 @@ async def update_collector( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Updates the parameters of a single Collector. @@ -950,8 +992,10 @@ async def sample_update_collector(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1029,7 +1073,7 @@ async def delete_collector( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a single Collector - changes state of collector to "Deleting". Background jobs does final @@ -1076,8 +1120,10 @@ async def sample_delete_collector(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1151,7 +1197,7 @@ async def resume_collector( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Resumes the given collector. @@ -1196,8 +1242,10 @@ async def sample_resume_collector(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1271,7 +1319,7 @@ async def register_collector( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Registers the given collector. @@ -1316,8 +1364,10 @@ async def sample_register_collector(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1391,7 +1441,7 @@ async def pause_collector( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Pauses the given collector. @@ -1436,8 +1486,10 @@ async def sample_pause_collector(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1508,7 +1560,7 @@ async def list_operations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Lists operations that match the specified filter in the request. @@ -1519,8 +1571,10 @@ async def list_operations( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.ListOperationsResponse: Response message for ``ListOperations`` method. @@ -1561,7 +1615,7 @@ async def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -1572,8 +1626,10 @@ async def get_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. @@ -1614,7 +1670,7 @@ async def delete_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Deletes a long-running operation. @@ -1630,8 +1686,10 @@ async def delete_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: None """ @@ -1668,7 +1726,7 @@ async def cancel_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Starts asynchronous cancellation on a long-running operation. @@ -1683,8 +1741,10 @@ async def cancel_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: None """ @@ -1721,7 +1781,7 @@ async def get_location( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.Location: r"""Gets information about a location. @@ -1732,8 +1792,10 @@ async def get_location( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.Location: Location object. @@ -1774,7 +1836,7 @@ async def list_locations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.ListLocationsResponse: r"""Lists information about the supported locations for this service. @@ -1785,8 +1847,10 @@ async def list_locations( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.ListLocationsResponse: Response message for ``ListLocations`` method. diff --git a/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/client.py b/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/client.py index 1e33374b702f..8ccacf2ddd65 100644 --- a/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/client.py +++ b/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.location import locations_pb2 # type: ignore @@ -622,6 +632,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -688,6 +702,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient`.", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "credentialsType": None, + }, + ) + def create_collector( self, request: Optional[ @@ -699,7 +736,7 @@ def create_collector( collector_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Create a Collector to manage the on-prem appliance which collects information about Customer assets. @@ -760,8 +797,10 @@ def sample_create_collector(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -837,7 +876,7 @@ def create_annotation( annotation: Optional[api_entities.Annotation] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Creates an Annotation @@ -889,8 +928,10 @@ def sample_create_annotation(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -963,7 +1004,7 @@ def get_annotation( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> api_entities.Annotation: r"""Gets details of a single Annotation. @@ -1005,8 +1046,10 @@ def sample_get_annotation(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.rapidmigrationassessment_v1.types.Annotation: @@ -1064,7 +1107,7 @@ def list_collectors( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListCollectorsPager: r"""Lists Collectors in a given project and location. @@ -1109,8 +1152,10 @@ def sample_list_collectors(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.rapidmigrationassessment_v1.services.rapid_migration_assessment.pagers.ListCollectorsPager: @@ -1184,7 +1229,7 @@ def get_collector( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> api_entities.Collector: r"""Gets details of a single Collector. @@ -1226,8 +1271,10 @@ def sample_get_collector(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.rapidmigrationassessment_v1.types.Collector: @@ -1286,7 +1333,7 @@ def update_collector( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Updates the parameters of a single Collector. @@ -1341,8 +1388,10 @@ def sample_update_collector(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1417,7 +1466,7 @@ def delete_collector( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Deletes a single Collector - changes state of collector to "Deleting". Background jobs does final @@ -1464,8 +1513,10 @@ def sample_delete_collector(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1536,7 +1587,7 @@ def resume_collector( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Resumes the given collector. @@ -1581,8 +1632,10 @@ def sample_resume_collector(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1653,7 +1706,7 @@ def register_collector( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Registers the given collector. @@ -1698,8 +1751,10 @@ def sample_register_collector(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1770,7 +1825,7 @@ def pause_collector( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Pauses the given collector. @@ -1815,8 +1870,10 @@ def sample_pause_collector(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1897,7 +1954,7 @@ def list_operations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Lists operations that match the specified filter in the request. @@ -1908,8 +1965,10 @@ def list_operations( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.ListOperationsResponse: Response message for ``ListOperations`` method. @@ -1950,7 +2009,7 @@ def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -1961,8 +2020,10 @@ def get_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. @@ -2003,7 +2064,7 @@ def delete_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Deletes a long-running operation. @@ -2019,8 +2080,10 @@ def delete_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: None """ @@ -2057,7 +2120,7 @@ def cancel_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Starts asynchronous cancellation on a long-running operation. @@ -2072,8 +2135,10 @@ def cancel_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: None """ @@ -2110,7 +2175,7 @@ def get_location( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.Location: r"""Gets information about a location. @@ -2121,8 +2186,10 @@ def get_location( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.Location: Location object. @@ -2163,7 +2230,7 @@ def list_locations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.ListLocationsResponse: r"""Lists information about the supported locations for this service. @@ -2174,8 +2241,10 @@ def list_locations( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.ListLocationsResponse: Response message for ``ListLocations`` method. diff --git a/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/pagers.py b/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/pagers.py index bb8ba76a69fb..f286dbb0a3a1 100644 --- a/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/pagers.py +++ b/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/pagers.py @@ -70,7 +70,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -84,8 +84,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = rapidmigrationassessment.ListCollectorsRequest(request) @@ -146,7 +148,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -160,8 +162,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = rapidmigrationassessment.ListCollectorsRequest(request) diff --git a/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/transports/grpc.py b/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/transports/grpc.py index 15c865e79d20..7b5fbb8eb731 100644 --- a/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/transports/grpc.py +++ b/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -22,7 +25,10 @@ from google.auth.transport.grpc import SslCredentials # type: ignore from google.cloud.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.rapidmigrationassessment_v1.types import ( api_entities, @@ -31,6 +37,81 @@ from .base import DEFAULT_CLIENT_INFO, RapidMigrationAssessmentTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class RapidMigrationAssessmentGrpcTransport(RapidMigrationAssessmentTransport): """gRPC backend transport for RapidMigrationAssessment. @@ -185,7 +266,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -249,7 +335,9 @@ def operations_client(self) -> operations_v1.OperationsClient: """ # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + self._operations_client = operations_v1.OperationsClient( + self._logged_channel + ) # Return the client from cache. return self._operations_client @@ -276,7 +364,7 @@ def create_collector( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_collector" not in self._stubs: - self._stubs["create_collector"] = self.grpc_channel.unary_unary( + self._stubs["create_collector"] = self._logged_channel.unary_unary( "/google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment/CreateCollector", request_serializer=rapidmigrationassessment.CreateCollectorRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -304,7 +392,7 @@ def create_annotation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_annotation" not in self._stubs: - self._stubs["create_annotation"] = self.grpc_channel.unary_unary( + self._stubs["create_annotation"] = self._logged_channel.unary_unary( "/google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment/CreateAnnotation", request_serializer=rapidmigrationassessment.CreateAnnotationRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -332,7 +420,7 @@ def get_annotation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_annotation" not in self._stubs: - self._stubs["get_annotation"] = self.grpc_channel.unary_unary( + self._stubs["get_annotation"] = self._logged_channel.unary_unary( "/google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment/GetAnnotation", request_serializer=rapidmigrationassessment.GetAnnotationRequest.serialize, response_deserializer=api_entities.Annotation.deserialize, @@ -361,7 +449,7 @@ def list_collectors( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_collectors" not in self._stubs: - self._stubs["list_collectors"] = self.grpc_channel.unary_unary( + self._stubs["list_collectors"] = self._logged_channel.unary_unary( "/google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment/ListCollectors", request_serializer=rapidmigrationassessment.ListCollectorsRequest.serialize, response_deserializer=rapidmigrationassessment.ListCollectorsResponse.deserialize, @@ -389,7 +477,7 @@ def get_collector( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_collector" not in self._stubs: - self._stubs["get_collector"] = self.grpc_channel.unary_unary( + self._stubs["get_collector"] = self._logged_channel.unary_unary( "/google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment/GetCollector", request_serializer=rapidmigrationassessment.GetCollectorRequest.serialize, response_deserializer=api_entities.Collector.deserialize, @@ -417,7 +505,7 @@ def update_collector( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_collector" not in self._stubs: - self._stubs["update_collector"] = self.grpc_channel.unary_unary( + self._stubs["update_collector"] = self._logged_channel.unary_unary( "/google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment/UpdateCollector", request_serializer=rapidmigrationassessment.UpdateCollectorRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -447,7 +535,7 @@ def delete_collector( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_collector" not in self._stubs: - self._stubs["delete_collector"] = self.grpc_channel.unary_unary( + self._stubs["delete_collector"] = self._logged_channel.unary_unary( "/google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment/DeleteCollector", request_serializer=rapidmigrationassessment.DeleteCollectorRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -475,7 +563,7 @@ def resume_collector( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "resume_collector" not in self._stubs: - self._stubs["resume_collector"] = self.grpc_channel.unary_unary( + self._stubs["resume_collector"] = self._logged_channel.unary_unary( "/google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment/ResumeCollector", request_serializer=rapidmigrationassessment.ResumeCollectorRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -503,7 +591,7 @@ def register_collector( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "register_collector" not in self._stubs: - self._stubs["register_collector"] = self.grpc_channel.unary_unary( + self._stubs["register_collector"] = self._logged_channel.unary_unary( "/google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment/RegisterCollector", request_serializer=rapidmigrationassessment.RegisterCollectorRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -531,7 +619,7 @@ def pause_collector( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "pause_collector" not in self._stubs: - self._stubs["pause_collector"] = self.grpc_channel.unary_unary( + self._stubs["pause_collector"] = self._logged_channel.unary_unary( "/google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment/PauseCollector", request_serializer=rapidmigrationassessment.PauseCollectorRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -539,7 +627,7 @@ def pause_collector( return self._stubs["pause_collector"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def delete_operation( @@ -551,7 +639,7 @@ def delete_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_operation" not in self._stubs: - self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + self._stubs["delete_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/DeleteOperation", request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, response_deserializer=None, @@ -568,7 +656,7 @@ def cancel_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "cancel_operation" not in self._stubs: - self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + self._stubs["cancel_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/CancelOperation", request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, response_deserializer=None, @@ -585,7 +673,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, @@ -604,7 +692,7 @@ def list_operations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_operations" not in self._stubs: - self._stubs["list_operations"] = self.grpc_channel.unary_unary( + self._stubs["list_operations"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/ListOperations", request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, response_deserializer=operations_pb2.ListOperationsResponse.FromString, @@ -623,7 +711,7 @@ def list_locations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_locations" not in self._stubs: - self._stubs["list_locations"] = self.grpc_channel.unary_unary( + self._stubs["list_locations"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/ListLocations", request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, response_deserializer=locations_pb2.ListLocationsResponse.FromString, @@ -640,7 +728,7 @@ def get_location( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_location" not in self._stubs: - self._stubs["get_location"] = self.grpc_channel.unary_unary( + self._stubs["get_location"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/GetLocation", request_serializer=locations_pb2.GetLocationRequest.SerializeToString, response_deserializer=locations_pb2.Location.FromString, diff --git a/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/transports/grpc_asyncio.py b/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/transports/grpc_asyncio.py index b83001d64298..75be4c8df6cb 100644 --- a/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/transports/grpc_asyncio.py +++ b/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -24,8 +27,11 @@ from google.auth.transport.grpc import SslCredentials # type: ignore from google.cloud.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.rapidmigrationassessment_v1.types import ( api_entities, @@ -35,6 +41,82 @@ from .base import DEFAULT_CLIENT_INFO, RapidMigrationAssessmentTransport from .grpc import RapidMigrationAssessmentGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class RapidMigrationAssessmentGrpcAsyncIOTransport(RapidMigrationAssessmentTransport): """gRPC AsyncIO backend transport for RapidMigrationAssessment. @@ -232,10 +314,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -258,7 +343,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel + self._logged_channel ) # Return the client from cache. @@ -287,7 +372,7 @@ def create_collector( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_collector" not in self._stubs: - self._stubs["create_collector"] = self.grpc_channel.unary_unary( + self._stubs["create_collector"] = self._logged_channel.unary_unary( "/google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment/CreateCollector", request_serializer=rapidmigrationassessment.CreateCollectorRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -316,7 +401,7 @@ def create_annotation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_annotation" not in self._stubs: - self._stubs["create_annotation"] = self.grpc_channel.unary_unary( + self._stubs["create_annotation"] = self._logged_channel.unary_unary( "/google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment/CreateAnnotation", request_serializer=rapidmigrationassessment.CreateAnnotationRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -345,7 +430,7 @@ def get_annotation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_annotation" not in self._stubs: - self._stubs["get_annotation"] = self.grpc_channel.unary_unary( + self._stubs["get_annotation"] = self._logged_channel.unary_unary( "/google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment/GetAnnotation", request_serializer=rapidmigrationassessment.GetAnnotationRequest.serialize, response_deserializer=api_entities.Annotation.deserialize, @@ -374,7 +459,7 @@ def list_collectors( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_collectors" not in self._stubs: - self._stubs["list_collectors"] = self.grpc_channel.unary_unary( + self._stubs["list_collectors"] = self._logged_channel.unary_unary( "/google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment/ListCollectors", request_serializer=rapidmigrationassessment.ListCollectorsRequest.serialize, response_deserializer=rapidmigrationassessment.ListCollectorsResponse.deserialize, @@ -403,7 +488,7 @@ def get_collector( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_collector" not in self._stubs: - self._stubs["get_collector"] = self.grpc_channel.unary_unary( + self._stubs["get_collector"] = self._logged_channel.unary_unary( "/google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment/GetCollector", request_serializer=rapidmigrationassessment.GetCollectorRequest.serialize, response_deserializer=api_entities.Collector.deserialize, @@ -432,7 +517,7 @@ def update_collector( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_collector" not in self._stubs: - self._stubs["update_collector"] = self.grpc_channel.unary_unary( + self._stubs["update_collector"] = self._logged_channel.unary_unary( "/google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment/UpdateCollector", request_serializer=rapidmigrationassessment.UpdateCollectorRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -463,7 +548,7 @@ def delete_collector( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_collector" not in self._stubs: - self._stubs["delete_collector"] = self.grpc_channel.unary_unary( + self._stubs["delete_collector"] = self._logged_channel.unary_unary( "/google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment/DeleteCollector", request_serializer=rapidmigrationassessment.DeleteCollectorRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -492,7 +577,7 @@ def resume_collector( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "resume_collector" not in self._stubs: - self._stubs["resume_collector"] = self.grpc_channel.unary_unary( + self._stubs["resume_collector"] = self._logged_channel.unary_unary( "/google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment/ResumeCollector", request_serializer=rapidmigrationassessment.ResumeCollectorRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -521,7 +606,7 @@ def register_collector( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "register_collector" not in self._stubs: - self._stubs["register_collector"] = self.grpc_channel.unary_unary( + self._stubs["register_collector"] = self._logged_channel.unary_unary( "/google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment/RegisterCollector", request_serializer=rapidmigrationassessment.RegisterCollectorRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -550,7 +635,7 @@ def pause_collector( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "pause_collector" not in self._stubs: - self._stubs["pause_collector"] = self.grpc_channel.unary_unary( + self._stubs["pause_collector"] = self._logged_channel.unary_unary( "/google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment/PauseCollector", request_serializer=rapidmigrationassessment.PauseCollectorRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -678,7 +763,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: @@ -694,7 +779,7 @@ def delete_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_operation" not in self._stubs: - self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + self._stubs["delete_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/DeleteOperation", request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, response_deserializer=None, @@ -711,7 +796,7 @@ def cancel_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "cancel_operation" not in self._stubs: - self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + self._stubs["cancel_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/CancelOperation", request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, response_deserializer=None, @@ -728,7 +813,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, @@ -747,7 +832,7 @@ def list_operations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_operations" not in self._stubs: - self._stubs["list_operations"] = self.grpc_channel.unary_unary( + self._stubs["list_operations"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/ListOperations", request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, response_deserializer=operations_pb2.ListOperationsResponse.FromString, @@ -766,7 +851,7 @@ def list_locations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_locations" not in self._stubs: - self._stubs["list_locations"] = self.grpc_channel.unary_unary( + self._stubs["list_locations"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/ListLocations", request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, response_deserializer=locations_pb2.ListLocationsResponse.FromString, @@ -783,7 +868,7 @@ def get_location( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_location" not in self._stubs: - self._stubs["get_location"] = self.grpc_channel.unary_unary( + self._stubs["get_location"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/GetLocation", request_serializer=locations_pb2.GetLocationRequest.SerializeToString, response_deserializer=locations_pb2.Location.FromString, diff --git a/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/transports/rest.py b/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/transports/rest.py index 8f9c9e8cd99e..714507957c5a 100644 --- a/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/transports/rest.py +++ b/packages/google-cloud-rapidmigrationassessment/google/cloud/rapidmigrationassessment_v1/services/rapid_migration_assessment/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -42,6 +42,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -154,9 +162,10 @@ def post_update_collector(self, response): def pre_create_annotation( self, request: rapidmigrationassessment.CreateAnnotationRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - rapidmigrationassessment.CreateAnnotationRequest, Sequence[Tuple[str, str]] + rapidmigrationassessment.CreateAnnotationRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for create_annotation @@ -179,9 +188,10 @@ def post_create_annotation( def pre_create_collector( self, request: rapidmigrationassessment.CreateCollectorRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - rapidmigrationassessment.CreateCollectorRequest, Sequence[Tuple[str, str]] + rapidmigrationassessment.CreateCollectorRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for create_collector @@ -204,9 +214,10 @@ def post_create_collector( def pre_delete_collector( self, request: rapidmigrationassessment.DeleteCollectorRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - rapidmigrationassessment.DeleteCollectorRequest, Sequence[Tuple[str, str]] + rapidmigrationassessment.DeleteCollectorRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for delete_collector @@ -229,9 +240,10 @@ def post_delete_collector( def pre_get_annotation( self, request: rapidmigrationassessment.GetAnnotationRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - rapidmigrationassessment.GetAnnotationRequest, Sequence[Tuple[str, str]] + rapidmigrationassessment.GetAnnotationRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for get_annotation @@ -254,8 +266,11 @@ def post_get_annotation( def pre_get_collector( self, request: rapidmigrationassessment.GetCollectorRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[rapidmigrationassessment.GetCollectorRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + rapidmigrationassessment.GetCollectorRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for get_collector Override in a subclass to manipulate the request or metadata @@ -277,9 +292,10 @@ def post_get_collector( def pre_list_collectors( self, request: rapidmigrationassessment.ListCollectorsRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - rapidmigrationassessment.ListCollectorsRequest, Sequence[Tuple[str, str]] + rapidmigrationassessment.ListCollectorsRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for list_collectors @@ -302,9 +318,10 @@ def post_list_collectors( def pre_pause_collector( self, request: rapidmigrationassessment.PauseCollectorRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - rapidmigrationassessment.PauseCollectorRequest, Sequence[Tuple[str, str]] + rapidmigrationassessment.PauseCollectorRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for pause_collector @@ -327,9 +344,10 @@ def post_pause_collector( def pre_register_collector( self, request: rapidmigrationassessment.RegisterCollectorRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - rapidmigrationassessment.RegisterCollectorRequest, Sequence[Tuple[str, str]] + rapidmigrationassessment.RegisterCollectorRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for register_collector @@ -352,9 +370,10 @@ def post_register_collector( def pre_resume_collector( self, request: rapidmigrationassessment.ResumeCollectorRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - rapidmigrationassessment.ResumeCollectorRequest, Sequence[Tuple[str, str]] + rapidmigrationassessment.ResumeCollectorRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for resume_collector @@ -377,9 +396,10 @@ def post_resume_collector( def pre_update_collector( self, request: rapidmigrationassessment.UpdateCollectorRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - rapidmigrationassessment.UpdateCollectorRequest, Sequence[Tuple[str, str]] + rapidmigrationassessment.UpdateCollectorRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for update_collector @@ -402,8 +422,10 @@ def post_update_collector( def pre_get_location( self, request: locations_pb2.GetLocationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[locations_pb2.GetLocationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + locations_pb2.GetLocationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_location Override in a subclass to manipulate the request or metadata @@ -425,8 +447,10 @@ def post_get_location( def pre_list_locations( self, request: locations_pb2.ListLocationsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[locations_pb2.ListLocationsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + locations_pb2.ListLocationsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_locations Override in a subclass to manipulate the request or metadata @@ -448,8 +472,10 @@ def post_list_locations( def pre_cancel_operation( self, request: operations_pb2.CancelOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.CancelOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.CancelOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for cancel_operation Override in a subclass to manipulate the request or metadata @@ -469,8 +495,10 @@ def post_cancel_operation(self, response: None) -> None: def pre_delete_operation( self, request: operations_pb2.DeleteOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.DeleteOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.DeleteOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for delete_operation Override in a subclass to manipulate the request or metadata @@ -490,8 +518,10 @@ def post_delete_operation(self, response: None) -> None: def pre_get_operation( self, request: operations_pb2.GetOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.GetOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.GetOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_operation Override in a subclass to manipulate the request or metadata @@ -513,8 +543,10 @@ def post_get_operation( def pre_list_operations( self, request: operations_pb2.ListOperationsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.ListOperationsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.ListOperationsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_operations Override in a subclass to manipulate the request or metadata @@ -710,7 +742,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the create annotation method over HTTP. @@ -720,8 +752,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -734,6 +768,7 @@ def __call__( http_options = ( _BaseRapidMigrationAssessmentRestTransport._BaseCreateAnnotation._get_http_options() ) + request, metadata = self._interceptor.pre_create_annotation( request, metadata ) @@ -750,6 +785,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.CreateAnnotation", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "CreateAnnotation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( RapidMigrationAssessmentRestTransport._CreateAnnotation._get_response( @@ -771,7 +833,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_annotation(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.create_annotation", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "CreateAnnotation", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _CreateCollector( @@ -810,7 +894,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the create collector method over HTTP. @@ -820,8 +904,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -834,6 +920,7 @@ def __call__( http_options = ( _BaseRapidMigrationAssessmentRestTransport._BaseCreateCollector._get_http_options() ) + request, metadata = self._interceptor.pre_create_collector( request, metadata ) @@ -850,6 +937,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.CreateCollector", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "CreateCollector", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( RapidMigrationAssessmentRestTransport._CreateCollector._get_response( @@ -871,7 +985,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_collector(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.create_collector", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "CreateCollector", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DeleteCollector( @@ -909,7 +1045,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the delete collector method over HTTP. @@ -919,8 +1055,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -933,6 +1071,7 @@ def __call__( http_options = ( _BaseRapidMigrationAssessmentRestTransport._BaseDeleteCollector._get_http_options() ) + request, metadata = self._interceptor.pre_delete_collector( request, metadata ) @@ -945,6 +1084,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.DeleteCollector", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "DeleteCollector", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( RapidMigrationAssessmentRestTransport._DeleteCollector._get_response( @@ -965,7 +1131,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_delete_collector(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.delete_collector", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "DeleteCollector", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetAnnotation( @@ -1003,7 +1191,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> api_entities.Annotation: r"""Call the get annotation method over HTTP. @@ -1014,8 +1202,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.api_entities.Annotation: @@ -1025,6 +1215,7 @@ def __call__( http_options = ( _BaseRapidMigrationAssessmentRestTransport._BaseGetAnnotation._get_http_options() ) + request, metadata = self._interceptor.pre_get_annotation(request, metadata) transcoded_request = _BaseRapidMigrationAssessmentRestTransport._BaseGetAnnotation._get_transcoded_request( http_options, request @@ -1035,6 +1226,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.GetAnnotation", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "GetAnnotation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( RapidMigrationAssessmentRestTransport._GetAnnotation._get_response( @@ -1057,7 +1275,29 @@ def __call__( pb_resp = api_entities.Annotation.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_annotation(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = api_entities.Annotation.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.get_annotation", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "GetAnnotation", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetCollector( @@ -1095,7 +1335,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> api_entities.Collector: r"""Call the get collector method over HTTP. @@ -1106,8 +1346,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.api_entities.Collector: @@ -1117,6 +1359,7 @@ def __call__( http_options = ( _BaseRapidMigrationAssessmentRestTransport._BaseGetCollector._get_http_options() ) + request, metadata = self._interceptor.pre_get_collector(request, metadata) transcoded_request = _BaseRapidMigrationAssessmentRestTransport._BaseGetCollector._get_transcoded_request( http_options, request @@ -1127,6 +1370,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.GetCollector", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "GetCollector", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( RapidMigrationAssessmentRestTransport._GetCollector._get_response( @@ -1149,7 +1419,29 @@ def __call__( pb_resp = api_entities.Collector.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_collector(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = api_entities.Collector.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.get_collector", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "GetCollector", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListCollectors( @@ -1187,7 +1479,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> rapidmigrationassessment.ListCollectorsResponse: r"""Call the list collectors method over HTTP. @@ -1198,8 +1490,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.rapidmigrationassessment.ListCollectorsResponse: @@ -1211,6 +1505,7 @@ def __call__( http_options = ( _BaseRapidMigrationAssessmentRestTransport._BaseListCollectors._get_http_options() ) + request, metadata = self._interceptor.pre_list_collectors(request, metadata) transcoded_request = _BaseRapidMigrationAssessmentRestTransport._BaseListCollectors._get_transcoded_request( http_options, request @@ -1221,6 +1516,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.ListCollectors", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "ListCollectors", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( RapidMigrationAssessmentRestTransport._ListCollectors._get_response( @@ -1243,7 +1565,33 @@ def __call__( pb_resp = rapidmigrationassessment.ListCollectorsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_collectors(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + rapidmigrationassessment.ListCollectorsResponse.to_json( + response + ) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.list_collectors", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "ListCollectors", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _PauseCollector( @@ -1282,7 +1630,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the pause collector method over HTTP. @@ -1292,8 +1640,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1306,6 +1656,7 @@ def __call__( http_options = ( _BaseRapidMigrationAssessmentRestTransport._BasePauseCollector._get_http_options() ) + request, metadata = self._interceptor.pre_pause_collector(request, metadata) transcoded_request = _BaseRapidMigrationAssessmentRestTransport._BasePauseCollector._get_transcoded_request( http_options, request @@ -1320,6 +1671,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.PauseCollector", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "PauseCollector", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( RapidMigrationAssessmentRestTransport._PauseCollector._get_response( @@ -1341,7 +1719,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_pause_collector(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.pause_collector", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "PauseCollector", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _RegisterCollector( @@ -1380,7 +1780,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the register collector method over HTTP. @@ -1390,8 +1790,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1404,6 +1806,7 @@ def __call__( http_options = ( _BaseRapidMigrationAssessmentRestTransport._BaseRegisterCollector._get_http_options() ) + request, metadata = self._interceptor.pre_register_collector( request, metadata ) @@ -1420,6 +1823,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.RegisterCollector", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "RegisterCollector", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( RapidMigrationAssessmentRestTransport._RegisterCollector._get_response( @@ -1441,7 +1871,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_register_collector(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.register_collector", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "RegisterCollector", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ResumeCollector( @@ -1480,7 +1932,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the resume collector method over HTTP. @@ -1490,8 +1942,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1504,6 +1958,7 @@ def __call__( http_options = ( _BaseRapidMigrationAssessmentRestTransport._BaseResumeCollector._get_http_options() ) + request, metadata = self._interceptor.pre_resume_collector( request, metadata ) @@ -1520,6 +1975,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.ResumeCollector", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "ResumeCollector", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( RapidMigrationAssessmentRestTransport._ResumeCollector._get_response( @@ -1541,7 +2023,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_resume_collector(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.resume_collector", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "ResumeCollector", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateCollector( @@ -1580,7 +2084,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the update collector method over HTTP. @@ -1590,8 +2094,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1604,6 +2110,7 @@ def __call__( http_options = ( _BaseRapidMigrationAssessmentRestTransport._BaseUpdateCollector._get_http_options() ) + request, metadata = self._interceptor.pre_update_collector( request, metadata ) @@ -1620,6 +2127,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.UpdateCollector", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "UpdateCollector", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( RapidMigrationAssessmentRestTransport._UpdateCollector._get_response( @@ -1641,7 +2175,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_collector(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.update_collector", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "UpdateCollector", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property @@ -1784,7 +2340,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.Location: r"""Call the get location method over HTTP. @@ -1794,8 +2350,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: locations_pb2.Location: Response from GetLocation method. @@ -1804,6 +2362,7 @@ def __call__( http_options = ( _BaseRapidMigrationAssessmentRestTransport._BaseGetLocation._get_http_options() ) + request, metadata = self._interceptor.pre_get_location(request, metadata) transcoded_request = _BaseRapidMigrationAssessmentRestTransport._BaseGetLocation._get_transcoded_request( http_options, request @@ -1814,6 +2373,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.GetLocation", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "GetLocation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RapidMigrationAssessmentRestTransport._GetLocation._get_response( self._host, @@ -1833,6 +2419,27 @@ def __call__( resp = locations_pb2.Location() resp = json_format.Parse(content, resp) resp = self._interceptor.post_get_location(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentAsyncClient.GetLocation", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "GetLocation", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property @@ -1874,7 +2481,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.ListLocationsResponse: r"""Call the list locations method over HTTP. @@ -1884,8 +2491,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: locations_pb2.ListLocationsResponse: Response from ListLocations method. @@ -1894,6 +2503,7 @@ def __call__( http_options = ( _BaseRapidMigrationAssessmentRestTransport._BaseListLocations._get_http_options() ) + request, metadata = self._interceptor.pre_list_locations(request, metadata) transcoded_request = _BaseRapidMigrationAssessmentRestTransport._BaseListLocations._get_transcoded_request( http_options, request @@ -1904,6 +2514,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.ListLocations", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "ListLocations", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( RapidMigrationAssessmentRestTransport._ListLocations._get_response( @@ -1925,6 +2562,27 @@ def __call__( resp = locations_pb2.ListLocationsResponse() resp = json_format.Parse(content, resp) resp = self._interceptor.post_list_locations(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentAsyncClient.ListLocations", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "ListLocations", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property @@ -1967,7 +2625,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Call the cancel operation method over HTTP. @@ -1977,13 +2635,16 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ http_options = ( _BaseRapidMigrationAssessmentRestTransport._BaseCancelOperation._get_http_options() ) + request, metadata = self._interceptor.pre_cancel_operation( request, metadata ) @@ -2000,6 +2661,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.CancelOperation", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "CancelOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( RapidMigrationAssessmentRestTransport._CancelOperation._get_response( @@ -2059,7 +2747,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Call the delete operation method over HTTP. @@ -2069,13 +2757,16 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ http_options = ( _BaseRapidMigrationAssessmentRestTransport._BaseDeleteOperation._get_http_options() ) + request, metadata = self._interceptor.pre_delete_operation( request, metadata ) @@ -2088,6 +2779,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.DeleteOperation", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "DeleteOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( RapidMigrationAssessmentRestTransport._DeleteOperation._get_response( @@ -2146,7 +2864,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the get operation method over HTTP. @@ -2156,8 +2874,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: operations_pb2.Operation: Response from GetOperation method. @@ -2166,6 +2886,7 @@ def __call__( http_options = ( _BaseRapidMigrationAssessmentRestTransport._BaseGetOperation._get_http_options() ) + request, metadata = self._interceptor.pre_get_operation(request, metadata) transcoded_request = _BaseRapidMigrationAssessmentRestTransport._BaseGetOperation._get_transcoded_request( http_options, request @@ -2176,6 +2897,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.GetOperation", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "GetOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( RapidMigrationAssessmentRestTransport._GetOperation._get_response( @@ -2197,6 +2945,27 @@ def __call__( resp = operations_pb2.Operation() resp = json_format.Parse(content, resp) resp = self._interceptor.post_get_operation(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentAsyncClient.GetOperation", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "GetOperation", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property @@ -2238,7 +3007,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Call the list operations method over HTTP. @@ -2248,8 +3017,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: operations_pb2.ListOperationsResponse: Response from ListOperations method. @@ -2258,6 +3029,7 @@ def __call__( http_options = ( _BaseRapidMigrationAssessmentRestTransport._BaseListOperations._get_http_options() ) + request, metadata = self._interceptor.pre_list_operations(request, metadata) transcoded_request = _BaseRapidMigrationAssessmentRestTransport._BaseListOperations._get_transcoded_request( http_options, request @@ -2268,6 +3040,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentClient.ListOperations", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "ListOperations", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( RapidMigrationAssessmentRestTransport._ListOperations._get_response( @@ -2289,6 +3088,27 @@ def __call__( resp = operations_pb2.ListOperationsResponse() resp = json_format.Parse(content, resp) resp = self._interceptor.post_list_operations(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.rapidmigrationassessment_v1.RapidMigrationAssessmentAsyncClient.ListOperations", + extra={ + "serviceName": "google.cloud.rapidmigrationassessment.v1.RapidMigrationAssessment", + "rpcName": "ListOperations", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property diff --git a/packages/google-cloud-rapidmigrationassessment/samples/generated_samples/snippet_metadata_google.cloud.rapidmigrationassessment.v1.json b/packages/google-cloud-rapidmigrationassessment/samples/generated_samples/snippet_metadata_google.cloud.rapidmigrationassessment.v1.json index 9e610eb890fc..2c00dccb6124 100644 --- a/packages/google-cloud-rapidmigrationassessment/samples/generated_samples/snippet_metadata_google.cloud.rapidmigrationassessment.v1.json +++ b/packages/google-cloud-rapidmigrationassessment/samples/generated_samples/snippet_metadata_google.cloud.rapidmigrationassessment.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-rapidmigrationassessment", - "version": "0.1.11" + "version": "0.1.0" }, "snippets": [ { @@ -51,7 +51,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -135,7 +135,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -224,7 +224,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -312,7 +312,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -393,7 +393,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -473,7 +473,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -554,7 +554,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.rapidmigrationassessment_v1.types.Annotation", @@ -634,7 +634,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.rapidmigrationassessment_v1.types.Annotation", @@ -715,7 +715,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.rapidmigrationassessment_v1.types.Collector", @@ -795,7 +795,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.rapidmigrationassessment_v1.types.Collector", @@ -876,7 +876,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.rapidmigrationassessment_v1.services.rapid_migration_assessment.pagers.ListCollectorsAsyncPager", @@ -956,7 +956,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.rapidmigrationassessment_v1.services.rapid_migration_assessment.pagers.ListCollectorsPager", @@ -1037,7 +1037,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -1117,7 +1117,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -1198,7 +1198,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -1278,7 +1278,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -1359,7 +1359,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -1439,7 +1439,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -1524,7 +1524,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -1608,7 +1608,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", diff --git a/packages/google-cloud-rapidmigrationassessment/tests/unit/gapic/rapidmigrationassessment_v1/test_rapid_migration_assessment.py b/packages/google-cloud-rapidmigrationassessment/tests/unit/gapic/rapidmigrationassessment_v1/test_rapid_migration_assessment.py index 4a1e2c25d457..78aa30177f24 100644 --- a/packages/google-cloud-rapidmigrationassessment/tests/unit/gapic/rapidmigrationassessment_v1/test_rapid_migration_assessment.py +++ b/packages/google-cloud-rapidmigrationassessment/tests/unit/gapic/rapidmigrationassessment_v1/test_rapid_migration_assessment.py @@ -4874,6 +4874,7 @@ def test_create_collector_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_collector(request) @@ -4939,6 +4940,7 @@ def test_create_collector_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_collector(**mock_args) @@ -5077,6 +5079,7 @@ def test_create_annotation_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_annotation(request) @@ -5129,6 +5132,7 @@ def test_create_annotation_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_annotation(**mock_args) @@ -5261,6 +5265,7 @@ def test_get_annotation_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_annotation(request) @@ -5308,6 +5313,7 @@ def test_get_annotation_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_annotation(**mock_args) @@ -5450,6 +5456,7 @@ def test_list_collectors_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_collectors(request) @@ -5505,6 +5512,7 @@ def test_list_collectors_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_collectors(**mock_args) @@ -5698,6 +5706,7 @@ def test_get_collector_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_collector(request) @@ -5745,6 +5754,7 @@ def test_get_collector_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_collector(**mock_args) @@ -5881,6 +5891,7 @@ def test_update_collector_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_collector(request) @@ -5942,6 +5953,7 @@ def test_update_collector_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_collector(**mock_args) @@ -6079,6 +6091,7 @@ def test_delete_collector_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_collector(request) @@ -6124,6 +6137,7 @@ def test_delete_collector_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_collector(**mock_args) @@ -6258,6 +6272,7 @@ def test_resume_collector_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.resume_collector(request) @@ -6303,6 +6318,7 @@ def test_resume_collector_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.resume_collector(**mock_args) @@ -6440,6 +6456,7 @@ def test_register_collector_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.register_collector(request) @@ -6485,6 +6502,7 @@ def test_register_collector_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.register_collector(**mock_args) @@ -6618,6 +6636,7 @@ def test_pause_collector_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.pause_collector(request) @@ -6663,6 +6682,7 @@ def test_pause_collector_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.pause_collector(**mock_args) @@ -7325,6 +7345,7 @@ def test_create_collector_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_collector(request) @@ -7441,6 +7462,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_collector(request) # Establish that the response is the type that we expect. @@ -7482,6 +7504,7 @@ def test_create_collector_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -7526,6 +7549,7 @@ def test_create_annotation_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_annotation(request) @@ -7632,6 +7656,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_annotation(request) # Establish that the response is the type that we expect. @@ -7673,6 +7698,7 @@ def test_create_annotation_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -7717,6 +7743,7 @@ def test_get_annotation_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_annotation(request) @@ -7753,6 +7780,7 @@ def test_get_annotation_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_annotation(request) # Establish that the response is the type that we expect. @@ -7794,6 +7822,7 @@ def test_get_annotation_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = api_entities.Annotation.to_json(api_entities.Annotation()) req.return_value.content = return_value @@ -7838,6 +7867,7 @@ def test_list_collectors_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_collectors(request) @@ -7874,6 +7904,7 @@ def test_list_collectors_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_collectors(request) # Establish that the response is the type that we expect. @@ -7915,6 +7946,7 @@ def test_list_collectors_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = rapidmigrationassessment.ListCollectorsResponse.to_json( rapidmigrationassessment.ListCollectorsResponse() ) @@ -7961,6 +7993,7 @@ def test_get_collector_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_collector(request) @@ -8005,6 +8038,7 @@ def test_get_collector_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_collector(request) # Establish that the response is the type that we expect. @@ -8054,6 +8088,7 @@ def test_get_collector_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = api_entities.Collector.to_json(api_entities.Collector()) req.return_value.content = return_value @@ -8100,6 +8135,7 @@ def test_update_collector_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_collector(request) @@ -8218,6 +8254,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_collector(request) # Establish that the response is the type that we expect. @@ -8259,6 +8296,7 @@ def test_update_collector_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -8303,6 +8341,7 @@ def test_delete_collector_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_collector(request) @@ -8333,6 +8372,7 @@ def test_delete_collector_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_collector(request) # Establish that the response is the type that we expect. @@ -8374,6 +8414,7 @@ def test_delete_collector_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -8418,6 +8459,7 @@ def test_resume_collector_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.resume_collector(request) @@ -8448,6 +8490,7 @@ def test_resume_collector_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.resume_collector(request) # Establish that the response is the type that we expect. @@ -8489,6 +8532,7 @@ def test_resume_collector_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -8533,6 +8577,7 @@ def test_register_collector_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.register_collector(request) @@ -8563,6 +8608,7 @@ def test_register_collector_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.register_collector(request) # Establish that the response is the type that we expect. @@ -8604,6 +8650,7 @@ def test_register_collector_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -8648,6 +8695,7 @@ def test_pause_collector_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.pause_collector(request) @@ -8678,6 +8726,7 @@ def test_pause_collector_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.pause_collector(request) # Establish that the response is the type that we expect. @@ -8719,6 +8768,7 @@ def test_pause_collector_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -8763,6 +8813,7 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_location(request) @@ -8793,6 +8844,7 @@ def test_get_location_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_location(request) @@ -8821,6 +8873,7 @@ def test_list_locations_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_locations(request) @@ -8851,6 +8904,7 @@ def test_list_locations_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_locations(request) @@ -8881,6 +8935,7 @@ def test_cancel_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.cancel_operation(request) @@ -8911,6 +8966,7 @@ def test_cancel_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.cancel_operation(request) @@ -8941,6 +8997,7 @@ def test_delete_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_operation(request) @@ -8971,6 +9028,7 @@ def test_delete_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_operation(request) @@ -9001,6 +9059,7 @@ def test_get_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_operation(request) @@ -9031,6 +9090,7 @@ def test_get_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_operation(request) @@ -9061,6 +9121,7 @@ def test_list_operations_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_operations(request) @@ -9091,6 +9152,7 @@ def test_list_operations_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_operations(request) diff --git a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/async_client.py b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/async_client.py index c93583c25687..484effa463cd 100644 --- a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/async_client.py +++ b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -54,6 +55,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, RecaptchaEnterpriseServiceTransport from .transports.grpc_asyncio import RecaptchaEnterpriseServiceGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class RecaptchaEnterpriseServiceAsyncClient: """Service to determine the likelihood an event is legitimate.""" @@ -297,6 +307,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.recaptchaenterprise_v1.RecaptchaEnterpriseServiceAsyncClient`.", + extra={ + "serviceName": "google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService", + "credentialsType": None, + }, + ) + async def create_assessment( self, request: Optional[ @@ -307,7 +339,7 @@ async def create_assessment( assessment: Optional[recaptchaenterprise.Assessment] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.Assessment: r"""Creates an Assessment of the likelihood an event is legitimate. @@ -358,8 +390,10 @@ async def sample_create_assessment(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.Assessment: @@ -427,7 +461,7 @@ async def annotate_assessment( ] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.AnnotateAssessmentResponse: r"""Annotates a previously created Assessment to provide additional information on whether the event turned out @@ -483,8 +517,10 @@ async def sample_annotate_assessment(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.AnnotateAssessmentResponse: @@ -548,7 +584,7 @@ async def create_key( key: Optional[recaptchaenterprise.Key] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.Key: r"""Creates a new reCAPTCHA Enterprise key. @@ -603,8 +639,10 @@ async def sample_create_key(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.Key: @@ -668,7 +706,7 @@ async def list_keys( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListKeysAsyncPager: r"""Returns the list of all keys that belong to a project. @@ -713,8 +751,10 @@ async def sample_list_keys(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListKeysAsyncPager: @@ -791,7 +831,7 @@ async def retrieve_legacy_secret_key( key: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.RetrieveLegacySecretKeyResponse: r"""Returns the secret key related to the specified public key. You must use the legacy secret key only in a @@ -838,8 +878,10 @@ async def sample_retrieve_legacy_secret_key(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.RetrieveLegacySecretKeyResponse: @@ -901,7 +943,7 @@ async def get_key( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.Key: r"""Returns the specified key. @@ -944,8 +986,10 @@ async def sample_get_key(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.Key: @@ -1006,7 +1050,7 @@ async def update_key( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.Key: r"""Updates the specified key. @@ -1060,8 +1104,10 @@ async def sample_update_key(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.Key: @@ -1125,7 +1171,7 @@ async def delete_key( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Deletes the specified key. @@ -1165,8 +1211,10 @@ async def sample_delete_key(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ # Create or coerce a protobuf request object. # - Quick check: If we got a request object, we should *not* have @@ -1217,7 +1265,7 @@ async def migrate_key( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.Key: r"""Migrates an existing key from reCAPTCHA to reCAPTCHA Enterprise. Once a key is migrated, it can be used from @@ -1259,8 +1307,10 @@ async def sample_migrate_key(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.Key: @@ -1309,7 +1359,7 @@ async def add_ip_override( ip_override_data: Optional[recaptchaenterprise.IpOverrideData] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.AddIpOverrideResponse: r"""Adds an IP override to a key. The following restrictions hold: @@ -1369,8 +1419,10 @@ async def sample_add_ip_override(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.AddIpOverrideResponse: @@ -1434,7 +1486,7 @@ async def remove_ip_override( ip_override_data: Optional[recaptchaenterprise.IpOverrideData] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.RemoveIpOverrideResponse: r"""Removes an IP override from a key. The following restrictions hold: @@ -1497,8 +1549,10 @@ async def sample_remove_ip_override(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.RemoveIpOverrideResponse: @@ -1561,7 +1615,7 @@ async def list_ip_overrides( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListIpOverridesAsyncPager: r"""Lists all IP overrides for a key. @@ -1605,8 +1659,10 @@ async def sample_list_ip_overrides(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListIpOverridesAsyncPager: @@ -1681,7 +1737,7 @@ async def get_metrics( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.Metrics: r"""Get some aggregated metrics for a Key. This data can be used to build dashboards. @@ -1725,8 +1781,10 @@ async def sample_get_metrics(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.Metrics: @@ -1788,7 +1846,7 @@ async def create_firewall_policy( firewall_policy: Optional[recaptchaenterprise.FirewallPolicy] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.FirewallPolicy: r"""Creates a new FirewallPolicy, specifying conditions at which reCAPTCHA Enterprise actions can be executed. A @@ -1841,8 +1899,10 @@ async def sample_create_firewall_policy(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.FirewallPolicy: @@ -1908,7 +1968,7 @@ async def list_firewall_policies( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListFirewallPoliciesAsyncPager: r"""Returns the list of all firewall policies that belong to a project. @@ -1954,8 +2014,10 @@ async def sample_list_firewall_policies(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListFirewallPoliciesAsyncPager: @@ -2032,7 +2094,7 @@ async def get_firewall_policy( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.FirewallPolicy: r"""Returns the specified firewall policy. @@ -2077,8 +2139,10 @@ async def sample_get_firewall_policy(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.FirewallPolicy: @@ -2143,7 +2207,7 @@ async def update_firewall_policy( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.FirewallPolicy: r"""Updates the specified firewall policy. @@ -2193,8 +2257,10 @@ async def sample_update_firewall_policy(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.FirewallPolicy: @@ -2262,7 +2328,7 @@ async def delete_firewall_policy( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Deletes the specified firewall policy. @@ -2304,8 +2370,10 @@ async def sample_delete_firewall_policy(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ # Create or coerce a protobuf request object. # - Quick check: If we got a request object, we should *not* have @@ -2360,7 +2428,7 @@ async def reorder_firewall_policies( names: Optional[MutableSequence[str]] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.ReorderFirewallPoliciesResponse: r"""Reorders all firewall policies. @@ -2413,8 +2481,10 @@ async def sample_reorder_firewall_policies(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.ReorderFirewallPoliciesResponse: @@ -2479,7 +2549,7 @@ async def list_related_account_groups( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListRelatedAccountGroupsAsyncPager: r"""List groups of related accounts. @@ -2525,8 +2595,10 @@ async def sample_list_related_account_groups(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListRelatedAccountGroupsAsyncPager: @@ -2602,7 +2674,7 @@ async def list_related_account_group_memberships( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListRelatedAccountGroupMembershipsAsyncPager: r"""Get memberships in a group of related accounts. @@ -2648,8 +2720,10 @@ async def sample_list_related_account_group_memberships(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListRelatedAccountGroupMembershipsAsyncPager: @@ -2731,7 +2805,7 @@ async def search_related_account_group_memberships( hashed_account_id: Optional[bytes] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.SearchRelatedAccountGroupMembershipsAsyncPager: r"""Search group memberships related to a given account. @@ -2789,8 +2863,10 @@ async def sample_search_related_account_group_memberships(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.SearchRelatedAccountGroupMembershipsAsyncPager: diff --git a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/client.py b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/client.py index 8bc83a54de8e..7dac0be6025a 100644 --- a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/client.py +++ b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -682,6 +692,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -748,6 +762,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.recaptchaenterprise_v1.RecaptchaEnterpriseServiceClient`.", + extra={ + "serviceName": "google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService", + "credentialsType": None, + }, + ) + def create_assessment( self, request: Optional[ @@ -758,7 +795,7 @@ def create_assessment( assessment: Optional[recaptchaenterprise.Assessment] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.Assessment: r"""Creates an Assessment of the likelihood an event is legitimate. @@ -809,8 +846,10 @@ def sample_create_assessment(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.Assessment: @@ -875,7 +914,7 @@ def annotate_assessment( ] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.AnnotateAssessmentResponse: r"""Annotates a previously created Assessment to provide additional information on whether the event turned out @@ -931,8 +970,10 @@ def sample_annotate_assessment(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.AnnotateAssessmentResponse: @@ -993,7 +1034,7 @@ def create_key( key: Optional[recaptchaenterprise.Key] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.Key: r"""Creates a new reCAPTCHA Enterprise key. @@ -1048,8 +1089,10 @@ def sample_create_key(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.Key: @@ -1110,7 +1153,7 @@ def list_keys( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListKeysPager: r"""Returns the list of all keys that belong to a project. @@ -1155,8 +1198,10 @@ def sample_list_keys(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListKeysPager: @@ -1230,7 +1275,7 @@ def retrieve_legacy_secret_key( key: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.RetrieveLegacySecretKeyResponse: r"""Returns the secret key related to the specified public key. You must use the legacy secret key only in a @@ -1277,8 +1322,10 @@ def sample_retrieve_legacy_secret_key(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.RetrieveLegacySecretKeyResponse: @@ -1339,7 +1386,7 @@ def get_key( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.Key: r"""Returns the specified key. @@ -1382,8 +1429,10 @@ def sample_get_key(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.Key: @@ -1443,7 +1492,7 @@ def update_key( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.Key: r"""Updates the specified key. @@ -1497,8 +1546,10 @@ def sample_update_key(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.Key: @@ -1559,7 +1610,7 @@ def delete_key( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Deletes the specified key. @@ -1599,8 +1650,10 @@ def sample_delete_key(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ # Create or coerce a protobuf request object. # - Quick check: If we got a request object, we should *not* have @@ -1648,7 +1701,7 @@ def migrate_key( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.Key: r"""Migrates an existing key from reCAPTCHA to reCAPTCHA Enterprise. Once a key is migrated, it can be used from @@ -1690,8 +1743,10 @@ def sample_migrate_key(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.Key: @@ -1738,7 +1793,7 @@ def add_ip_override( ip_override_data: Optional[recaptchaenterprise.IpOverrideData] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.AddIpOverrideResponse: r"""Adds an IP override to a key. The following restrictions hold: @@ -1798,8 +1853,10 @@ def sample_add_ip_override(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.AddIpOverrideResponse: @@ -1860,7 +1917,7 @@ def remove_ip_override( ip_override_data: Optional[recaptchaenterprise.IpOverrideData] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.RemoveIpOverrideResponse: r"""Removes an IP override from a key. The following restrictions hold: @@ -1923,8 +1980,10 @@ def sample_remove_ip_override(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.RemoveIpOverrideResponse: @@ -1984,7 +2043,7 @@ def list_ip_overrides( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListIpOverridesPager: r"""Lists all IP overrides for a key. @@ -2028,8 +2087,10 @@ def sample_list_ip_overrides(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListIpOverridesPager: @@ -2101,7 +2162,7 @@ def get_metrics( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.Metrics: r"""Get some aggregated metrics for a Key. This data can be used to build dashboards. @@ -2145,8 +2206,10 @@ def sample_get_metrics(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.Metrics: @@ -2205,7 +2268,7 @@ def create_firewall_policy( firewall_policy: Optional[recaptchaenterprise.FirewallPolicy] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.FirewallPolicy: r"""Creates a new FirewallPolicy, specifying conditions at which reCAPTCHA Enterprise actions can be executed. A @@ -2258,8 +2321,10 @@ def sample_create_firewall_policy(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.FirewallPolicy: @@ -2322,7 +2387,7 @@ def list_firewall_policies( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListFirewallPoliciesPager: r"""Returns the list of all firewall policies that belong to a project. @@ -2368,8 +2433,10 @@ def sample_list_firewall_policies(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListFirewallPoliciesPager: @@ -2443,7 +2510,7 @@ def get_firewall_policy( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.FirewallPolicy: r"""Returns the specified firewall policy. @@ -2488,8 +2555,10 @@ def sample_get_firewall_policy(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.FirewallPolicy: @@ -2551,7 +2620,7 @@ def update_firewall_policy( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.FirewallPolicy: r"""Updates the specified firewall policy. @@ -2601,8 +2670,10 @@ def sample_update_firewall_policy(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.FirewallPolicy: @@ -2667,7 +2738,7 @@ def delete_firewall_policy( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Deletes the specified firewall policy. @@ -2709,8 +2780,10 @@ def sample_delete_firewall_policy(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ # Create or coerce a protobuf request object. # - Quick check: If we got a request object, we should *not* have @@ -2762,7 +2835,7 @@ def reorder_firewall_policies( names: Optional[MutableSequence[str]] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recaptchaenterprise.ReorderFirewallPoliciesResponse: r"""Reorders all firewall policies. @@ -2815,8 +2888,10 @@ def sample_reorder_firewall_policies(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.types.ReorderFirewallPoliciesResponse: @@ -2880,7 +2955,7 @@ def list_related_account_groups( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListRelatedAccountGroupsPager: r"""List groups of related accounts. @@ -2926,8 +3001,10 @@ def sample_list_related_account_groups(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListRelatedAccountGroupsPager: @@ -3002,7 +3079,7 @@ def list_related_account_group_memberships( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListRelatedAccountGroupMembershipsPager: r"""Get memberships in a group of related accounts. @@ -3048,8 +3125,10 @@ def sample_list_related_account_group_memberships(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListRelatedAccountGroupMembershipsPager: @@ -3130,7 +3209,7 @@ def search_related_account_group_memberships( hashed_account_id: Optional[bytes] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.SearchRelatedAccountGroupMembershipsPager: r"""Search group memberships related to a given account. @@ -3188,8 +3267,10 @@ def sample_search_related_account_group_memberships(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.SearchRelatedAccountGroupMembershipsPager: diff --git a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/pagers.py b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/pagers.py index f50c54e13244..b104fff8c458 100644 --- a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/pagers.py +++ b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -81,8 +81,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recaptchaenterprise.ListKeysRequest(request) @@ -141,7 +143,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -155,8 +157,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recaptchaenterprise.ListKeysRequest(request) @@ -219,7 +223,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -233,8 +237,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recaptchaenterprise.ListIpOverridesRequest(request) @@ -293,7 +299,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -307,8 +313,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recaptchaenterprise.ListIpOverridesRequest(request) @@ -371,7 +379,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -385,8 +393,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recaptchaenterprise.ListFirewallPoliciesRequest(request) @@ -447,7 +457,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -461,8 +471,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recaptchaenterprise.ListFirewallPoliciesRequest(request) @@ -527,7 +539,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -541,8 +553,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recaptchaenterprise.ListRelatedAccountGroupsRequest(request) @@ -603,7 +617,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -617,8 +631,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recaptchaenterprise.ListRelatedAccountGroupsRequest(request) @@ -685,7 +701,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -699,8 +715,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recaptchaenterprise.ListRelatedAccountGroupMembershipsRequest( @@ -766,7 +784,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -780,8 +798,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recaptchaenterprise.ListRelatedAccountGroupMembershipsRequest( @@ -852,7 +872,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -866,8 +886,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recaptchaenterprise.SearchRelatedAccountGroupMembershipsRequest( @@ -933,7 +955,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -947,8 +969,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recaptchaenterprise.SearchRelatedAccountGroupMembershipsRequest( diff --git a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/transports/grpc.py b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/transports/grpc.py index 687afe06080c..89ac2b80f323 100644 --- a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/transports/grpc.py +++ b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -21,12 +24,90 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.protobuf import empty_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.recaptchaenterprise_v1.types import recaptchaenterprise from .base import DEFAULT_CLIENT_INFO, RecaptchaEnterpriseServiceTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class RecaptchaEnterpriseServiceGrpcTransport(RecaptchaEnterpriseServiceTransport): """gRPC backend transport for RecaptchaEnterpriseService. @@ -180,7 +261,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -257,7 +343,7 @@ def create_assessment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_assessment" not in self._stubs: - self._stubs["create_assessment"] = self.grpc_channel.unary_unary( + self._stubs["create_assessment"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/CreateAssessment", request_serializer=recaptchaenterprise.CreateAssessmentRequest.serialize, response_deserializer=recaptchaenterprise.Assessment.deserialize, @@ -288,7 +374,7 @@ def annotate_assessment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "annotate_assessment" not in self._stubs: - self._stubs["annotate_assessment"] = self.grpc_channel.unary_unary( + self._stubs["annotate_assessment"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/AnnotateAssessment", request_serializer=recaptchaenterprise.AnnotateAssessmentRequest.serialize, response_deserializer=recaptchaenterprise.AnnotateAssessmentResponse.deserialize, @@ -314,7 +400,7 @@ def create_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_key" not in self._stubs: - self._stubs["create_key"] = self.grpc_channel.unary_unary( + self._stubs["create_key"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/CreateKey", request_serializer=recaptchaenterprise.CreateKeyRequest.serialize, response_deserializer=recaptchaenterprise.Key.deserialize, @@ -343,7 +429,7 @@ def list_keys( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_keys" not in self._stubs: - self._stubs["list_keys"] = self.grpc_channel.unary_unary( + self._stubs["list_keys"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/ListKeys", request_serializer=recaptchaenterprise.ListKeysRequest.serialize, response_deserializer=recaptchaenterprise.ListKeysResponse.deserialize, @@ -374,7 +460,9 @@ def retrieve_legacy_secret_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "retrieve_legacy_secret_key" not in self._stubs: - self._stubs["retrieve_legacy_secret_key"] = self.grpc_channel.unary_unary( + self._stubs[ + "retrieve_legacy_secret_key" + ] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/RetrieveLegacySecretKey", request_serializer=recaptchaenterprise.RetrieveLegacySecretKeyRequest.serialize, response_deserializer=recaptchaenterprise.RetrieveLegacySecretKeyResponse.deserialize, @@ -400,7 +488,7 @@ def get_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_key" not in self._stubs: - self._stubs["get_key"] = self.grpc_channel.unary_unary( + self._stubs["get_key"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/GetKey", request_serializer=recaptchaenterprise.GetKeyRequest.serialize, response_deserializer=recaptchaenterprise.Key.deserialize, @@ -426,7 +514,7 @@ def update_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_key" not in self._stubs: - self._stubs["update_key"] = self.grpc_channel.unary_unary( + self._stubs["update_key"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/UpdateKey", request_serializer=recaptchaenterprise.UpdateKeyRequest.serialize, response_deserializer=recaptchaenterprise.Key.deserialize, @@ -452,7 +540,7 @@ def delete_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_key" not in self._stubs: - self._stubs["delete_key"] = self.grpc_channel.unary_unary( + self._stubs["delete_key"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/DeleteKey", request_serializer=recaptchaenterprise.DeleteKeyRequest.serialize, response_deserializer=empty_pb2.Empty.FromString, @@ -484,7 +572,7 @@ def migrate_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "migrate_key" not in self._stubs: - self._stubs["migrate_key"] = self.grpc_channel.unary_unary( + self._stubs["migrate_key"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/MigrateKey", request_serializer=recaptchaenterprise.MigrateKeyRequest.serialize, response_deserializer=recaptchaenterprise.Key.deserialize, @@ -517,7 +605,7 @@ def add_ip_override( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "add_ip_override" not in self._stubs: - self._stubs["add_ip_override"] = self.grpc_channel.unary_unary( + self._stubs["add_ip_override"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/AddIpOverride", request_serializer=recaptchaenterprise.AddIpOverrideRequest.serialize, response_deserializer=recaptchaenterprise.AddIpOverrideResponse.deserialize, @@ -553,7 +641,7 @@ def remove_ip_override( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "remove_ip_override" not in self._stubs: - self._stubs["remove_ip_override"] = self.grpc_channel.unary_unary( + self._stubs["remove_ip_override"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/RemoveIpOverride", request_serializer=recaptchaenterprise.RemoveIpOverrideRequest.serialize, response_deserializer=recaptchaenterprise.RemoveIpOverrideResponse.deserialize, @@ -582,7 +670,7 @@ def list_ip_overrides( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_ip_overrides" not in self._stubs: - self._stubs["list_ip_overrides"] = self.grpc_channel.unary_unary( + self._stubs["list_ip_overrides"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/ListIpOverrides", request_serializer=recaptchaenterprise.ListIpOverridesRequest.serialize, response_deserializer=recaptchaenterprise.ListIpOverridesResponse.deserialize, @@ -609,7 +697,7 @@ def get_metrics( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_metrics" not in self._stubs: - self._stubs["get_metrics"] = self.grpc_channel.unary_unary( + self._stubs["get_metrics"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/GetMetrics", request_serializer=recaptchaenterprise.GetMetricsRequest.serialize, response_deserializer=recaptchaenterprise.Metrics.deserialize, @@ -640,7 +728,7 @@ def create_firewall_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_firewall_policy" not in self._stubs: - self._stubs["create_firewall_policy"] = self.grpc_channel.unary_unary( + self._stubs["create_firewall_policy"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/CreateFirewallPolicy", request_serializer=recaptchaenterprise.CreateFirewallPolicyRequest.serialize, response_deserializer=recaptchaenterprise.FirewallPolicy.deserialize, @@ -670,7 +758,7 @@ def list_firewall_policies( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_firewall_policies" not in self._stubs: - self._stubs["list_firewall_policies"] = self.grpc_channel.unary_unary( + self._stubs["list_firewall_policies"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/ListFirewallPolicies", request_serializer=recaptchaenterprise.ListFirewallPoliciesRequest.serialize, response_deserializer=recaptchaenterprise.ListFirewallPoliciesResponse.deserialize, @@ -699,7 +787,7 @@ def get_firewall_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_firewall_policy" not in self._stubs: - self._stubs["get_firewall_policy"] = self.grpc_channel.unary_unary( + self._stubs["get_firewall_policy"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/GetFirewallPolicy", request_serializer=recaptchaenterprise.GetFirewallPolicyRequest.serialize, response_deserializer=recaptchaenterprise.FirewallPolicy.deserialize, @@ -728,7 +816,7 @@ def update_firewall_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_firewall_policy" not in self._stubs: - self._stubs["update_firewall_policy"] = self.grpc_channel.unary_unary( + self._stubs["update_firewall_policy"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/UpdateFirewallPolicy", request_serializer=recaptchaenterprise.UpdateFirewallPolicyRequest.serialize, response_deserializer=recaptchaenterprise.FirewallPolicy.deserialize, @@ -754,7 +842,7 @@ def delete_firewall_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_firewall_policy" not in self._stubs: - self._stubs["delete_firewall_policy"] = self.grpc_channel.unary_unary( + self._stubs["delete_firewall_policy"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/DeleteFirewallPolicy", request_serializer=recaptchaenterprise.DeleteFirewallPolicyRequest.serialize, response_deserializer=empty_pb2.Empty.FromString, @@ -783,7 +871,7 @@ def reorder_firewall_policies( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "reorder_firewall_policies" not in self._stubs: - self._stubs["reorder_firewall_policies"] = self.grpc_channel.unary_unary( + self._stubs["reorder_firewall_policies"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/ReorderFirewallPolicies", request_serializer=recaptchaenterprise.ReorderFirewallPoliciesRequest.serialize, response_deserializer=recaptchaenterprise.ReorderFirewallPoliciesResponse.deserialize, @@ -812,7 +900,9 @@ def list_related_account_groups( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_related_account_groups" not in self._stubs: - self._stubs["list_related_account_groups"] = self.grpc_channel.unary_unary( + self._stubs[ + "list_related_account_groups" + ] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/ListRelatedAccountGroups", request_serializer=recaptchaenterprise.ListRelatedAccountGroupsRequest.serialize, response_deserializer=recaptchaenterprise.ListRelatedAccountGroupsResponse.deserialize, @@ -844,7 +934,7 @@ def list_related_account_group_memberships( if "list_related_account_group_memberships" not in self._stubs: self._stubs[ "list_related_account_group_memberships" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/ListRelatedAccountGroupMemberships", request_serializer=recaptchaenterprise.ListRelatedAccountGroupMembershipsRequest.serialize, response_deserializer=recaptchaenterprise.ListRelatedAccountGroupMembershipsResponse.deserialize, @@ -876,7 +966,7 @@ def search_related_account_group_memberships( if "search_related_account_group_memberships" not in self._stubs: self._stubs[ "search_related_account_group_memberships" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/SearchRelatedAccountGroupMemberships", request_serializer=recaptchaenterprise.SearchRelatedAccountGroupMembershipsRequest.serialize, response_deserializer=recaptchaenterprise.SearchRelatedAccountGroupMembershipsResponse.deserialize, @@ -884,7 +974,7 @@ def search_related_account_group_memberships( return self._stubs["search_related_account_group_memberships"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/transports/grpc_asyncio.py b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/transports/grpc_asyncio.py index d1ca99fffd9b..237641de903c 100644 --- a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -23,14 +26,93 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.protobuf import empty_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.recaptchaenterprise_v1.types import recaptchaenterprise from .base import DEFAULT_CLIENT_INFO, RecaptchaEnterpriseServiceTransport from .grpc import RecaptchaEnterpriseServiceGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class RecaptchaEnterpriseServiceGrpcAsyncIOTransport( RecaptchaEnterpriseServiceTransport @@ -229,10 +311,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -268,7 +353,7 @@ def create_assessment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_assessment" not in self._stubs: - self._stubs["create_assessment"] = self.grpc_channel.unary_unary( + self._stubs["create_assessment"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/CreateAssessment", request_serializer=recaptchaenterprise.CreateAssessmentRequest.serialize, response_deserializer=recaptchaenterprise.Assessment.deserialize, @@ -299,7 +384,7 @@ def annotate_assessment( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "annotate_assessment" not in self._stubs: - self._stubs["annotate_assessment"] = self.grpc_channel.unary_unary( + self._stubs["annotate_assessment"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/AnnotateAssessment", request_serializer=recaptchaenterprise.AnnotateAssessmentRequest.serialize, response_deserializer=recaptchaenterprise.AnnotateAssessmentResponse.deserialize, @@ -327,7 +412,7 @@ def create_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_key" not in self._stubs: - self._stubs["create_key"] = self.grpc_channel.unary_unary( + self._stubs["create_key"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/CreateKey", request_serializer=recaptchaenterprise.CreateKeyRequest.serialize, response_deserializer=recaptchaenterprise.Key.deserialize, @@ -357,7 +442,7 @@ def list_keys( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_keys" not in self._stubs: - self._stubs["list_keys"] = self.grpc_channel.unary_unary( + self._stubs["list_keys"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/ListKeys", request_serializer=recaptchaenterprise.ListKeysRequest.serialize, response_deserializer=recaptchaenterprise.ListKeysResponse.deserialize, @@ -388,7 +473,9 @@ def retrieve_legacy_secret_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "retrieve_legacy_secret_key" not in self._stubs: - self._stubs["retrieve_legacy_secret_key"] = self.grpc_channel.unary_unary( + self._stubs[ + "retrieve_legacy_secret_key" + ] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/RetrieveLegacySecretKey", request_serializer=recaptchaenterprise.RetrieveLegacySecretKeyRequest.serialize, response_deserializer=recaptchaenterprise.RetrieveLegacySecretKeyResponse.deserialize, @@ -416,7 +503,7 @@ def get_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_key" not in self._stubs: - self._stubs["get_key"] = self.grpc_channel.unary_unary( + self._stubs["get_key"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/GetKey", request_serializer=recaptchaenterprise.GetKeyRequest.serialize, response_deserializer=recaptchaenterprise.Key.deserialize, @@ -444,7 +531,7 @@ def update_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_key" not in self._stubs: - self._stubs["update_key"] = self.grpc_channel.unary_unary( + self._stubs["update_key"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/UpdateKey", request_serializer=recaptchaenterprise.UpdateKeyRequest.serialize, response_deserializer=recaptchaenterprise.Key.deserialize, @@ -470,7 +557,7 @@ def delete_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_key" not in self._stubs: - self._stubs["delete_key"] = self.grpc_channel.unary_unary( + self._stubs["delete_key"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/DeleteKey", request_serializer=recaptchaenterprise.DeleteKeyRequest.serialize, response_deserializer=empty_pb2.Empty.FromString, @@ -504,7 +591,7 @@ def migrate_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "migrate_key" not in self._stubs: - self._stubs["migrate_key"] = self.grpc_channel.unary_unary( + self._stubs["migrate_key"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/MigrateKey", request_serializer=recaptchaenterprise.MigrateKeyRequest.serialize, response_deserializer=recaptchaenterprise.Key.deserialize, @@ -537,7 +624,7 @@ def add_ip_override( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "add_ip_override" not in self._stubs: - self._stubs["add_ip_override"] = self.grpc_channel.unary_unary( + self._stubs["add_ip_override"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/AddIpOverride", request_serializer=recaptchaenterprise.AddIpOverrideRequest.serialize, response_deserializer=recaptchaenterprise.AddIpOverrideResponse.deserialize, @@ -573,7 +660,7 @@ def remove_ip_override( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "remove_ip_override" not in self._stubs: - self._stubs["remove_ip_override"] = self.grpc_channel.unary_unary( + self._stubs["remove_ip_override"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/RemoveIpOverride", request_serializer=recaptchaenterprise.RemoveIpOverrideRequest.serialize, response_deserializer=recaptchaenterprise.RemoveIpOverrideResponse.deserialize, @@ -602,7 +689,7 @@ def list_ip_overrides( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_ip_overrides" not in self._stubs: - self._stubs["list_ip_overrides"] = self.grpc_channel.unary_unary( + self._stubs["list_ip_overrides"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/ListIpOverrides", request_serializer=recaptchaenterprise.ListIpOverridesRequest.serialize, response_deserializer=recaptchaenterprise.ListIpOverridesResponse.deserialize, @@ -631,7 +718,7 @@ def get_metrics( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_metrics" not in self._stubs: - self._stubs["get_metrics"] = self.grpc_channel.unary_unary( + self._stubs["get_metrics"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/GetMetrics", request_serializer=recaptchaenterprise.GetMetricsRequest.serialize, response_deserializer=recaptchaenterprise.Metrics.deserialize, @@ -662,7 +749,7 @@ def create_firewall_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_firewall_policy" not in self._stubs: - self._stubs["create_firewall_policy"] = self.grpc_channel.unary_unary( + self._stubs["create_firewall_policy"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/CreateFirewallPolicy", request_serializer=recaptchaenterprise.CreateFirewallPolicyRequest.serialize, response_deserializer=recaptchaenterprise.FirewallPolicy.deserialize, @@ -692,7 +779,7 @@ def list_firewall_policies( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_firewall_policies" not in self._stubs: - self._stubs["list_firewall_policies"] = self.grpc_channel.unary_unary( + self._stubs["list_firewall_policies"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/ListFirewallPolicies", request_serializer=recaptchaenterprise.ListFirewallPoliciesRequest.serialize, response_deserializer=recaptchaenterprise.ListFirewallPoliciesResponse.deserialize, @@ -721,7 +808,7 @@ def get_firewall_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_firewall_policy" not in self._stubs: - self._stubs["get_firewall_policy"] = self.grpc_channel.unary_unary( + self._stubs["get_firewall_policy"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/GetFirewallPolicy", request_serializer=recaptchaenterprise.GetFirewallPolicyRequest.serialize, response_deserializer=recaptchaenterprise.FirewallPolicy.deserialize, @@ -750,7 +837,7 @@ def update_firewall_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_firewall_policy" not in self._stubs: - self._stubs["update_firewall_policy"] = self.grpc_channel.unary_unary( + self._stubs["update_firewall_policy"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/UpdateFirewallPolicy", request_serializer=recaptchaenterprise.UpdateFirewallPolicyRequest.serialize, response_deserializer=recaptchaenterprise.FirewallPolicy.deserialize, @@ -778,7 +865,7 @@ def delete_firewall_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_firewall_policy" not in self._stubs: - self._stubs["delete_firewall_policy"] = self.grpc_channel.unary_unary( + self._stubs["delete_firewall_policy"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/DeleteFirewallPolicy", request_serializer=recaptchaenterprise.DeleteFirewallPolicyRequest.serialize, response_deserializer=empty_pb2.Empty.FromString, @@ -807,7 +894,7 @@ def reorder_firewall_policies( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "reorder_firewall_policies" not in self._stubs: - self._stubs["reorder_firewall_policies"] = self.grpc_channel.unary_unary( + self._stubs["reorder_firewall_policies"] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/ReorderFirewallPolicies", request_serializer=recaptchaenterprise.ReorderFirewallPoliciesRequest.serialize, response_deserializer=recaptchaenterprise.ReorderFirewallPoliciesResponse.deserialize, @@ -836,7 +923,9 @@ def list_related_account_groups( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_related_account_groups" not in self._stubs: - self._stubs["list_related_account_groups"] = self.grpc_channel.unary_unary( + self._stubs[ + "list_related_account_groups" + ] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/ListRelatedAccountGroups", request_serializer=recaptchaenterprise.ListRelatedAccountGroupsRequest.serialize, response_deserializer=recaptchaenterprise.ListRelatedAccountGroupsResponse.deserialize, @@ -868,7 +957,7 @@ def list_related_account_group_memberships( if "list_related_account_group_memberships" not in self._stubs: self._stubs[ "list_related_account_group_memberships" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/ListRelatedAccountGroupMemberships", request_serializer=recaptchaenterprise.ListRelatedAccountGroupMembershipsRequest.serialize, response_deserializer=recaptchaenterprise.ListRelatedAccountGroupMembershipsResponse.deserialize, @@ -900,7 +989,7 @@ def search_related_account_group_memberships( if "search_related_account_group_memberships" not in self._stubs: self._stubs[ "search_related_account_group_memberships" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/SearchRelatedAccountGroupMemberships", request_serializer=recaptchaenterprise.SearchRelatedAccountGroupMembershipsRequest.serialize, response_deserializer=recaptchaenterprise.SearchRelatedAccountGroupMembershipsResponse.deserialize, @@ -1028,7 +1117,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-recaptcha-enterprise/samples/generated_samples/snippet_metadata_google.cloud.recaptchaenterprise.v1.json b/packages/google-cloud-recaptcha-enterprise/samples/generated_samples/snippet_metadata_google.cloud.recaptchaenterprise.v1.json index 0d14f8e6deb6..78c7a5f19cbb 100644 --- a/packages/google-cloud-recaptcha-enterprise/samples/generated_samples/snippet_metadata_google.cloud.recaptchaenterprise.v1.json +++ b/packages/google-cloud-recaptcha-enterprise/samples/generated_samples/snippet_metadata_google.cloud.recaptchaenterprise.v1.json @@ -51,7 +51,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.AddIpOverrideResponse", @@ -135,7 +135,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.AddIpOverrideResponse", @@ -220,7 +220,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.AnnotateAssessmentResponse", @@ -304,7 +304,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.AnnotateAssessmentResponse", @@ -389,7 +389,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.Assessment", @@ -473,7 +473,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.Assessment", @@ -558,7 +558,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.FirewallPolicy", @@ -642,7 +642,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.FirewallPolicy", @@ -727,7 +727,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.Key", @@ -811,7 +811,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.Key", @@ -892,7 +892,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "shortName": "delete_firewall_policy" @@ -969,7 +969,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "shortName": "delete_firewall_policy" @@ -1047,7 +1047,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "shortName": "delete_key" @@ -1124,7 +1124,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "shortName": "delete_key" @@ -1202,7 +1202,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.FirewallPolicy", @@ -1282,7 +1282,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.FirewallPolicy", @@ -1363,7 +1363,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.Key", @@ -1443,7 +1443,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.Key", @@ -1524,7 +1524,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.Metrics", @@ -1604,7 +1604,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.Metrics", @@ -1685,7 +1685,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListFirewallPoliciesAsyncPager", @@ -1765,7 +1765,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListFirewallPoliciesPager", @@ -1846,7 +1846,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListIpOverridesAsyncPager", @@ -1926,7 +1926,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListIpOverridesPager", @@ -2007,7 +2007,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListKeysAsyncPager", @@ -2087,7 +2087,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListKeysPager", @@ -2168,7 +2168,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListRelatedAccountGroupMembershipsAsyncPager", @@ -2248,7 +2248,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListRelatedAccountGroupMembershipsPager", @@ -2329,7 +2329,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListRelatedAccountGroupsAsyncPager", @@ -2409,7 +2409,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListRelatedAccountGroupsPager", @@ -2486,7 +2486,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.Key", @@ -2562,7 +2562,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.Key", @@ -2647,7 +2647,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.RemoveIpOverrideResponse", @@ -2731,7 +2731,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.RemoveIpOverrideResponse", @@ -2816,7 +2816,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.ReorderFirewallPoliciesResponse", @@ -2900,7 +2900,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.ReorderFirewallPoliciesResponse", @@ -2981,7 +2981,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.RetrieveLegacySecretKeyResponse", @@ -3061,7 +3061,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.RetrieveLegacySecretKeyResponse", @@ -3146,7 +3146,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.SearchRelatedAccountGroupMembershipsAsyncPager", @@ -3230,7 +3230,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.SearchRelatedAccountGroupMembershipsPager", @@ -3315,7 +3315,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.FirewallPolicy", @@ -3399,7 +3399,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.FirewallPolicy", @@ -3484,7 +3484,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.Key", @@ -3568,7 +3568,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recaptchaenterprise_v1.types.Key", diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine/gapic_version.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine/gapic_version.py index e9c1f8ae6685..558c8aab67c5 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine/gapic_version.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.10.14" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/gapic_version.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/gapic_version.py index e9c1f8ae6685..558c8aab67c5 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/gapic_version.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.10.14" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/async_client.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/async_client.py index f6b05b6cebb8..fe2f58ad1287 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/async_client.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -58,6 +59,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, CatalogServiceTransport from .transports.grpc_asyncio import CatalogServiceGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class CatalogServiceAsyncClient: """Service for ingesting catalog information of the customer's @@ -269,6 +279,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.recommendationengine_v1beta1.CatalogServiceAsyncClient`.", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.CatalogService", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.recommendationengine.v1beta1.CatalogService", + "credentialsType": None, + }, + ) + async def create_catalog_item( self, request: Optional[Union[catalog_service.CreateCatalogItemRequest, dict]] = None, @@ -277,7 +309,7 @@ async def create_catalog_item( catalog_item: Optional[catalog.CatalogItem] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> catalog.CatalogItem: r"""Creates a catalog item. @@ -332,8 +364,10 @@ async def sample_create_catalog_item(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommendationengine_v1beta1.types.CatalogItem: @@ -396,7 +430,7 @@ async def get_catalog_item( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> catalog.CatalogItem: r"""Gets a specific catalog item. @@ -440,8 +474,10 @@ async def sample_get_catalog_item(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommendationengine_v1beta1.types.CatalogItem: @@ -503,7 +539,7 @@ async def list_catalog_items( filter: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListCatalogItemsAsyncPager: r"""Gets a list of catalog items. @@ -555,8 +591,10 @@ async def sample_list_catalog_items(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommendationengine_v1beta1.services.catalog_service.pagers.ListCatalogItemsAsyncPager: @@ -635,7 +673,7 @@ async def update_catalog_item( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> catalog.CatalogItem: r"""Updates a catalog item. Partial updating is supported. Non-existing items will be created. @@ -701,8 +739,10 @@ async def sample_update_catalog_item(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommendationengine_v1beta1.types.CatalogItem: @@ -767,7 +807,7 @@ async def delete_catalog_item( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Deletes a catalog item. @@ -808,8 +848,10 @@ async def sample_delete_catalog_item(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ # Create or coerce a protobuf request object. # - Quick check: If we got a request object, we should *not* have @@ -864,7 +906,7 @@ async def import_catalog_items( errors_config: Optional[import_.ImportErrorsConfig] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Bulk import of multiple catalog items. Request processing may be synchronous. No partial updating @@ -944,8 +986,10 @@ async def sample_import_catalog_items(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/client.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/client.py index 6421ed94b14c..07a6ee428d57 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/client.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.protobuf import field_mask_pb2 # type: ignore @@ -613,6 +623,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -678,6 +692,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.recommendationengine_v1beta1.CatalogServiceClient`.", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.CatalogService", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.recommendationengine.v1beta1.CatalogService", + "credentialsType": None, + }, + ) + def create_catalog_item( self, request: Optional[Union[catalog_service.CreateCatalogItemRequest, dict]] = None, @@ -686,7 +723,7 @@ def create_catalog_item( catalog_item: Optional[catalog.CatalogItem] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> catalog.CatalogItem: r"""Creates a catalog item. @@ -741,8 +778,10 @@ def sample_create_catalog_item(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommendationengine_v1beta1.types.CatalogItem: @@ -802,7 +841,7 @@ def get_catalog_item( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> catalog.CatalogItem: r"""Gets a specific catalog item. @@ -846,8 +885,10 @@ def sample_get_catalog_item(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommendationengine_v1beta1.types.CatalogItem: @@ -906,7 +947,7 @@ def list_catalog_items( filter: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListCatalogItemsPager: r"""Gets a list of catalog items. @@ -958,8 +999,10 @@ def sample_list_catalog_items(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommendationengine_v1beta1.services.catalog_service.pagers.ListCatalogItemsPager: @@ -1035,7 +1078,7 @@ def update_catalog_item( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> catalog.CatalogItem: r"""Updates a catalog item. Partial updating is supported. Non-existing items will be created. @@ -1101,8 +1144,10 @@ def sample_update_catalog_item(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommendationengine_v1beta1.types.CatalogItem: @@ -1164,7 +1209,7 @@ def delete_catalog_item( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Deletes a catalog item. @@ -1205,8 +1250,10 @@ def sample_delete_catalog_item(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ # Create or coerce a protobuf request object. # - Quick check: If we got a request object, we should *not* have @@ -1258,7 +1305,7 @@ def import_catalog_items( errors_config: Optional[import_.ImportErrorsConfig] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Bulk import of multiple catalog items. Request processing may be synchronous. No partial updating @@ -1338,8 +1385,10 @@ def sample_import_catalog_items(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/pagers.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/pagers.py index a3be7e9af1eb..f90864597491 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/pagers.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -81,8 +81,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = catalog_service.ListCatalogItemsRequest(request) @@ -141,7 +143,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -155,8 +157,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = catalog_service.ListCatalogItemsRequest(request) diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/transports/grpc.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/transports/grpc.py index d4f5db092aad..ce65d5605d34 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/transports/grpc.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -22,7 +25,10 @@ from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.recommendationengine_v1beta1.types import ( catalog, @@ -32,6 +38,81 @@ from .base import DEFAULT_CLIENT_INFO, CatalogServiceTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.CatalogService", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.CatalogService", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class CatalogServiceGrpcTransport(CatalogServiceTransport): """gRPC backend transport for CatalogService. @@ -187,7 +268,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -251,7 +337,9 @@ def operations_client(self) -> operations_v1.OperationsClient: """ # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + self._operations_client = operations_v1.OperationsClient( + self._logged_channel + ) # Return the client from cache. return self._operations_client @@ -275,7 +363,7 @@ def create_catalog_item( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_catalog_item" not in self._stubs: - self._stubs["create_catalog_item"] = self.grpc_channel.unary_unary( + self._stubs["create_catalog_item"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.CatalogService/CreateCatalogItem", request_serializer=catalog_service.CreateCatalogItemRequest.serialize, response_deserializer=catalog.CatalogItem.deserialize, @@ -301,7 +389,7 @@ def get_catalog_item( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_catalog_item" not in self._stubs: - self._stubs["get_catalog_item"] = self.grpc_channel.unary_unary( + self._stubs["get_catalog_item"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.CatalogService/GetCatalogItem", request_serializer=catalog_service.GetCatalogItemRequest.serialize, response_deserializer=catalog.CatalogItem.deserialize, @@ -330,7 +418,7 @@ def list_catalog_items( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_catalog_items" not in self._stubs: - self._stubs["list_catalog_items"] = self.grpc_channel.unary_unary( + self._stubs["list_catalog_items"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.CatalogService/ListCatalogItems", request_serializer=catalog_service.ListCatalogItemsRequest.serialize, response_deserializer=catalog_service.ListCatalogItemsResponse.deserialize, @@ -357,7 +445,7 @@ def update_catalog_item( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_catalog_item" not in self._stubs: - self._stubs["update_catalog_item"] = self.grpc_channel.unary_unary( + self._stubs["update_catalog_item"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.CatalogService/UpdateCatalogItem", request_serializer=catalog_service.UpdateCatalogItemRequest.serialize, response_deserializer=catalog.CatalogItem.deserialize, @@ -383,7 +471,7 @@ def delete_catalog_item( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_catalog_item" not in self._stubs: - self._stubs["delete_catalog_item"] = self.grpc_channel.unary_unary( + self._stubs["delete_catalog_item"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.CatalogService/DeleteCatalogItem", request_serializer=catalog_service.DeleteCatalogItemRequest.serialize, response_deserializer=empty_pb2.Empty.FromString, @@ -415,7 +503,7 @@ def import_catalog_items( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "import_catalog_items" not in self._stubs: - self._stubs["import_catalog_items"] = self.grpc_channel.unary_unary( + self._stubs["import_catalog_items"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.CatalogService/ImportCatalogItems", request_serializer=import_.ImportCatalogItemsRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -423,7 +511,7 @@ def import_catalog_items( return self._stubs["import_catalog_items"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/transports/grpc_asyncio.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/transports/grpc_asyncio.py index 851088c51b64..0bc9444ebe83 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -24,8 +27,11 @@ from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.recommendationengine_v1beta1.types import ( catalog, @@ -36,6 +42,82 @@ from .base import DEFAULT_CLIENT_INFO, CatalogServiceTransport from .grpc import CatalogServiceGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.CatalogService", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.CatalogService", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class CatalogServiceGrpcAsyncIOTransport(CatalogServiceTransport): """gRPC AsyncIO backend transport for CatalogService. @@ -234,10 +316,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -260,7 +345,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel + self._logged_channel ) # Return the client from cache. @@ -287,7 +372,7 @@ def create_catalog_item( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_catalog_item" not in self._stubs: - self._stubs["create_catalog_item"] = self.grpc_channel.unary_unary( + self._stubs["create_catalog_item"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.CatalogService/CreateCatalogItem", request_serializer=catalog_service.CreateCatalogItemRequest.serialize, response_deserializer=catalog.CatalogItem.deserialize, @@ -315,7 +400,7 @@ def get_catalog_item( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_catalog_item" not in self._stubs: - self._stubs["get_catalog_item"] = self.grpc_channel.unary_unary( + self._stubs["get_catalog_item"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.CatalogService/GetCatalogItem", request_serializer=catalog_service.GetCatalogItemRequest.serialize, response_deserializer=catalog.CatalogItem.deserialize, @@ -344,7 +429,7 @@ def list_catalog_items( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_catalog_items" not in self._stubs: - self._stubs["list_catalog_items"] = self.grpc_channel.unary_unary( + self._stubs["list_catalog_items"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.CatalogService/ListCatalogItems", request_serializer=catalog_service.ListCatalogItemsRequest.serialize, response_deserializer=catalog_service.ListCatalogItemsResponse.deserialize, @@ -373,7 +458,7 @@ def update_catalog_item( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_catalog_item" not in self._stubs: - self._stubs["update_catalog_item"] = self.grpc_channel.unary_unary( + self._stubs["update_catalog_item"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.CatalogService/UpdateCatalogItem", request_serializer=catalog_service.UpdateCatalogItemRequest.serialize, response_deserializer=catalog.CatalogItem.deserialize, @@ -401,7 +486,7 @@ def delete_catalog_item( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_catalog_item" not in self._stubs: - self._stubs["delete_catalog_item"] = self.grpc_channel.unary_unary( + self._stubs["delete_catalog_item"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.CatalogService/DeleteCatalogItem", request_serializer=catalog_service.DeleteCatalogItemRequest.serialize, response_deserializer=empty_pb2.Empty.FromString, @@ -435,7 +520,7 @@ def import_catalog_items( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "import_catalog_items" not in self._stubs: - self._stubs["import_catalog_items"] = self.grpc_channel.unary_unary( + self._stubs["import_catalog_items"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.CatalogService/ImportCatalogItems", request_serializer=import_.ImportCatalogItemsRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -543,7 +628,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/transports/rest.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/transports/rest.py index 4378227f9804..9acbdce0a671 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/transports/rest.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/catalog_service/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -43,6 +43,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -119,8 +127,11 @@ def post_update_catalog_item(self, response): def pre_create_catalog_item( self, request: catalog_service.CreateCatalogItemRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[catalog_service.CreateCatalogItemRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + catalog_service.CreateCatalogItemRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for create_catalog_item Override in a subclass to manipulate the request or metadata @@ -142,8 +153,11 @@ def post_create_catalog_item( def pre_delete_catalog_item( self, request: catalog_service.DeleteCatalogItemRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[catalog_service.DeleteCatalogItemRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + catalog_service.DeleteCatalogItemRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for delete_catalog_item Override in a subclass to manipulate the request or metadata @@ -154,8 +168,10 @@ def pre_delete_catalog_item( def pre_get_catalog_item( self, request: catalog_service.GetCatalogItemRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[catalog_service.GetCatalogItemRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + catalog_service.GetCatalogItemRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_catalog_item Override in a subclass to manipulate the request or metadata @@ -177,8 +193,10 @@ def post_get_catalog_item( def pre_import_catalog_items( self, request: import_.ImportCatalogItemsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[import_.ImportCatalogItemsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + import_.ImportCatalogItemsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for import_catalog_items Override in a subclass to manipulate the request or metadata @@ -200,8 +218,10 @@ def post_import_catalog_items( def pre_list_catalog_items( self, request: catalog_service.ListCatalogItemsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[catalog_service.ListCatalogItemsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + catalog_service.ListCatalogItemsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_catalog_items Override in a subclass to manipulate the request or metadata @@ -223,8 +243,11 @@ def post_list_catalog_items( def pre_update_catalog_item( self, request: catalog_service.UpdateCatalogItemRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[catalog_service.UpdateCatalogItemRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + catalog_service.UpdateCatalogItemRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for update_catalog_item Override in a subclass to manipulate the request or metadata @@ -415,7 +438,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> catalog.CatalogItem: r"""Call the create catalog item method over HTTP. @@ -426,8 +449,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.catalog.CatalogItem: @@ -439,6 +464,7 @@ def __call__( http_options = ( _BaseCatalogServiceRestTransport._BaseCreateCatalogItem._get_http_options() ) + request, metadata = self._interceptor.pre_create_catalog_item( request, metadata ) @@ -455,6 +481,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommendationengine_v1beta1.CatalogServiceClient.CreateCatalogItem", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.CatalogService", + "rpcName": "CreateCatalogItem", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CatalogServiceRestTransport._CreateCatalogItem._get_response( self._host, @@ -476,7 +529,29 @@ def __call__( pb_resp = catalog.CatalogItem.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_catalog_item(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = catalog.CatalogItem.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommendationengine_v1beta1.CatalogServiceClient.create_catalog_item", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.CatalogService", + "rpcName": "CreateCatalogItem", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DeleteCatalogItem( @@ -513,7 +588,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): r"""Call the delete catalog item method over HTTP. @@ -524,13 +599,16 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ http_options = ( _BaseCatalogServiceRestTransport._BaseDeleteCatalogItem._get_http_options() ) + request, metadata = self._interceptor.pre_delete_catalog_item( request, metadata ) @@ -543,6 +621,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommendationengine_v1beta1.CatalogServiceClient.DeleteCatalogItem", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.CatalogService", + "rpcName": "DeleteCatalogItem", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CatalogServiceRestTransport._DeleteCatalogItem._get_response( self._host, @@ -592,7 +697,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> catalog.CatalogItem: r"""Call the get catalog item method over HTTP. @@ -603,8 +708,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.catalog.CatalogItem: @@ -616,6 +723,7 @@ def __call__( http_options = ( _BaseCatalogServiceRestTransport._BaseGetCatalogItem._get_http_options() ) + request, metadata = self._interceptor.pre_get_catalog_item( request, metadata ) @@ -628,6 +736,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommendationengine_v1beta1.CatalogServiceClient.GetCatalogItem", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.CatalogService", + "rpcName": "GetCatalogItem", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CatalogServiceRestTransport._GetCatalogItem._get_response( self._host, @@ -648,7 +783,29 @@ def __call__( pb_resp = catalog.CatalogItem.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_catalog_item(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = catalog.CatalogItem.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommendationengine_v1beta1.CatalogServiceClient.get_catalog_item", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.CatalogService", + "rpcName": "GetCatalogItem", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ImportCatalogItems( @@ -686,7 +843,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the import catalog items method over HTTP. @@ -696,8 +853,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -710,6 +869,7 @@ def __call__( http_options = ( _BaseCatalogServiceRestTransport._BaseImportCatalogItems._get_http_options() ) + request, metadata = self._interceptor.pre_import_catalog_items( request, metadata ) @@ -726,6 +886,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommendationengine_v1beta1.CatalogServiceClient.ImportCatalogItems", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.CatalogService", + "rpcName": "ImportCatalogItems", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CatalogServiceRestTransport._ImportCatalogItems._get_response( self._host, @@ -745,7 +932,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_import_catalog_items(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommendationengine_v1beta1.CatalogServiceClient.import_catalog_items", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.CatalogService", + "rpcName": "ImportCatalogItems", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListCatalogItems( @@ -782,7 +991,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> catalog_service.ListCatalogItemsResponse: r"""Call the list catalog items method over HTTP. @@ -793,8 +1002,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.catalog_service.ListCatalogItemsResponse: @@ -806,6 +1017,7 @@ def __call__( http_options = ( _BaseCatalogServiceRestTransport._BaseListCatalogItems._get_http_options() ) + request, metadata = self._interceptor.pre_list_catalog_items( request, metadata ) @@ -818,6 +1030,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommendationengine_v1beta1.CatalogServiceClient.ListCatalogItems", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.CatalogService", + "rpcName": "ListCatalogItems", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CatalogServiceRestTransport._ListCatalogItems._get_response( self._host, @@ -838,7 +1077,31 @@ def __call__( pb_resp = catalog_service.ListCatalogItemsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_catalog_items(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = catalog_service.ListCatalogItemsResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommendationengine_v1beta1.CatalogServiceClient.list_catalog_items", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.CatalogService", + "rpcName": "ListCatalogItems", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateCatalogItem( @@ -876,7 +1139,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> catalog.CatalogItem: r"""Call the update catalog item method over HTTP. @@ -887,8 +1150,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.catalog.CatalogItem: @@ -900,6 +1165,7 @@ def __call__( http_options = ( _BaseCatalogServiceRestTransport._BaseUpdateCatalogItem._get_http_options() ) + request, metadata = self._interceptor.pre_update_catalog_item( request, metadata ) @@ -916,6 +1182,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommendationengine_v1beta1.CatalogServiceClient.UpdateCatalogItem", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.CatalogService", + "rpcName": "UpdateCatalogItem", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CatalogServiceRestTransport._UpdateCatalogItem._get_response( self._host, @@ -937,7 +1230,29 @@ def __call__( pb_resp = catalog.CatalogItem.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_catalog_item(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = catalog.CatalogItem.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommendationengine_v1beta1.CatalogServiceClient.update_catalog_item", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.CatalogService", + "rpcName": "UpdateCatalogItem", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/async_client.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/async_client.py index b8da065eece4..b5e1f694483c 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/async_client.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -53,6 +54,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, PredictionApiKeyRegistryTransport from .transports.grpc_asyncio import PredictionApiKeyRegistryGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class PredictionApiKeyRegistryAsyncClient: """Service for registering API keys for use with the ``predict`` @@ -282,6 +292,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.recommendationengine_v1beta1.PredictionApiKeyRegistryAsyncClient`.", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry", + "credentialsType": None, + }, + ) + async def create_prediction_api_key_registration( self, request: Optional[ @@ -297,7 +329,7 @@ async def create_prediction_api_key_registration( ] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> prediction_apikey_registry_service.PredictionApiKeyRegistration: r"""Register an API key for use with predict method. @@ -348,8 +380,10 @@ async def sample_create_prediction_api_key_registration(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommendationengine_v1beta1.types.PredictionApiKeyRegistration: @@ -420,7 +454,7 @@ async def list_prediction_api_key_registrations( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListPredictionApiKeyRegistrationsAsyncPager: r"""List the registered apiKeys for use with predict method. @@ -466,8 +500,10 @@ async def sample_list_prediction_api_key_registrations(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommendationengine_v1beta1.services.prediction_api_key_registry.pagers.ListPredictionApiKeyRegistrationsAsyncPager: @@ -552,7 +588,7 @@ async def delete_prediction_api_key_registration( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Unregister an apiKey from using for predict method. @@ -594,8 +630,10 @@ async def sample_delete_prediction_api_key_registration(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ # Create or coerce a protobuf request object. # - Quick check: If we got a request object, we should *not* have diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/client.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/client.py index 0042b9bbdfba..036d80331e7d 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/client.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.cloud.recommendationengine_v1beta1.services.prediction_api_key_registry import ( pagers, ) @@ -624,6 +634,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -690,6 +704,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.recommendationengine_v1beta1.PredictionApiKeyRegistryClient`.", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry", + "credentialsType": None, + }, + ) + def create_prediction_api_key_registration( self, request: Optional[ @@ -705,7 +742,7 @@ def create_prediction_api_key_registration( ] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> prediction_apikey_registry_service.PredictionApiKeyRegistration: r"""Register an API key for use with predict method. @@ -756,8 +793,10 @@ def sample_create_prediction_api_key_registration(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommendationengine_v1beta1.types.PredictionApiKeyRegistration: @@ -829,7 +868,7 @@ def list_prediction_api_key_registrations( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListPredictionApiKeyRegistrationsPager: r"""List the registered apiKeys for use with predict method. @@ -875,8 +914,10 @@ def sample_list_prediction_api_key_registrations(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommendationengine_v1beta1.services.prediction_api_key_registry.pagers.ListPredictionApiKeyRegistrationsPager: @@ -960,7 +1001,7 @@ def delete_prediction_api_key_registration( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Unregister an apiKey from using for predict method. @@ -1002,8 +1043,10 @@ def sample_delete_prediction_api_key_registration(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ # Create or coerce a protobuf request object. # - Quick check: If we got a request object, we should *not* have diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/pagers.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/pagers.py index 5d99b48c5633..b58bd3229c09 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/pagers.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/pagers.py @@ -72,7 +72,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -86,8 +86,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = ( @@ -161,7 +163,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -175,8 +177,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = ( diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/transports/grpc.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/transports/grpc.py index a122ae8c72e0..e29895a2a2c1 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/transports/grpc.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -21,7 +24,10 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.protobuf import empty_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.recommendationengine_v1beta1.types import ( prediction_apikey_registry_service, @@ -29,6 +35,81 @@ from .base import DEFAULT_CLIENT_INFO, PredictionApiKeyRegistryTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class PredictionApiKeyRegistryGrpcTransport(PredictionApiKeyRegistryTransport): """gRPC backend transport for PredictionApiKeyRegistry. @@ -187,7 +268,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -267,7 +353,7 @@ def create_prediction_api_key_registration( if "create_prediction_api_key_registration" not in self._stubs: self._stubs[ "create_prediction_api_key_registration" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry/CreatePredictionApiKeyRegistration", request_serializer=prediction_apikey_registry_service.CreatePredictionApiKeyRegistrationRequest.serialize, response_deserializer=prediction_apikey_registry_service.PredictionApiKeyRegistration.deserialize, @@ -300,7 +386,7 @@ def list_prediction_api_key_registrations( if "list_prediction_api_key_registrations" not in self._stubs: self._stubs[ "list_prediction_api_key_registrations" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry/ListPredictionApiKeyRegistrations", request_serializer=prediction_apikey_registry_service.ListPredictionApiKeyRegistrationsRequest.serialize, response_deserializer=prediction_apikey_registry_service.ListPredictionApiKeyRegistrationsResponse.deserialize, @@ -332,7 +418,7 @@ def delete_prediction_api_key_registration( if "delete_prediction_api_key_registration" not in self._stubs: self._stubs[ "delete_prediction_api_key_registration" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry/DeletePredictionApiKeyRegistration", request_serializer=prediction_apikey_registry_service.DeletePredictionApiKeyRegistrationRequest.serialize, response_deserializer=empty_pb2.Empty.FromString, @@ -340,7 +426,7 @@ def delete_prediction_api_key_registration( return self._stubs["delete_prediction_api_key_registration"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/transports/grpc_asyncio.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/transports/grpc_asyncio.py index d1c124c847f3..fc87754ef147 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/transports/grpc_asyncio.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -23,8 +26,11 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.protobuf import empty_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.recommendationengine_v1beta1.types import ( prediction_apikey_registry_service, @@ -33,6 +39,82 @@ from .base import DEFAULT_CLIENT_INFO, PredictionApiKeyRegistryTransport from .grpc import PredictionApiKeyRegistryGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class PredictionApiKeyRegistryGrpcAsyncIOTransport(PredictionApiKeyRegistryTransport): """gRPC AsyncIO backend transport for PredictionApiKeyRegistry. @@ -234,10 +316,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -275,7 +360,7 @@ def create_prediction_api_key_registration( if "create_prediction_api_key_registration" not in self._stubs: self._stubs[ "create_prediction_api_key_registration" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry/CreatePredictionApiKeyRegistration", request_serializer=prediction_apikey_registry_service.CreatePredictionApiKeyRegistrationRequest.serialize, response_deserializer=prediction_apikey_registry_service.PredictionApiKeyRegistration.deserialize, @@ -310,7 +395,7 @@ def list_prediction_api_key_registrations( if "list_prediction_api_key_registrations" not in self._stubs: self._stubs[ "list_prediction_api_key_registrations" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry/ListPredictionApiKeyRegistrations", request_serializer=prediction_apikey_registry_service.ListPredictionApiKeyRegistrationsRequest.serialize, response_deserializer=prediction_apikey_registry_service.ListPredictionApiKeyRegistrationsResponse.deserialize, @@ -342,7 +427,7 @@ def delete_prediction_api_key_registration( if "delete_prediction_api_key_registration" not in self._stubs: self._stubs[ "delete_prediction_api_key_registration" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry/DeletePredictionApiKeyRegistration", request_serializer=prediction_apikey_registry_service.DeletePredictionApiKeyRegistrationRequest.serialize, response_deserializer=empty_pb2.Empty.FromString, @@ -405,7 +490,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/transports/rest.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/transports/rest.py index bc9c34970b52..2258b1f82b3a 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/transports/rest.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -40,6 +40,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -92,10 +100,10 @@ def post_list_prediction_api_key_registrations(self, response): def pre_create_prediction_api_key_registration( self, request: prediction_apikey_registry_service.CreatePredictionApiKeyRegistrationRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ prediction_apikey_registry_service.CreatePredictionApiKeyRegistrationRequest, - Sequence[Tuple[str, str]], + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for create_prediction_api_key_registration @@ -118,10 +126,10 @@ def post_create_prediction_api_key_registration( def pre_delete_prediction_api_key_registration( self, request: prediction_apikey_registry_service.DeletePredictionApiKeyRegistrationRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ prediction_apikey_registry_service.DeletePredictionApiKeyRegistrationRequest, - Sequence[Tuple[str, str]], + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for delete_prediction_api_key_registration @@ -133,10 +141,10 @@ def pre_delete_prediction_api_key_registration( def pre_list_prediction_api_key_registrations( self, request: prediction_apikey_registry_service.ListPredictionApiKeyRegistrationsRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ prediction_apikey_registry_service.ListPredictionApiKeyRegistrationsRequest, - Sequence[Tuple[str, str]], + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for list_prediction_api_key_registrations @@ -287,7 +295,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> prediction_apikey_registry_service.PredictionApiKeyRegistration: r"""Call the create prediction api key registration method over HTTP. @@ -299,8 +307,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.prediction_apikey_registry_service.PredictionApiKeyRegistration: @@ -310,6 +320,7 @@ def __call__( http_options = ( _BasePredictionApiKeyRegistryRestTransport._BaseCreatePredictionApiKeyRegistration._get_http_options() ) + ( request, metadata, @@ -329,6 +340,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommendationengine_v1beta1.PredictionApiKeyRegistryClient.CreatePredictionApiKeyRegistration", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry", + "rpcName": "CreatePredictionApiKeyRegistration", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = PredictionApiKeyRegistryRestTransport._CreatePredictionApiKeyRegistration._get_response( self._host, @@ -352,7 +390,31 @@ def __call__( ) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_prediction_api_key_registration(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = prediction_apikey_registry_service.PredictionApiKeyRegistration.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommendationengine_v1beta1.PredictionApiKeyRegistryClient.create_prediction_api_key_registration", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry", + "rpcName": "CreatePredictionApiKeyRegistration", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DeletePredictionApiKeyRegistration( @@ -392,7 +454,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): r"""Call the delete prediction api key registration method over HTTP. @@ -404,13 +466,16 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ http_options = ( _BasePredictionApiKeyRegistryRestTransport._BaseDeletePredictionApiKeyRegistration._get_http_options() ) + ( request, metadata, @@ -426,6 +491,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommendationengine_v1beta1.PredictionApiKeyRegistryClient.DeletePredictionApiKeyRegistration", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry", + "rpcName": "DeletePredictionApiKeyRegistration", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = PredictionApiKeyRegistryRestTransport._DeletePredictionApiKeyRegistration._get_response( self._host, @@ -478,7 +570,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> ( prediction_apikey_registry_service.ListPredictionApiKeyRegistrationsResponse ): @@ -492,8 +584,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.prediction_apikey_registry_service.ListPredictionApiKeyRegistrationsResponse: @@ -505,6 +599,7 @@ def __call__( http_options = ( _BasePredictionApiKeyRegistryRestTransport._BaseListPredictionApiKeyRegistrations._get_http_options() ) + ( request, metadata, @@ -520,6 +615,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommendationengine_v1beta1.PredictionApiKeyRegistryClient.ListPredictionApiKeyRegistrations", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry", + "rpcName": "ListPredictionApiKeyRegistrations", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = PredictionApiKeyRegistryRestTransport._ListPredictionApiKeyRegistrations._get_response( self._host, @@ -544,7 +666,31 @@ def __call__( ) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_prediction_api_key_registrations(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = prediction_apikey_registry_service.ListPredictionApiKeyRegistrationsResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommendationengine_v1beta1.PredictionApiKeyRegistryClient.list_prediction_api_key_registrations", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry", + "rpcName": "ListPredictionApiKeyRegistrations", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/async_client.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/async_client.py index 3c0ea1a7de50..5324a0f324df 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/async_client.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -50,6 +51,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, PredictionServiceTransport from .transports.grpc_asyncio import PredictionServiceGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class PredictionServiceAsyncClient: """Service for making recommendation prediction.""" @@ -259,6 +269,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.recommendationengine_v1beta1.PredictionServiceAsyncClient`.", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionService", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionService", + "credentialsType": None, + }, + ) + async def predict( self, request: Optional[Union[prediction_service.PredictRequest, dict]] = None, @@ -267,7 +299,7 @@ async def predict( user_event: Optional[gcr_user_event.UserEvent] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.PredictAsyncPager: r"""Makes a recommendation prediction. If using API Key based authentication, the API Key must be registered using the @@ -367,8 +399,10 @@ async def sample_predict(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommendationengine_v1beta1.services.prediction_service.pagers.PredictAsyncPager: diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/client.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/client.py index 09195e8b3adf..3156b065fbe6 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/client.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.cloud.recommendationengine_v1beta1.services.prediction_service import pagers from google.cloud.recommendationengine_v1beta1.types import user_event as gcr_user_event from google.cloud.recommendationengine_v1beta1.types import prediction_service @@ -587,6 +597,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -653,6 +667,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.recommendationengine_v1beta1.PredictionServiceClient`.", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionService", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionService", + "credentialsType": None, + }, + ) + def predict( self, request: Optional[Union[prediction_service.PredictRequest, dict]] = None, @@ -661,7 +698,7 @@ def predict( user_event: Optional[gcr_user_event.UserEvent] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.PredictPager: r"""Makes a recommendation prediction. If using API Key based authentication, the API Key must be registered using the @@ -761,8 +798,10 @@ def sample_predict(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommendationengine_v1beta1.services.prediction_service.pagers.PredictPager: diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/pagers.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/pagers.py index 02faf4a3e2ba..cc69a48ec5f8 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/pagers.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -81,8 +81,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = prediction_service.PredictRequest(request) @@ -141,7 +143,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -155,8 +157,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = prediction_service.PredictRequest(request) diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/transports/grpc.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/transports/grpc.py index 47c3244ef842..2b03a7d2353d 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/transports/grpc.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -20,12 +23,90 @@ import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.recommendationengine_v1beta1.types import prediction_service from .base import DEFAULT_CLIENT_INFO, PredictionServiceTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionService", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionService", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class PredictionServiceGrpcTransport(PredictionServiceTransport): """gRPC backend transport for PredictionService. @@ -179,7 +260,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -259,7 +345,7 @@ def predict( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "predict" not in self._stubs: - self._stubs["predict"] = self.grpc_channel.unary_unary( + self._stubs["predict"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.PredictionService/Predict", request_serializer=prediction_service.PredictRequest.serialize, response_deserializer=prediction_service.PredictResponse.deserialize, @@ -267,7 +353,7 @@ def predict( return self._stubs["predict"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/transports/grpc_asyncio.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/transports/grpc_asyncio.py index cf292e2009f3..0a766dff6572 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -22,14 +25,93 @@ from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.recommendationengine_v1beta1.types import prediction_service from .base import DEFAULT_CLIENT_INFO, PredictionServiceTransport from .grpc import PredictionServiceGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionService", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionService", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class PredictionServiceGrpcAsyncIOTransport(PredictionServiceTransport): """gRPC AsyncIO backend transport for PredictionService. @@ -226,10 +308,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -268,7 +353,7 @@ def predict( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "predict" not in self._stubs: - self._stubs["predict"] = self.grpc_channel.unary_unary( + self._stubs["predict"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.PredictionService/Predict", request_serializer=prediction_service.PredictRequest.serialize, response_deserializer=prediction_service.PredictResponse.deserialize, @@ -301,7 +386,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/transports/rest.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/transports/rest.py index c558589bb0e1..bd23c1b1b54c 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/transports/rest.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/prediction_service/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -37,6 +37,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -77,8 +85,10 @@ def post_predict(self, response): def pre_predict( self, request: prediction_service.PredictRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[prediction_service.PredictRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + prediction_service.PredictRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for predict Override in a subclass to manipulate the request or metadata @@ -219,7 +229,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> prediction_service.PredictResponse: r"""Call the predict method over HTTP. @@ -229,8 +239,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.prediction_service.PredictResponse: @@ -240,6 +252,7 @@ def __call__( http_options = ( _BasePredictionServiceRestTransport._BasePredict._get_http_options() ) + request, metadata = self._interceptor.pre_predict(request, metadata) transcoded_request = _BasePredictionServiceRestTransport._BasePredict._get_transcoded_request( http_options, request @@ -258,6 +271,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommendationengine_v1beta1.PredictionServiceClient.Predict", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionService", + "rpcName": "Predict", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = PredictionServiceRestTransport._Predict._get_response( self._host, @@ -279,7 +319,31 @@ def __call__( pb_resp = prediction_service.PredictResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_predict(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = prediction_service.PredictResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommendationengine_v1beta1.PredictionServiceClient.predict", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.PredictionService", + "rpcName": "Predict", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/async_client.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/async_client.py index c618593aaac8..bdd58ca28207 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/async_client.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -58,6 +59,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, UserEventServiceTransport from .transports.grpc_asyncio import UserEventServiceGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class UserEventServiceAsyncClient: """Service for ingesting end user actions on the customer @@ -267,6 +277,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.recommendationengine_v1beta1.UserEventServiceAsyncClient`.", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.UserEventService", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.recommendationengine.v1beta1.UserEventService", + "credentialsType": None, + }, + ) + async def write_user_event( self, request: Optional[Union[user_event_service.WriteUserEventRequest, dict]] = None, @@ -275,7 +307,7 @@ async def write_user_event( user_event: Optional[gcr_user_event.UserEvent] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> gcr_user_event.UserEvent: r"""Writes a single user event. @@ -329,8 +361,10 @@ async def sample_write_user_event(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommendationengine_v1beta1.types.UserEvent: @@ -400,7 +434,7 @@ async def collect_user_event( ets: Optional[int] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> httpbody_pb2.HttpBody: r"""Writes a single user event from the browser. This uses a GET request to due to browser restriction of @@ -481,8 +515,10 @@ async def sample_collect_user_event(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api.httpbody_pb2.HttpBody: @@ -594,7 +630,7 @@ async def list_user_events( filter: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListUserEventsAsyncPager: r"""Gets a list of user events within a time range, with potential filtering. @@ -681,8 +717,10 @@ async def sample_list_user_events(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommendationengine_v1beta1.services.user_event_service.pagers.ListUserEventsAsyncPager: @@ -763,7 +801,7 @@ async def purge_user_events( force: Optional[bool] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Deletes permanently all user events specified by the filter provided. Depending on the number of events @@ -851,8 +889,10 @@ async def sample_purge_user_events(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -931,7 +971,7 @@ async def import_user_events( errors_config: Optional[import_.ImportErrorsConfig] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Bulk import of User events. Request processing might be synchronous. Events that already exist are skipped. @@ -1012,8 +1052,10 @@ async def sample_import_user_events(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/client.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/client.py index 9c1bc8193293..3b8ec2844e8d 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/client.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api import httpbody_pb2 # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -593,6 +603,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -659,6 +673,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.recommendationengine_v1beta1.UserEventServiceClient`.", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.UserEventService", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.recommendationengine.v1beta1.UserEventService", + "credentialsType": None, + }, + ) + def write_user_event( self, request: Optional[Union[user_event_service.WriteUserEventRequest, dict]] = None, @@ -667,7 +704,7 @@ def write_user_event( user_event: Optional[gcr_user_event.UserEvent] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> gcr_user_event.UserEvent: r"""Writes a single user event. @@ -721,8 +758,10 @@ def sample_write_user_event(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommendationengine_v1beta1.types.UserEvent: @@ -789,7 +828,7 @@ def collect_user_event( ets: Optional[int] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> httpbody_pb2.HttpBody: r"""Writes a single user event from the browser. This uses a GET request to due to browser restriction of @@ -870,8 +909,10 @@ def sample_collect_user_event(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api.httpbody_pb2.HttpBody: @@ -980,7 +1021,7 @@ def list_user_events( filter: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListUserEventsPager: r"""Gets a list of user events within a time range, with potential filtering. @@ -1067,8 +1108,10 @@ def sample_list_user_events(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommendationengine_v1beta1.services.user_event_service.pagers.ListUserEventsPager: @@ -1146,7 +1189,7 @@ def purge_user_events( force: Optional[bool] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Deletes permanently all user events specified by the filter provided. Depending on the number of events @@ -1234,8 +1277,10 @@ def sample_purge_user_events(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1311,7 +1356,7 @@ def import_user_events( errors_config: Optional[import_.ImportErrorsConfig] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Bulk import of User events. Request processing might be synchronous. Events that already exist are skipped. @@ -1392,8 +1437,10 @@ def sample_import_user_events(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/pagers.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/pagers.py index ece5e17a1a5f..0f29ea52e5f9 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/pagers.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/pagers.py @@ -70,7 +70,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -84,8 +84,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = user_event_service.ListUserEventsRequest(request) @@ -144,7 +146,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -158,8 +160,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = user_event_service.ListUserEventsRequest(request) diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/transports/grpc.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/transports/grpc.py index bfe5cfd85a3c..d7255532ef36 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/transports/grpc.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -22,7 +25,10 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.recommendationengine_v1beta1.types import user_event as gcr_user_event from google.cloud.recommendationengine_v1beta1.types import import_ @@ -30,6 +36,81 @@ from .base import DEFAULT_CLIENT_INFO, UserEventServiceTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.UserEventService", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.UserEventService", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class UserEventServiceGrpcTransport(UserEventServiceTransport): """gRPC backend transport for UserEventService. @@ -185,7 +266,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -249,7 +335,9 @@ def operations_client(self) -> operations_v1.OperationsClient: """ # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + self._operations_client = operations_v1.OperationsClient( + self._logged_channel + ) # Return the client from cache. return self._operations_client @@ -273,7 +361,7 @@ def write_user_event( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "write_user_event" not in self._stubs: - self._stubs["write_user_event"] = self.grpc_channel.unary_unary( + self._stubs["write_user_event"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.UserEventService/WriteUserEvent", request_serializer=user_event_service.WriteUserEventRequest.serialize, response_deserializer=gcr_user_event.UserEvent.deserialize, @@ -305,7 +393,7 @@ def collect_user_event( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "collect_user_event" not in self._stubs: - self._stubs["collect_user_event"] = self.grpc_channel.unary_unary( + self._stubs["collect_user_event"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.UserEventService/CollectUserEvent", request_serializer=user_event_service.CollectUserEventRequest.serialize, response_deserializer=httpbody_pb2.HttpBody.FromString, @@ -335,7 +423,7 @@ def list_user_events( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_user_events" not in self._stubs: - self._stubs["list_user_events"] = self.grpc_channel.unary_unary( + self._stubs["list_user_events"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.UserEventService/ListUserEvents", request_serializer=user_event_service.ListUserEventsRequest.serialize, response_deserializer=user_event_service.ListUserEventsResponse.deserialize, @@ -367,7 +455,7 @@ def purge_user_events( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "purge_user_events" not in self._stubs: - self._stubs["purge_user_events"] = self.grpc_channel.unary_unary( + self._stubs["purge_user_events"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.UserEventService/PurgeUserEvents", request_serializer=user_event_service.PurgeUserEventsRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -400,7 +488,7 @@ def import_user_events( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "import_user_events" not in self._stubs: - self._stubs["import_user_events"] = self.grpc_channel.unary_unary( + self._stubs["import_user_events"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.UserEventService/ImportUserEvents", request_serializer=import_.ImportUserEventsRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -408,7 +496,7 @@ def import_user_events( return self._stubs["import_user_events"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/transports/grpc_asyncio.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/transports/grpc_asyncio.py index c0277db65ecd..83b3d2a9b004 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -24,8 +27,11 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.recommendationengine_v1beta1.types import user_event as gcr_user_event from google.cloud.recommendationengine_v1beta1.types import import_ @@ -34,6 +40,82 @@ from .base import DEFAULT_CLIENT_INFO, UserEventServiceTransport from .grpc import UserEventServiceGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.UserEventService", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.UserEventService", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class UserEventServiceGrpcAsyncIOTransport(UserEventServiceTransport): """gRPC AsyncIO backend transport for UserEventService. @@ -232,10 +314,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -258,7 +343,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel + self._logged_channel ) # Return the client from cache. @@ -285,7 +370,7 @@ def write_user_event( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "write_user_event" not in self._stubs: - self._stubs["write_user_event"] = self.grpc_channel.unary_unary( + self._stubs["write_user_event"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.UserEventService/WriteUserEvent", request_serializer=user_event_service.WriteUserEventRequest.serialize, response_deserializer=gcr_user_event.UserEvent.deserialize, @@ -319,7 +404,7 @@ def collect_user_event( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "collect_user_event" not in self._stubs: - self._stubs["collect_user_event"] = self.grpc_channel.unary_unary( + self._stubs["collect_user_event"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.UserEventService/CollectUserEvent", request_serializer=user_event_service.CollectUserEventRequest.serialize, response_deserializer=httpbody_pb2.HttpBody.FromString, @@ -349,7 +434,7 @@ def list_user_events( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_user_events" not in self._stubs: - self._stubs["list_user_events"] = self.grpc_channel.unary_unary( + self._stubs["list_user_events"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.UserEventService/ListUserEvents", request_serializer=user_event_service.ListUserEventsRequest.serialize, response_deserializer=user_event_service.ListUserEventsResponse.deserialize, @@ -381,7 +466,7 @@ def purge_user_events( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "purge_user_events" not in self._stubs: - self._stubs["purge_user_events"] = self.grpc_channel.unary_unary( + self._stubs["purge_user_events"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.UserEventService/PurgeUserEvents", request_serializer=user_event_service.PurgeUserEventsRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -416,7 +501,7 @@ def import_user_events( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "import_user_events" not in self._stubs: - self._stubs["import_user_events"] = self.grpc_channel.unary_unary( + self._stubs["import_user_events"] = self._logged_channel.unary_unary( "/google.cloud.recommendationengine.v1beta1.UserEventService/ImportUserEvents", request_serializer=import_.ImportUserEventsRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -509,7 +594,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/transports/rest.py b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/transports/rest.py index e060f959e61b..2808d40aa592 100644 --- a/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/transports/rest.py +++ b/packages/google-cloud-recommendations-ai/google/cloud/recommendationengine_v1beta1/services/user_event_service/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -41,6 +41,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -113,8 +121,11 @@ def post_write_user_event(self, response): def pre_collect_user_event( self, request: user_event_service.CollectUserEventRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[user_event_service.CollectUserEventRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + user_event_service.CollectUserEventRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for collect_user_event Override in a subclass to manipulate the request or metadata @@ -136,8 +147,10 @@ def post_collect_user_event( def pre_import_user_events( self, request: import_.ImportUserEventsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[import_.ImportUserEventsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + import_.ImportUserEventsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for import_user_events Override in a subclass to manipulate the request or metadata @@ -159,8 +172,11 @@ def post_import_user_events( def pre_list_user_events( self, request: user_event_service.ListUserEventsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[user_event_service.ListUserEventsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + user_event_service.ListUserEventsRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for list_user_events Override in a subclass to manipulate the request or metadata @@ -182,8 +198,11 @@ def post_list_user_events( def pre_purge_user_events( self, request: user_event_service.PurgeUserEventsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[user_event_service.PurgeUserEventsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + user_event_service.PurgeUserEventsRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for purge_user_events Override in a subclass to manipulate the request or metadata @@ -205,8 +224,11 @@ def post_purge_user_events( def pre_write_user_event( self, request: user_event_service.WriteUserEventRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[user_event_service.WriteUserEventRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + user_event_service.WriteUserEventRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for write_user_event Override in a subclass to manipulate the request or metadata @@ -397,7 +419,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> httpbody_pb2.HttpBody: r"""Call the collect user event method over HTTP. @@ -408,8 +430,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.httpbody_pb2.HttpBody: @@ -468,6 +492,7 @@ def __call__( http_options = ( _BaseUserEventServiceRestTransport._BaseCollectUserEvent._get_http_options() ) + request, metadata = self._interceptor.pre_collect_user_event( request, metadata ) @@ -480,6 +505,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommendationengine_v1beta1.UserEventServiceClient.CollectUserEvent", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.UserEventService", + "rpcName": "CollectUserEvent", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = UserEventServiceRestTransport._CollectUserEvent._get_response( self._host, @@ -500,7 +552,29 @@ def __call__( pb_resp = resp json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_collect_user_event(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommendationengine_v1beta1.UserEventServiceClient.collect_user_event", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.UserEventService", + "rpcName": "CollectUserEvent", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ImportUserEvents( @@ -539,7 +613,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the import user events method over HTTP. @@ -550,8 +624,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -564,6 +640,7 @@ def __call__( http_options = ( _BaseUserEventServiceRestTransport._BaseImportUserEvents._get_http_options() ) + request, metadata = self._interceptor.pre_import_user_events( request, metadata ) @@ -580,6 +657,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommendationengine_v1beta1.UserEventServiceClient.ImportUserEvents", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.UserEventService", + "rpcName": "ImportUserEvents", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = UserEventServiceRestTransport._ImportUserEvents._get_response( self._host, @@ -599,7 +703,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_import_user_events(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommendationengine_v1beta1.UserEventServiceClient.import_user_events", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.UserEventService", + "rpcName": "ImportUserEvents", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListUserEvents( @@ -636,7 +762,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> user_event_service.ListUserEventsResponse: r"""Call the list user events method over HTTP. @@ -647,8 +773,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.user_event_service.ListUserEventsResponse: @@ -660,6 +788,7 @@ def __call__( http_options = ( _BaseUserEventServiceRestTransport._BaseListUserEvents._get_http_options() ) + request, metadata = self._interceptor.pre_list_user_events( request, metadata ) @@ -672,6 +801,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommendationengine_v1beta1.UserEventServiceClient.ListUserEvents", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.UserEventService", + "rpcName": "ListUserEvents", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = UserEventServiceRestTransport._ListUserEvents._get_response( self._host, @@ -692,7 +848,31 @@ def __call__( pb_resp = user_event_service.ListUserEventsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_user_events(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + user_event_service.ListUserEventsResponse.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommendationengine_v1beta1.UserEventServiceClient.list_user_events", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.UserEventService", + "rpcName": "ListUserEvents", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _PurgeUserEvents( @@ -731,7 +911,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the purge user events method over HTTP. @@ -742,8 +922,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -756,6 +938,7 @@ def __call__( http_options = ( _BaseUserEventServiceRestTransport._BasePurgeUserEvents._get_http_options() ) + request, metadata = self._interceptor.pre_purge_user_events( request, metadata ) @@ -772,6 +955,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommendationengine_v1beta1.UserEventServiceClient.PurgeUserEvents", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.UserEventService", + "rpcName": "PurgeUserEvents", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = UserEventServiceRestTransport._PurgeUserEvents._get_response( self._host, @@ -791,7 +1001,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_purge_user_events(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommendationengine_v1beta1.UserEventServiceClient.purge_user_events", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.UserEventService", + "rpcName": "PurgeUserEvents", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _WriteUserEvent( @@ -829,7 +1061,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> gcr_user_event.UserEvent: r"""Call the write user event method over HTTP. @@ -840,8 +1072,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.gcr_user_event.UserEvent: @@ -855,6 +1089,7 @@ def __call__( http_options = ( _BaseUserEventServiceRestTransport._BaseWriteUserEvent._get_http_options() ) + request, metadata = self._interceptor.pre_write_user_event( request, metadata ) @@ -871,6 +1106,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommendationengine_v1beta1.UserEventServiceClient.WriteUserEvent", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.UserEventService", + "rpcName": "WriteUserEvent", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = UserEventServiceRestTransport._WriteUserEvent._get_response( self._host, @@ -892,7 +1154,29 @@ def __call__( pb_resp = gcr_user_event.UserEvent.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_write_user_event(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = gcr_user_event.UserEvent.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommendationengine_v1beta1.UserEventServiceClient.write_user_event", + extra={ + "serviceName": "google.cloud.recommendationengine.v1beta1.UserEventService", + "rpcName": "WriteUserEvent", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property diff --git a/packages/google-cloud-recommendations-ai/samples/generated_samples/snippet_metadata_google.cloud.recommendationengine.v1beta1.json b/packages/google-cloud-recommendations-ai/samples/generated_samples/snippet_metadata_google.cloud.recommendationengine.v1beta1.json index 966c861303ab..d22dc88c7d5b 100644 --- a/packages/google-cloud-recommendations-ai/samples/generated_samples/snippet_metadata_google.cloud.recommendationengine.v1beta1.json +++ b/packages/google-cloud-recommendations-ai/samples/generated_samples/snippet_metadata_google.cloud.recommendationengine.v1beta1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-recommendations-ai", - "version": "0.10.14" + "version": "0.1.0" }, "snippets": [ { @@ -51,7 +51,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommendationengine_v1beta1.types.CatalogItem", @@ -135,7 +135,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommendationengine_v1beta1.types.CatalogItem", @@ -216,7 +216,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "shortName": "delete_catalog_item" @@ -293,7 +293,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "shortName": "delete_catalog_item" @@ -371,7 +371,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommendationengine_v1beta1.types.CatalogItem", @@ -451,7 +451,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommendationengine_v1beta1.types.CatalogItem", @@ -544,7 +544,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -636,7 +636,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -721,7 +721,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommendationengine_v1beta1.services.catalog_service.pagers.ListCatalogItemsAsyncPager", @@ -805,7 +805,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommendationengine_v1beta1.services.catalog_service.pagers.ListCatalogItemsPager", @@ -894,7 +894,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommendationengine_v1beta1.types.CatalogItem", @@ -982,7 +982,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommendationengine_v1beta1.types.CatalogItem", @@ -1067,7 +1067,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommendationengine_v1beta1.types.PredictionApiKeyRegistration", @@ -1151,7 +1151,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommendationengine_v1beta1.types.PredictionApiKeyRegistration", @@ -1232,7 +1232,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "shortName": "delete_prediction_api_key_registration" @@ -1309,7 +1309,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "shortName": "delete_prediction_api_key_registration" @@ -1387,7 +1387,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommendationengine_v1beta1.services.prediction_api_key_registry.pagers.ListPredictionApiKeyRegistrationsAsyncPager", @@ -1467,7 +1467,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommendationengine_v1beta1.services.prediction_api_key_registry.pagers.ListPredictionApiKeyRegistrationsPager", @@ -1552,7 +1552,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommendationengine_v1beta1.services.prediction_service.pagers.PredictAsyncPager", @@ -1636,7 +1636,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommendationengine_v1beta1.services.prediction_service.pagers.PredictPager", @@ -1729,7 +1729,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api.httpbody_pb2.HttpBody", @@ -1821,7 +1821,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api.httpbody_pb2.HttpBody", @@ -1914,7 +1914,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -2006,7 +2006,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -2091,7 +2091,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommendationengine_v1beta1.services.user_event_service.pagers.ListUserEventsAsyncPager", @@ -2175,7 +2175,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommendationengine_v1beta1.services.user_event_service.pagers.ListUserEventsPager", @@ -2264,7 +2264,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -2352,7 +2352,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -2437,7 +2437,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommendationengine_v1beta1.types.UserEvent", @@ -2521,7 +2521,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommendationengine_v1beta1.types.UserEvent", diff --git a/packages/google-cloud-recommendations-ai/tests/unit/gapic/recommendationengine_v1beta1/test_catalog_service.py b/packages/google-cloud-recommendations-ai/tests/unit/gapic/recommendationengine_v1beta1/test_catalog_service.py index d072b6a8c97a..40a8e8d24f93 100644 --- a/packages/google-cloud-recommendations-ai/tests/unit/gapic/recommendationengine_v1beta1/test_catalog_service.py +++ b/packages/google-cloud-recommendations-ai/tests/unit/gapic/recommendationengine_v1beta1/test_catalog_service.py @@ -3561,6 +3561,7 @@ def test_create_catalog_item_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_catalog_item(request) @@ -3617,6 +3618,7 @@ def test_create_catalog_item_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_catalog_item(**mock_args) @@ -3751,6 +3753,7 @@ def test_get_catalog_item_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_catalog_item(request) @@ -3798,6 +3801,7 @@ def test_get_catalog_item_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_catalog_item(**mock_args) @@ -3941,6 +3945,7 @@ def test_list_catalog_items_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_catalog_items(request) @@ -3998,6 +4003,7 @@ def test_list_catalog_items_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_catalog_items(**mock_args) @@ -4202,6 +4208,7 @@ def test_update_catalog_item_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_catalog_item(request) @@ -4259,6 +4266,7 @@ def test_update_catalog_item_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_catalog_item(**mock_args) @@ -4393,6 +4401,7 @@ def test_delete_catalog_item_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_catalog_item(request) @@ -4438,6 +4447,7 @@ def test_delete_catalog_item_rest_flattened(): json_return_value = "" response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_catalog_item(**mock_args) @@ -4575,6 +4585,7 @@ def test_import_catalog_items_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.import_catalog_items(request) @@ -4635,6 +4646,7 @@ def test_import_catalog_items_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.import_catalog_items(**mock_args) @@ -5136,6 +5148,7 @@ def test_create_catalog_item_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_catalog_item(request) @@ -5265,6 +5278,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_catalog_item(request) # Establish that the response is the type that we expect. @@ -5310,6 +5324,7 @@ def test_create_catalog_item_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = catalog.CatalogItem.to_json(catalog.CatalogItem()) req.return_value.content = return_value @@ -5356,6 +5371,7 @@ def test_get_catalog_item_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_catalog_item(request) @@ -5398,6 +5414,7 @@ def test_get_catalog_item_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_catalog_item(request) # Establish that the response is the type that we expect. @@ -5443,6 +5460,7 @@ def test_get_catalog_item_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = catalog.CatalogItem.to_json(catalog.CatalogItem()) req.return_value.content = return_value @@ -5487,6 +5505,7 @@ def test_list_catalog_items_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_catalog_items(request) @@ -5522,6 +5541,7 @@ def test_list_catalog_items_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_catalog_items(request) # Establish that the response is the type that we expect. @@ -5562,6 +5582,7 @@ def test_list_catalog_items_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = catalog_service.ListCatalogItemsResponse.to_json( catalog_service.ListCatalogItemsResponse() ) @@ -5610,6 +5631,7 @@ def test_update_catalog_item_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_catalog_item(request) @@ -5741,6 +5763,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_catalog_item(request) # Establish that the response is the type that we expect. @@ -5786,6 +5809,7 @@ def test_update_catalog_item_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = catalog.CatalogItem.to_json(catalog.CatalogItem()) req.return_value.content = return_value @@ -5832,6 +5856,7 @@ def test_delete_catalog_item_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_catalog_item(request) @@ -5864,6 +5889,7 @@ def test_delete_catalog_item_rest_call_success(request_type): json_return_value = "" response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_catalog_item(request) # Establish that the response is the type that we expect. @@ -5900,6 +5926,7 @@ def test_delete_catalog_item_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} request = catalog_service.DeleteCatalogItemRequest() metadata = [ @@ -5940,6 +5967,7 @@ def test_import_catalog_items_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.import_catalog_items(request) @@ -5970,6 +5998,7 @@ def test_import_catalog_items_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.import_catalog_items(request) # Establish that the response is the type that we expect. @@ -6011,6 +6040,7 @@ def test_import_catalog_items_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value diff --git a/packages/google-cloud-recommendations-ai/tests/unit/gapic/recommendationengine_v1beta1/test_prediction_api_key_registry.py b/packages/google-cloud-recommendations-ai/tests/unit/gapic/recommendationengine_v1beta1/test_prediction_api_key_registry.py index ee3edf7e85fb..e417cbeb6e91 100644 --- a/packages/google-cloud-recommendations-ai/tests/unit/gapic/recommendationengine_v1beta1/test_prediction_api_key_registry.py +++ b/packages/google-cloud-recommendations-ai/tests/unit/gapic/recommendationengine_v1beta1/test_prediction_api_key_registry.py @@ -2557,6 +2557,7 @@ def test_create_prediction_api_key_registration_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_prediction_api_key_registration(request) @@ -2621,6 +2622,7 @@ def test_create_prediction_api_key_registration_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_prediction_api_key_registration(**mock_args) @@ -2777,6 +2779,7 @@ def test_list_prediction_api_key_registrations_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_prediction_api_key_registrations(request) @@ -2838,6 +2841,7 @@ def test_list_prediction_api_key_registrations_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_prediction_api_key_registrations(**mock_args) @@ -3052,6 +3056,7 @@ def test_delete_prediction_api_key_registration_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_prediction_api_key_registration(request) @@ -3099,6 +3104,7 @@ def test_delete_prediction_api_key_registration_rest_flattened(): json_return_value = "" response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_prediction_api_key_registration(**mock_args) @@ -3448,6 +3454,7 @@ def test_create_prediction_api_key_registration_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_prediction_api_key_registration(request) @@ -3489,6 +3496,7 @@ def test_create_prediction_api_key_registration_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_prediction_api_key_registration(request) # Establish that the response is the type that we expect. @@ -3533,6 +3541,7 @@ def test_create_prediction_api_key_registration_rest_interceptors(null_intercept req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = ( prediction_apikey_registry_service.PredictionApiKeyRegistration.to_json( prediction_apikey_registry_service.PredictionApiKeyRegistration() @@ -3587,6 +3596,7 @@ def test_list_prediction_api_key_registrations_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_prediction_api_key_registrations(request) @@ -3626,6 +3636,7 @@ def test_list_prediction_api_key_registrations_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_prediction_api_key_registrations(request) # Establish that the response is the type that we expect. @@ -3668,6 +3679,7 @@ def test_list_prediction_api_key_registrations_rest_interceptors(null_intercepto req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = prediction_apikey_registry_service.ListPredictionApiKeyRegistrationsResponse.to_json( prediction_apikey_registry_service.ListPredictionApiKeyRegistrationsResponse() ) @@ -3720,6 +3732,7 @@ def test_delete_prediction_api_key_registration_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_prediction_api_key_registration(request) @@ -3752,6 +3765,7 @@ def test_delete_prediction_api_key_registration_rest_call_success(request_type): json_return_value = "" response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_prediction_api_key_registration(request) # Establish that the response is the type that we expect. @@ -3789,6 +3803,7 @@ def test_delete_prediction_api_key_registration_rest_interceptors(null_intercept req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} request = ( prediction_apikey_registry_service.DeletePredictionApiKeyRegistrationRequest() diff --git a/packages/google-cloud-recommendations-ai/tests/unit/gapic/recommendationengine_v1beta1/test_prediction_service.py b/packages/google-cloud-recommendations-ai/tests/unit/gapic/recommendationengine_v1beta1/test_prediction_service.py index 32a0a73d3788..55224e7f9975 100644 --- a/packages/google-cloud-recommendations-ai/tests/unit/gapic/recommendationengine_v1beta1/test_prediction_service.py +++ b/packages/google-cloud-recommendations-ai/tests/unit/gapic/recommendationengine_v1beta1/test_prediction_service.py @@ -1753,6 +1753,7 @@ def test_predict_rest_required_fields(request_type=prediction_service.PredictReq response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.predict(request) @@ -1809,6 +1810,7 @@ def test_predict_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.predict(**mock_args) @@ -2106,6 +2108,7 @@ def test_predict_rest_bad_request(request_type=prediction_service.PredictRequest response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.predict(request) @@ -2146,6 +2149,7 @@ def test_predict_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.predict(request) # Establish that the response is the type that we expect. @@ -2189,6 +2193,7 @@ def test_predict_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = prediction_service.PredictResponse.to_json( prediction_service.PredictResponse() ) diff --git a/packages/google-cloud-recommendations-ai/tests/unit/gapic/recommendationengine_v1beta1/test_user_event_service.py b/packages/google-cloud-recommendations-ai/tests/unit/gapic/recommendationengine_v1beta1/test_user_event_service.py index 89c8229f81dd..c89712ecff86 100644 --- a/packages/google-cloud-recommendations-ai/tests/unit/gapic/recommendationengine_v1beta1/test_user_event_service.py +++ b/packages/google-cloud-recommendations-ai/tests/unit/gapic/recommendationengine_v1beta1/test_user_event_service.py @@ -3232,6 +3232,7 @@ def test_write_user_event_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.write_user_event(request) @@ -3288,6 +3289,7 @@ def test_write_user_event_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.write_user_event(**mock_args) @@ -3437,6 +3439,7 @@ def test_collect_user_event_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.collect_user_event(request) @@ -3505,6 +3508,7 @@ def test_collect_user_event_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.collect_user_event(**mock_args) @@ -3649,6 +3653,7 @@ def test_list_user_events_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_user_events(request) @@ -3706,6 +3711,7 @@ def test_list_user_events_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_user_events(**mock_args) @@ -3911,6 +3917,7 @@ def test_purge_user_events_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.purge_user_events(request) @@ -3966,6 +3973,7 @@ def test_purge_user_events_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.purge_user_events(**mock_args) @@ -4105,6 +4113,7 @@ def test_import_user_events_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.import_user_events(request) @@ -4165,6 +4174,7 @@ def test_import_user_events_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.import_user_events(**mock_args) @@ -4601,6 +4611,7 @@ def test_write_user_event_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.write_user_event(request) @@ -4753,6 +4764,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.write_user_event(request) # Establish that the response is the type that we expect. @@ -4794,6 +4806,7 @@ def test_write_user_event_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = gcr_user_event.UserEvent.to_json(gcr_user_event.UserEvent()) req.return_value.content = return_value @@ -4840,6 +4853,7 @@ def test_collect_user_event_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.collect_user_event(request) @@ -4875,6 +4889,7 @@ def test_collect_user_event_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.collect_user_event(request) # Establish that the response is the type that we expect. @@ -4916,6 +4931,7 @@ def test_collect_user_event_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(httpbody_pb2.HttpBody()) req.return_value.content = return_value @@ -4962,6 +4978,7 @@ def test_list_user_events_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_user_events(request) @@ -4999,6 +5016,7 @@ def test_list_user_events_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_user_events(request) # Establish that the response is the type that we expect. @@ -5039,6 +5057,7 @@ def test_list_user_events_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = user_event_service.ListUserEventsResponse.to_json( user_event_service.ListUserEventsResponse() ) @@ -5087,6 +5106,7 @@ def test_purge_user_events_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.purge_user_events(request) @@ -5119,6 +5139,7 @@ def test_purge_user_events_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.purge_user_events(request) # Establish that the response is the type that we expect. @@ -5160,6 +5181,7 @@ def test_purge_user_events_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -5206,6 +5228,7 @@ def test_import_user_events_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.import_user_events(request) @@ -5238,6 +5261,7 @@ def test_import_user_events_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.import_user_events(request) # Establish that the response is the type that we expect. @@ -5279,6 +5303,7 @@ def test_import_user_events_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value diff --git a/packages/google-cloud-recommender/google/cloud/recommender/gapic_version.py b/packages/google-cloud-recommender/google/cloud/recommender/gapic_version.py index 1230672bab9e..558c8aab67c5 100644 --- a/packages/google-cloud-recommender/google/cloud/recommender/gapic_version.py +++ b/packages/google-cloud-recommender/google/cloud/recommender/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.16.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-recommender/google/cloud/recommender_v1/gapic_version.py b/packages/google-cloud-recommender/google/cloud/recommender_v1/gapic_version.py index 1230672bab9e..558c8aab67c5 100644 --- a/packages/google-cloud-recommender/google/cloud/recommender_v1/gapic_version.py +++ b/packages/google-cloud-recommender/google/cloud/recommender_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.16.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/async_client.py b/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/async_client.py index fde02c55493e..a402c8ffebcb 100644 --- a/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/async_client.py +++ b/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -64,6 +65,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, RecommenderTransport from .transports.grpc_asyncio import RecommenderGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class RecommenderAsyncClient: """Provides insights and recommendations for cloud customers for @@ -286,6 +296,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.recommender_v1.RecommenderAsyncClient`.", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.recommender.v1.Recommender", + "credentialsType": None, + }, + ) + async def list_insights( self, request: Optional[Union[recommender_service.ListInsightsRequest, dict]] = None, @@ -293,7 +325,7 @@ async def list_insights( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListInsightsAsyncPager: r"""Lists insights for the specified Cloud Resource. Requires the recommender.*.list IAM permission for the specified insight @@ -354,8 +386,10 @@ async def sample_list_insights(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.services.recommender.pagers.ListInsightsAsyncPager: @@ -429,7 +463,7 @@ async def get_insight( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> insight.Insight: r"""Gets the requested insight. Requires the recommender.*.get IAM permission for the specified insight type. @@ -471,8 +505,10 @@ async def sample_get_insight(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.types.Insight: @@ -539,7 +575,7 @@ async def mark_insight_accepted( etag: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> insight.Insight: r"""Marks the Insight State as Accepted. Users can use this method to indicate to the Recommender API that they have applied some @@ -602,8 +638,10 @@ async def sample_mark_insight_accepted(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.types.Insight: @@ -674,7 +712,7 @@ async def list_recommendations( filter: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListRecommendationsAsyncPager: r"""Lists recommendations for the specified Cloud Resource. Requires the recommender.*.list IAM permission for the specified @@ -767,8 +805,10 @@ async def sample_list_recommendations(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.services.recommender.pagers.ListRecommendationsAsyncPager: @@ -846,7 +886,7 @@ async def get_recommendation( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Gets the requested recommendation. Requires the recommender.*.get IAM permission for the specified recommender. @@ -888,8 +928,10 @@ async def sample_get_recommendation(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.types.Recommendation: @@ -953,7 +995,7 @@ async def mark_recommendation_dismissed( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Mark the Recommendation State as Dismissed. Users can use this method to indicate to the Recommender API that an ACTIVE @@ -997,8 +1039,10 @@ async def sample_mark_recommendation_dismissed(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.types.Recommendation: @@ -1053,7 +1097,7 @@ async def mark_recommendation_claimed( etag: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Marks the Recommendation State as Claimed. Users can use this method to indicate to the Recommender API that they are starting @@ -1122,8 +1166,10 @@ async def sample_mark_recommendation_claimed(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.types.Recommendation: @@ -1197,7 +1243,7 @@ async def mark_recommendation_succeeded( etag: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Marks the Recommendation State as Succeeded. Users can use this method to indicate to the Recommender API that they have applied @@ -1266,8 +1312,10 @@ async def sample_mark_recommendation_succeeded(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.types.Recommendation: @@ -1341,7 +1389,7 @@ async def mark_recommendation_failed( etag: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Marks the Recommendation State as Failed. Users can use this method to indicate to the Recommender API that they have applied @@ -1410,8 +1458,10 @@ async def sample_mark_recommendation_failed(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.types.Recommendation: @@ -1481,7 +1531,7 @@ async def get_recommender_config( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommender_config.RecommenderConfig: r"""Gets the requested Recommender Config. There is only one instance of the config for each Recommender. @@ -1534,8 +1584,10 @@ async def sample_get_recommender_config(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.types.RecommenderConfig: @@ -1597,7 +1649,7 @@ async def update_recommender_config( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> gcr_recommender_config.RecommenderConfig: r"""Updates a Recommender Config. This will create a new revision of the config. @@ -1645,8 +1697,10 @@ async def sample_update_recommender_config(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.types.RecommenderConfig: @@ -1711,7 +1765,7 @@ async def get_insight_type_config( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> insight_type_config.InsightTypeConfig: r"""Gets the requested InsightTypeConfig. There is only one instance of the config for each InsightType. @@ -1764,8 +1818,10 @@ async def sample_get_insight_type_config(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.types.InsightTypeConfig: @@ -1827,7 +1883,7 @@ async def update_insight_type_config( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> gcr_insight_type_config.InsightTypeConfig: r"""Updates an InsightTypeConfig change. This will create a new revision of the config. @@ -1875,8 +1931,10 @@ async def sample_update_insight_type_config(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.types.InsightTypeConfig: diff --git a/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/client.py b/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/client.py index 71b561dc213c..1a4a9226790d 100644 --- a/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/client.py +++ b/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.protobuf import duration_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore @@ -712,6 +722,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -774,6 +788,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.recommender_v1.RecommenderClient`.", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.recommender.v1.Recommender", + "credentialsType": None, + }, + ) + def list_insights( self, request: Optional[Union[recommender_service.ListInsightsRequest, dict]] = None, @@ -781,7 +818,7 @@ def list_insights( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListInsightsPager: r"""Lists insights for the specified Cloud Resource. Requires the recommender.*.list IAM permission for the specified insight @@ -842,8 +879,10 @@ def sample_list_insights(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.services.recommender.pagers.ListInsightsPager: @@ -914,7 +953,7 @@ def get_insight( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> insight.Insight: r"""Gets the requested insight. Requires the recommender.*.get IAM permission for the specified insight type. @@ -956,8 +995,10 @@ def sample_get_insight(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.types.Insight: @@ -1021,7 +1062,7 @@ def mark_insight_accepted( etag: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> insight.Insight: r"""Marks the Insight State as Accepted. Users can use this method to indicate to the Recommender API that they have applied some @@ -1084,8 +1125,10 @@ def sample_mark_insight_accepted(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.types.Insight: @@ -1152,7 +1195,7 @@ def list_recommendations( filter: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListRecommendationsPager: r"""Lists recommendations for the specified Cloud Resource. Requires the recommender.*.list IAM permission for the specified @@ -1245,8 +1288,10 @@ def sample_list_recommendations(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.services.recommender.pagers.ListRecommendationsPager: @@ -1321,7 +1366,7 @@ def get_recommendation( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Gets the requested recommendation. Requires the recommender.*.get IAM permission for the specified recommender. @@ -1363,8 +1408,10 @@ def sample_get_recommendation(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.types.Recommendation: @@ -1425,7 +1472,7 @@ def mark_recommendation_dismissed( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Mark the Recommendation State as Dismissed. Users can use this method to indicate to the Recommender API that an ACTIVE @@ -1469,8 +1516,10 @@ def sample_mark_recommendation_dismissed(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.types.Recommendation: @@ -1525,7 +1574,7 @@ def mark_recommendation_claimed( etag: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Marks the Recommendation State as Claimed. Users can use this method to indicate to the Recommender API that they are starting @@ -1594,8 +1643,10 @@ def sample_mark_recommendation_claimed(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.types.Recommendation: @@ -1667,7 +1718,7 @@ def mark_recommendation_succeeded( etag: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Marks the Recommendation State as Succeeded. Users can use this method to indicate to the Recommender API that they have applied @@ -1736,8 +1787,10 @@ def sample_mark_recommendation_succeeded(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.types.Recommendation: @@ -1809,7 +1862,7 @@ def mark_recommendation_failed( etag: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Marks the Recommendation State as Failed. Users can use this method to indicate to the Recommender API that they have applied @@ -1878,8 +1931,10 @@ def sample_mark_recommendation_failed(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.types.Recommendation: @@ -1947,7 +2002,7 @@ def get_recommender_config( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommender_config.RecommenderConfig: r"""Gets the requested Recommender Config. There is only one instance of the config for each Recommender. @@ -2000,8 +2055,10 @@ def sample_get_recommender_config(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.types.RecommenderConfig: @@ -2060,7 +2117,7 @@ def update_recommender_config( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> gcr_recommender_config.RecommenderConfig: r"""Updates a Recommender Config. This will create a new revision of the config. @@ -2108,8 +2165,10 @@ def sample_update_recommender_config(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.types.RecommenderConfig: @@ -2173,7 +2232,7 @@ def get_insight_type_config( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> insight_type_config.InsightTypeConfig: r"""Gets the requested InsightTypeConfig. There is only one instance of the config for each InsightType. @@ -2226,8 +2285,10 @@ def sample_get_insight_type_config(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.types.InsightTypeConfig: @@ -2286,7 +2347,7 @@ def update_insight_type_config( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> gcr_insight_type_config.InsightTypeConfig: r"""Updates an InsightTypeConfig change. This will create a new revision of the config. @@ -2334,8 +2395,10 @@ def sample_update_insight_type_config(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1.types.InsightTypeConfig: diff --git a/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/pagers.py b/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/pagers.py index f0fc915235d2..19361bd8e868 100644 --- a/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/pagers.py +++ b/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/pagers.py @@ -71,7 +71,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -85,8 +85,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recommender_service.ListInsightsRequest(request) @@ -145,7 +147,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -159,8 +161,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recommender_service.ListInsightsRequest(request) @@ -223,7 +227,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -237,8 +241,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recommender_service.ListRecommendationsRequest(request) @@ -299,7 +305,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -313,8 +319,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recommender_service.ListRecommendationsRequest(request) diff --git a/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/transports/grpc.py b/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/transports/grpc.py index eb2bd4abcb16..0368879c10c9 100644 --- a/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/transports/grpc.py +++ b/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -20,7 +23,10 @@ import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.recommender_v1.types import ( insight_type_config as gcr_insight_type_config, @@ -36,6 +42,81 @@ from .base import DEFAULT_CLIENT_INFO, RecommenderTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class RecommenderGrpcTransport(RecommenderTransport): """gRPC backend transport for Recommender. @@ -193,7 +274,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -272,7 +358,7 @@ def list_insights( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_insights" not in self._stubs: - self._stubs["list_insights"] = self.grpc_channel.unary_unary( + self._stubs["list_insights"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/ListInsights", request_serializer=recommender_service.ListInsightsRequest.serialize, response_deserializer=recommender_service.ListInsightsResponse.deserialize, @@ -299,7 +385,7 @@ def get_insight( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_insight" not in self._stubs: - self._stubs["get_insight"] = self.grpc_channel.unary_unary( + self._stubs["get_insight"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/GetInsight", request_serializer=recommender_service.GetInsightRequest.serialize, response_deserializer=insight.Insight.deserialize, @@ -332,7 +418,7 @@ def mark_insight_accepted( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "mark_insight_accepted" not in self._stubs: - self._stubs["mark_insight_accepted"] = self.grpc_channel.unary_unary( + self._stubs["mark_insight_accepted"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/MarkInsightAccepted", request_serializer=recommender_service.MarkInsightAcceptedRequest.serialize, response_deserializer=insight.Insight.deserialize, @@ -363,7 +449,7 @@ def list_recommendations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_recommendations" not in self._stubs: - self._stubs["list_recommendations"] = self.grpc_channel.unary_unary( + self._stubs["list_recommendations"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/ListRecommendations", request_serializer=recommender_service.ListRecommendationsRequest.serialize, response_deserializer=recommender_service.ListRecommendationsResponse.deserialize, @@ -392,7 +478,7 @@ def get_recommendation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_recommendation" not in self._stubs: - self._stubs["get_recommendation"] = self.grpc_channel.unary_unary( + self._stubs["get_recommendation"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/GetRecommendation", request_serializer=recommender_service.GetRecommendationRequest.serialize, response_deserializer=recommendation.Recommendation.deserialize, @@ -431,7 +517,7 @@ def mark_recommendation_dismissed( if "mark_recommendation_dismissed" not in self._stubs: self._stubs[ "mark_recommendation_dismissed" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/MarkRecommendationDismissed", request_serializer=recommender_service.MarkRecommendationDismissedRequest.serialize, response_deserializer=recommendation.Recommendation.deserialize, @@ -470,7 +556,9 @@ def mark_recommendation_claimed( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "mark_recommendation_claimed" not in self._stubs: - self._stubs["mark_recommendation_claimed"] = self.grpc_channel.unary_unary( + self._stubs[ + "mark_recommendation_claimed" + ] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/MarkRecommendationClaimed", request_serializer=recommender_service.MarkRecommendationClaimedRequest.serialize, response_deserializer=recommendation.Recommendation.deserialize, @@ -511,7 +599,7 @@ def mark_recommendation_succeeded( if "mark_recommendation_succeeded" not in self._stubs: self._stubs[ "mark_recommendation_succeeded" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/MarkRecommendationSucceeded", request_serializer=recommender_service.MarkRecommendationSucceededRequest.serialize, response_deserializer=recommendation.Recommendation.deserialize, @@ -550,7 +638,9 @@ def mark_recommendation_failed( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "mark_recommendation_failed" not in self._stubs: - self._stubs["mark_recommendation_failed"] = self.grpc_channel.unary_unary( + self._stubs[ + "mark_recommendation_failed" + ] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/MarkRecommendationFailed", request_serializer=recommender_service.MarkRecommendationFailedRequest.serialize, response_deserializer=recommendation.Recommendation.deserialize, @@ -580,7 +670,7 @@ def get_recommender_config( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_recommender_config" not in self._stubs: - self._stubs["get_recommender_config"] = self.grpc_channel.unary_unary( + self._stubs["get_recommender_config"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/GetRecommenderConfig", request_serializer=recommender_service.GetRecommenderConfigRequest.serialize, response_deserializer=recommender_config.RecommenderConfig.deserialize, @@ -610,7 +700,7 @@ def update_recommender_config( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_recommender_config" not in self._stubs: - self._stubs["update_recommender_config"] = self.grpc_channel.unary_unary( + self._stubs["update_recommender_config"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/UpdateRecommenderConfig", request_serializer=recommender_service.UpdateRecommenderConfigRequest.serialize, response_deserializer=gcr_recommender_config.RecommenderConfig.deserialize, @@ -640,7 +730,7 @@ def get_insight_type_config( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_insight_type_config" not in self._stubs: - self._stubs["get_insight_type_config"] = self.grpc_channel.unary_unary( + self._stubs["get_insight_type_config"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/GetInsightTypeConfig", request_serializer=recommender_service.GetInsightTypeConfigRequest.serialize, response_deserializer=insight_type_config.InsightTypeConfig.deserialize, @@ -670,7 +760,9 @@ def update_insight_type_config( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_insight_type_config" not in self._stubs: - self._stubs["update_insight_type_config"] = self.grpc_channel.unary_unary( + self._stubs[ + "update_insight_type_config" + ] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/UpdateInsightTypeConfig", request_serializer=recommender_service.UpdateInsightTypeConfigRequest.serialize, response_deserializer=gcr_insight_type_config.InsightTypeConfig.deserialize, @@ -678,7 +770,7 @@ def update_insight_type_config( return self._stubs["update_insight_type_config"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/transports/grpc_asyncio.py b/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/transports/grpc_asyncio.py index 413fbd3463c0..d8d212ba0f15 100644 --- a/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/transports/grpc_asyncio.py +++ b/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -22,8 +25,11 @@ from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.recommender_v1.types import ( insight_type_config as gcr_insight_type_config, @@ -40,6 +46,82 @@ from .base import DEFAULT_CLIENT_INFO, RecommenderTransport from .grpc import RecommenderGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class RecommenderGrpcAsyncIOTransport(RecommenderTransport): """gRPC AsyncIO backend transport for Recommender. @@ -240,10 +322,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -280,7 +365,7 @@ def list_insights( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_insights" not in self._stubs: - self._stubs["list_insights"] = self.grpc_channel.unary_unary( + self._stubs["list_insights"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/ListInsights", request_serializer=recommender_service.ListInsightsRequest.serialize, response_deserializer=recommender_service.ListInsightsResponse.deserialize, @@ -307,7 +392,7 @@ def get_insight( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_insight" not in self._stubs: - self._stubs["get_insight"] = self.grpc_channel.unary_unary( + self._stubs["get_insight"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/GetInsight", request_serializer=recommender_service.GetInsightRequest.serialize, response_deserializer=insight.Insight.deserialize, @@ -342,7 +427,7 @@ def mark_insight_accepted( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "mark_insight_accepted" not in self._stubs: - self._stubs["mark_insight_accepted"] = self.grpc_channel.unary_unary( + self._stubs["mark_insight_accepted"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/MarkInsightAccepted", request_serializer=recommender_service.MarkInsightAcceptedRequest.serialize, response_deserializer=insight.Insight.deserialize, @@ -373,7 +458,7 @@ def list_recommendations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_recommendations" not in self._stubs: - self._stubs["list_recommendations"] = self.grpc_channel.unary_unary( + self._stubs["list_recommendations"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/ListRecommendations", request_serializer=recommender_service.ListRecommendationsRequest.serialize, response_deserializer=recommender_service.ListRecommendationsResponse.deserialize, @@ -403,7 +488,7 @@ def get_recommendation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_recommendation" not in self._stubs: - self._stubs["get_recommendation"] = self.grpc_channel.unary_unary( + self._stubs["get_recommendation"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/GetRecommendation", request_serializer=recommender_service.GetRecommendationRequest.serialize, response_deserializer=recommendation.Recommendation.deserialize, @@ -442,7 +527,7 @@ def mark_recommendation_dismissed( if "mark_recommendation_dismissed" not in self._stubs: self._stubs[ "mark_recommendation_dismissed" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/MarkRecommendationDismissed", request_serializer=recommender_service.MarkRecommendationDismissedRequest.serialize, response_deserializer=recommendation.Recommendation.deserialize, @@ -481,7 +566,9 @@ def mark_recommendation_claimed( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "mark_recommendation_claimed" not in self._stubs: - self._stubs["mark_recommendation_claimed"] = self.grpc_channel.unary_unary( + self._stubs[ + "mark_recommendation_claimed" + ] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/MarkRecommendationClaimed", request_serializer=recommender_service.MarkRecommendationClaimedRequest.serialize, response_deserializer=recommendation.Recommendation.deserialize, @@ -522,7 +609,7 @@ def mark_recommendation_succeeded( if "mark_recommendation_succeeded" not in self._stubs: self._stubs[ "mark_recommendation_succeeded" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/MarkRecommendationSucceeded", request_serializer=recommender_service.MarkRecommendationSucceededRequest.serialize, response_deserializer=recommendation.Recommendation.deserialize, @@ -561,7 +648,9 @@ def mark_recommendation_failed( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "mark_recommendation_failed" not in self._stubs: - self._stubs["mark_recommendation_failed"] = self.grpc_channel.unary_unary( + self._stubs[ + "mark_recommendation_failed" + ] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/MarkRecommendationFailed", request_serializer=recommender_service.MarkRecommendationFailedRequest.serialize, response_deserializer=recommendation.Recommendation.deserialize, @@ -591,7 +680,7 @@ def get_recommender_config( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_recommender_config" not in self._stubs: - self._stubs["get_recommender_config"] = self.grpc_channel.unary_unary( + self._stubs["get_recommender_config"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/GetRecommenderConfig", request_serializer=recommender_service.GetRecommenderConfigRequest.serialize, response_deserializer=recommender_config.RecommenderConfig.deserialize, @@ -621,7 +710,7 @@ def update_recommender_config( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_recommender_config" not in self._stubs: - self._stubs["update_recommender_config"] = self.grpc_channel.unary_unary( + self._stubs["update_recommender_config"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/UpdateRecommenderConfig", request_serializer=recommender_service.UpdateRecommenderConfigRequest.serialize, response_deserializer=gcr_recommender_config.RecommenderConfig.deserialize, @@ -651,7 +740,7 @@ def get_insight_type_config( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_insight_type_config" not in self._stubs: - self._stubs["get_insight_type_config"] = self.grpc_channel.unary_unary( + self._stubs["get_insight_type_config"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/GetInsightTypeConfig", request_serializer=recommender_service.GetInsightTypeConfigRequest.serialize, response_deserializer=insight_type_config.InsightTypeConfig.deserialize, @@ -681,7 +770,9 @@ def update_insight_type_config( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_insight_type_config" not in self._stubs: - self._stubs["update_insight_type_config"] = self.grpc_channel.unary_unary( + self._stubs[ + "update_insight_type_config" + ] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1.Recommender/UpdateInsightTypeConfig", request_serializer=recommender_service.UpdateInsightTypeConfigRequest.serialize, response_deserializer=gcr_insight_type_config.InsightTypeConfig.deserialize, @@ -804,7 +895,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/transports/rest.py b/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/transports/rest.py index d72350cbb6eb..25b3a7928786 100644 --- a/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/transports/rest.py +++ b/packages/google-cloud-recommender/google/cloud/recommender_v1/services/recommender/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -47,6 +47,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -183,8 +191,10 @@ def post_update_recommender_config(self, response): def pre_get_insight( self, request: recommender_service.GetInsightRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[recommender_service.GetInsightRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + recommender_service.GetInsightRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_insight Override in a subclass to manipulate the request or metadata @@ -204,9 +214,10 @@ def post_get_insight(self, response: insight.Insight) -> insight.Insight: def pre_get_insight_type_config( self, request: recommender_service.GetInsightTypeConfigRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - recommender_service.GetInsightTypeConfigRequest, Sequence[Tuple[str, str]] + recommender_service.GetInsightTypeConfigRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for get_insight_type_config @@ -229,8 +240,11 @@ def post_get_insight_type_config( def pre_get_recommendation( self, request: recommender_service.GetRecommendationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[recommender_service.GetRecommendationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + recommender_service.GetRecommendationRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for get_recommendation Override in a subclass to manipulate the request or metadata @@ -252,9 +266,10 @@ def post_get_recommendation( def pre_get_recommender_config( self, request: recommender_service.GetRecommenderConfigRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - recommender_service.GetRecommenderConfigRequest, Sequence[Tuple[str, str]] + recommender_service.GetRecommenderConfigRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for get_recommender_config @@ -277,8 +292,10 @@ def post_get_recommender_config( def pre_list_insights( self, request: recommender_service.ListInsightsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[recommender_service.ListInsightsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + recommender_service.ListInsightsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_insights Override in a subclass to manipulate the request or metadata @@ -300,9 +317,10 @@ def post_list_insights( def pre_list_recommendations( self, request: recommender_service.ListRecommendationsRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - recommender_service.ListRecommendationsRequest, Sequence[Tuple[str, str]] + recommender_service.ListRecommendationsRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for list_recommendations @@ -325,9 +343,10 @@ def post_list_recommendations( def pre_mark_insight_accepted( self, request: recommender_service.MarkInsightAcceptedRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - recommender_service.MarkInsightAcceptedRequest, Sequence[Tuple[str, str]] + recommender_service.MarkInsightAcceptedRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for mark_insight_accepted @@ -348,9 +367,10 @@ def post_mark_insight_accepted(self, response: insight.Insight) -> insight.Insig def pre_mark_recommendation_claimed( self, request: recommender_service.MarkRecommendationClaimedRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - recommender_service.MarkRecommendationClaimedRequest, Sequence[Tuple[str, str]] + recommender_service.MarkRecommendationClaimedRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for mark_recommendation_claimed @@ -373,10 +393,10 @@ def post_mark_recommendation_claimed( def pre_mark_recommendation_dismissed( self, request: recommender_service.MarkRecommendationDismissedRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ recommender_service.MarkRecommendationDismissedRequest, - Sequence[Tuple[str, str]], + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for mark_recommendation_dismissed @@ -399,9 +419,10 @@ def post_mark_recommendation_dismissed( def pre_mark_recommendation_failed( self, request: recommender_service.MarkRecommendationFailedRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - recommender_service.MarkRecommendationFailedRequest, Sequence[Tuple[str, str]] + recommender_service.MarkRecommendationFailedRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for mark_recommendation_failed @@ -424,10 +445,10 @@ def post_mark_recommendation_failed( def pre_mark_recommendation_succeeded( self, request: recommender_service.MarkRecommendationSucceededRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ recommender_service.MarkRecommendationSucceededRequest, - Sequence[Tuple[str, str]], + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for mark_recommendation_succeeded @@ -450,9 +471,10 @@ def post_mark_recommendation_succeeded( def pre_update_insight_type_config( self, request: recommender_service.UpdateInsightTypeConfigRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - recommender_service.UpdateInsightTypeConfigRequest, Sequence[Tuple[str, str]] + recommender_service.UpdateInsightTypeConfigRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for update_insight_type_config @@ -475,9 +497,10 @@ def post_update_insight_type_config( def pre_update_recommender_config( self, request: recommender_service.UpdateRecommenderConfigRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - recommender_service.UpdateRecommenderConfigRequest, Sequence[Tuple[str, str]] + recommender_service.UpdateRecommenderConfigRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for update_recommender_config @@ -622,7 +645,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> insight.Insight: r"""Call the get insight method over HTTP. @@ -632,8 +655,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.insight.Insight: @@ -647,6 +672,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseGetInsight._get_http_options() ) + request, metadata = self._interceptor.pre_get_insight(request, metadata) transcoded_request = ( _BaseRecommenderRestTransport._BaseGetInsight._get_transcoded_request( @@ -661,6 +687,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1.RecommenderClient.GetInsight", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "GetInsight", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RecommenderRestTransport._GetInsight._get_response( self._host, @@ -681,7 +734,29 @@ def __call__( pb_resp = insight.Insight.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_insight(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = insight.Insight.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1.RecommenderClient.get_insight", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "GetInsight", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetInsightTypeConfig( @@ -718,7 +793,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> insight_type_config.InsightTypeConfig: r"""Call the get insight type config method over HTTP. @@ -728,8 +803,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.insight_type_config.InsightTypeConfig: @@ -739,6 +816,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseGetInsightTypeConfig._get_http_options() ) + request, metadata = self._interceptor.pre_get_insight_type_config( request, metadata ) @@ -751,6 +829,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1.RecommenderClient.GetInsightTypeConfig", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "GetInsightTypeConfig", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RecommenderRestTransport._GetInsightTypeConfig._get_response( self._host, @@ -771,7 +876,31 @@ def __call__( pb_resp = insight_type_config.InsightTypeConfig.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_insight_type_config(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = insight_type_config.InsightTypeConfig.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1.RecommenderClient.get_insight_type_config", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "GetInsightTypeConfig", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetRecommendation( @@ -808,7 +937,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Call the get recommendation method over HTTP. @@ -818,8 +947,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.recommendation.Recommendation: @@ -833,6 +964,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseGetRecommendation._get_http_options() ) + request, metadata = self._interceptor.pre_get_recommendation( request, metadata ) @@ -845,6 +977,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1.RecommenderClient.GetRecommendation", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "GetRecommendation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RecommenderRestTransport._GetRecommendation._get_response( self._host, @@ -865,7 +1024,29 @@ def __call__( pb_resp = recommendation.Recommendation.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_recommendation(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = recommendation.Recommendation.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1.RecommenderClient.get_recommendation", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "GetRecommendation", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetRecommenderConfig( @@ -902,7 +1083,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommender_config.RecommenderConfig: r"""Call the get recommender config method over HTTP. @@ -912,8 +1093,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.recommender_config.RecommenderConfig: @@ -923,6 +1106,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseGetRecommenderConfig._get_http_options() ) + request, metadata = self._interceptor.pre_get_recommender_config( request, metadata ) @@ -935,6 +1119,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1.RecommenderClient.GetRecommenderConfig", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "GetRecommenderConfig", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RecommenderRestTransport._GetRecommenderConfig._get_response( self._host, @@ -955,7 +1166,31 @@ def __call__( pb_resp = recommender_config.RecommenderConfig.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_recommender_config(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = recommender_config.RecommenderConfig.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1.RecommenderClient.get_recommender_config", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "GetRecommenderConfig", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListInsights( @@ -992,7 +1227,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommender_service.ListInsightsResponse: r"""Call the list insights method over HTTP. @@ -1002,8 +1237,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.recommender_service.ListInsightsResponse: @@ -1013,6 +1250,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseListInsights._get_http_options() ) + request, metadata = self._interceptor.pre_list_insights(request, metadata) transcoded_request = ( _BaseRecommenderRestTransport._BaseListInsights._get_transcoded_request( @@ -1027,6 +1265,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1.RecommenderClient.ListInsights", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "ListInsights", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RecommenderRestTransport._ListInsights._get_response( self._host, @@ -1047,7 +1312,31 @@ def __call__( pb_resp = recommender_service.ListInsightsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_insights(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = recommender_service.ListInsightsResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1.RecommenderClient.list_insights", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "ListInsights", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListRecommendations( @@ -1084,7 +1373,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommender_service.ListRecommendationsResponse: r"""Call the list recommendations method over HTTP. @@ -1094,8 +1383,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.recommender_service.ListRecommendationsResponse: @@ -1105,6 +1396,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseListRecommendations._get_http_options() ) + request, metadata = self._interceptor.pre_list_recommendations( request, metadata ) @@ -1117,6 +1409,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1.RecommenderClient.ListRecommendations", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "ListRecommendations", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RecommenderRestTransport._ListRecommendations._get_response( self._host, @@ -1137,7 +1456,33 @@ def __call__( pb_resp = recommender_service.ListRecommendationsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_recommendations(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + recommender_service.ListRecommendationsResponse.to_json( + response + ) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1.RecommenderClient.list_recommendations", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "ListRecommendations", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _MarkInsightAccepted( @@ -1175,7 +1520,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> insight.Insight: r"""Call the mark insight accepted method over HTTP. @@ -1185,8 +1530,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.insight.Insight: @@ -1200,6 +1547,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseMarkInsightAccepted._get_http_options() ) + request, metadata = self._interceptor.pre_mark_insight_accepted( request, metadata ) @@ -1216,6 +1564,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1.RecommenderClient.MarkInsightAccepted", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "MarkInsightAccepted", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RecommenderRestTransport._MarkInsightAccepted._get_response( self._host, @@ -1237,7 +1612,29 @@ def __call__( pb_resp = insight.Insight.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_mark_insight_accepted(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = insight.Insight.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1.RecommenderClient.mark_insight_accepted", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "MarkInsightAccepted", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _MarkRecommendationClaimed( @@ -1276,7 +1673,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Call the mark recommendation claimed method over HTTP. @@ -1287,8 +1684,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.recommendation.Recommendation: @@ -1302,6 +1701,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseMarkRecommendationClaimed._get_http_options() ) + request, metadata = self._interceptor.pre_mark_recommendation_claimed( request, metadata ) @@ -1318,6 +1718,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1.RecommenderClient.MarkRecommendationClaimed", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "MarkRecommendationClaimed", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( RecommenderRestTransport._MarkRecommendationClaimed._get_response( @@ -1341,7 +1768,29 @@ def __call__( pb_resp = recommendation.Recommendation.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_mark_recommendation_claimed(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = recommendation.Recommendation.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1.RecommenderClient.mark_recommendation_claimed", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "MarkRecommendationClaimed", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _MarkRecommendationDismissed( @@ -1380,7 +1829,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Call the mark recommendation dismissed method over HTTP. @@ -1391,8 +1840,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.recommendation.Recommendation: @@ -1406,6 +1857,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseMarkRecommendationDismissed._get_http_options() ) + request, metadata = self._interceptor.pre_mark_recommendation_dismissed( request, metadata ) @@ -1422,6 +1874,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1.RecommenderClient.MarkRecommendationDismissed", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "MarkRecommendationDismissed", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( RecommenderRestTransport._MarkRecommendationDismissed._get_response( @@ -1445,7 +1924,29 @@ def __call__( pb_resp = recommendation.Recommendation.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_mark_recommendation_dismissed(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = recommendation.Recommendation.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1.RecommenderClient.mark_recommendation_dismissed", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "MarkRecommendationDismissed", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _MarkRecommendationFailed( @@ -1483,7 +1984,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Call the mark recommendation failed method over HTTP. @@ -1494,8 +1995,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.recommendation.Recommendation: @@ -1509,6 +2012,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseMarkRecommendationFailed._get_http_options() ) + request, metadata = self._interceptor.pre_mark_recommendation_failed( request, metadata ) @@ -1525,6 +2029,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1.RecommenderClient.MarkRecommendationFailed", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "MarkRecommendationFailed", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RecommenderRestTransport._MarkRecommendationFailed._get_response( self._host, @@ -1546,7 +2077,29 @@ def __call__( pb_resp = recommendation.Recommendation.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_mark_recommendation_failed(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = recommendation.Recommendation.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1.RecommenderClient.mark_recommendation_failed", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "MarkRecommendationFailed", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _MarkRecommendationSucceeded( @@ -1585,7 +2138,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Call the mark recommendation succeeded method over HTTP. @@ -1596,8 +2149,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.recommendation.Recommendation: @@ -1611,6 +2166,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseMarkRecommendationSucceeded._get_http_options() ) + request, metadata = self._interceptor.pre_mark_recommendation_succeeded( request, metadata ) @@ -1627,6 +2183,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1.RecommenderClient.MarkRecommendationSucceeded", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "MarkRecommendationSucceeded", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( RecommenderRestTransport._MarkRecommendationSucceeded._get_response( @@ -1650,7 +2233,29 @@ def __call__( pb_resp = recommendation.Recommendation.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_mark_recommendation_succeeded(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = recommendation.Recommendation.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1.RecommenderClient.mark_recommendation_succeeded", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "MarkRecommendationSucceeded", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateInsightTypeConfig( @@ -1688,7 +2293,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> gcr_insight_type_config.InsightTypeConfig: r"""Call the update insight type config method over HTTP. @@ -1699,8 +2304,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.gcr_insight_type_config.InsightTypeConfig: @@ -1710,6 +2317,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseUpdateInsightTypeConfig._get_http_options() ) + request, metadata = self._interceptor.pre_update_insight_type_config( request, metadata ) @@ -1726,6 +2334,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1.RecommenderClient.UpdateInsightTypeConfig", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "UpdateInsightTypeConfig", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RecommenderRestTransport._UpdateInsightTypeConfig._get_response( self._host, @@ -1747,7 +2382,31 @@ def __call__( pb_resp = gcr_insight_type_config.InsightTypeConfig.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_insight_type_config(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + gcr_insight_type_config.InsightTypeConfig.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1.RecommenderClient.update_insight_type_config", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "UpdateInsightTypeConfig", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateRecommenderConfig( @@ -1785,7 +2444,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> gcr_recommender_config.RecommenderConfig: r"""Call the update recommender config method over HTTP. @@ -1795,8 +2454,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.gcr_recommender_config.RecommenderConfig: @@ -1806,6 +2467,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseUpdateRecommenderConfig._get_http_options() ) + request, metadata = self._interceptor.pre_update_recommender_config( request, metadata ) @@ -1822,6 +2484,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1.RecommenderClient.UpdateRecommenderConfig", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "UpdateRecommenderConfig", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RecommenderRestTransport._UpdateRecommenderConfig._get_response( self._host, @@ -1843,7 +2532,31 @@ def __call__( pb_resp = gcr_recommender_config.RecommenderConfig.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_recommender_config(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = gcr_recommender_config.RecommenderConfig.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1.RecommenderClient.update_recommender_config", + extra={ + "serviceName": "google.cloud.recommender.v1.Recommender", + "rpcName": "UpdateRecommenderConfig", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property diff --git a/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/gapic_version.py b/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/gapic_version.py index 1230672bab9e..558c8aab67c5 100644 --- a/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/gapic_version.py +++ b/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.16.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/async_client.py b/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/async_client.py index f7546402b04b..52c20f7d05b4 100644 --- a/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/async_client.py +++ b/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -64,6 +65,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, RecommenderTransport from .transports.grpc_asyncio import RecommenderGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class RecommenderAsyncClient: """Provides insights and recommendations for cloud customers for @@ -286,6 +296,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.recommender_v1beta1.RecommenderAsyncClient`.", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "credentialsType": None, + }, + ) + async def list_insights( self, request: Optional[Union[recommender_service.ListInsightsRequest, dict]] = None, @@ -293,7 +325,7 @@ async def list_insights( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListInsightsAsyncPager: r"""Lists insights for the specified Cloud Resource. Requires the recommender.*.list IAM permission for the specified insight @@ -354,8 +386,10 @@ async def sample_list_insights(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.services.recommender.pagers.ListInsightsAsyncPager: @@ -429,7 +463,7 @@ async def get_insight( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> insight.Insight: r"""Gets the requested insight. Requires the recommender.*.get IAM permission for the specified insight type. @@ -471,8 +505,10 @@ async def sample_get_insight(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.types.Insight: @@ -539,7 +575,7 @@ async def mark_insight_accepted( etag: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> insight.Insight: r"""Marks the Insight State as Accepted. Users can use this method to indicate to the Recommender API that they have applied some @@ -602,8 +638,10 @@ async def sample_mark_insight_accepted(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.types.Insight: @@ -674,7 +712,7 @@ async def list_recommendations( filter: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListRecommendationsAsyncPager: r"""Lists recommendations for the specified Cloud Resource. Requires the recommender.*.list IAM permission for the specified @@ -761,8 +799,10 @@ async def sample_list_recommendations(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.services.recommender.pagers.ListRecommendationsAsyncPager: @@ -840,7 +880,7 @@ async def get_recommendation( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Gets the requested recommendation. Requires the recommender.*.get IAM permission for the specified recommender. @@ -882,8 +922,10 @@ async def sample_get_recommendation(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.types.Recommendation: @@ -950,7 +992,7 @@ async def mark_recommendation_claimed( etag: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Marks the Recommendation State as Claimed. Users can use this method to indicate to the Recommender API that they are starting @@ -1019,8 +1061,10 @@ async def sample_mark_recommendation_claimed(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.types.Recommendation: @@ -1094,7 +1138,7 @@ async def mark_recommendation_succeeded( etag: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Marks the Recommendation State as Succeeded. Users can use this method to indicate to the Recommender API that they have applied @@ -1163,8 +1207,10 @@ async def sample_mark_recommendation_succeeded(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.types.Recommendation: @@ -1238,7 +1284,7 @@ async def mark_recommendation_failed( etag: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Marks the Recommendation State as Failed. Users can use this method to indicate to the Recommender API that they have applied @@ -1307,8 +1353,10 @@ async def sample_mark_recommendation_failed(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.types.Recommendation: @@ -1378,7 +1426,7 @@ async def get_recommender_config( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommender_config.RecommenderConfig: r"""Gets the requested Recommender Config. There is only one instance of the config for each Recommender. @@ -1429,8 +1477,10 @@ async def sample_get_recommender_config(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.types.RecommenderConfig: @@ -1492,7 +1542,7 @@ async def update_recommender_config( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> gcr_recommender_config.RecommenderConfig: r"""Updates a Recommender Config. This will create a new revision of the config. @@ -1540,8 +1590,10 @@ async def sample_update_recommender_config(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.types.RecommenderConfig: @@ -1606,7 +1658,7 @@ async def get_insight_type_config( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> insight_type_config.InsightTypeConfig: r"""Gets the requested InsightTypeConfig. There is only one instance of the config for each InsightType. @@ -1657,8 +1709,10 @@ async def sample_get_insight_type_config(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.types.InsightTypeConfig: @@ -1720,7 +1774,7 @@ async def update_insight_type_config( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> gcr_insight_type_config.InsightTypeConfig: r"""Updates an InsightTypeConfig change. This will create a new revision of the config. @@ -1768,8 +1822,10 @@ async def sample_update_insight_type_config(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.types.InsightTypeConfig: @@ -1833,7 +1889,7 @@ async def list_recommenders( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListRecommendersAsyncPager: r"""Lists all available Recommenders. No IAM permissions are required. @@ -1870,8 +1926,10 @@ async def sample_list_recommenders(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.services.recommender.pagers.ListRecommendersAsyncPager: @@ -1926,7 +1984,7 @@ async def list_insight_types( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListInsightTypesAsyncPager: r"""Lists available InsightTypes. No IAM permissions are required. @@ -1963,8 +2021,10 @@ async def sample_list_insight_types(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.services.recommender.pagers.ListInsightTypesAsyncPager: diff --git a/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/client.py b/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/client.py index 983ea9c9bb2b..611392db7047 100644 --- a/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/client.py +++ b/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.protobuf import duration_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore @@ -712,6 +722,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -774,6 +788,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.recommender_v1beta1.RecommenderClient`.", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "credentialsType": None, + }, + ) + def list_insights( self, request: Optional[Union[recommender_service.ListInsightsRequest, dict]] = None, @@ -781,7 +818,7 @@ def list_insights( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListInsightsPager: r"""Lists insights for the specified Cloud Resource. Requires the recommender.*.list IAM permission for the specified insight @@ -842,8 +879,10 @@ def sample_list_insights(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.services.recommender.pagers.ListInsightsPager: @@ -914,7 +953,7 @@ def get_insight( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> insight.Insight: r"""Gets the requested insight. Requires the recommender.*.get IAM permission for the specified insight type. @@ -956,8 +995,10 @@ def sample_get_insight(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.types.Insight: @@ -1021,7 +1062,7 @@ def mark_insight_accepted( etag: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> insight.Insight: r"""Marks the Insight State as Accepted. Users can use this method to indicate to the Recommender API that they have applied some @@ -1084,8 +1125,10 @@ def sample_mark_insight_accepted(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.types.Insight: @@ -1152,7 +1195,7 @@ def list_recommendations( filter: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListRecommendationsPager: r"""Lists recommendations for the specified Cloud Resource. Requires the recommender.*.list IAM permission for the specified @@ -1239,8 +1282,10 @@ def sample_list_recommendations(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.services.recommender.pagers.ListRecommendationsPager: @@ -1315,7 +1360,7 @@ def get_recommendation( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Gets the requested recommendation. Requires the recommender.*.get IAM permission for the specified recommender. @@ -1357,8 +1402,10 @@ def sample_get_recommendation(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.types.Recommendation: @@ -1422,7 +1469,7 @@ def mark_recommendation_claimed( etag: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Marks the Recommendation State as Claimed. Users can use this method to indicate to the Recommender API that they are starting @@ -1491,8 +1538,10 @@ def sample_mark_recommendation_claimed(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.types.Recommendation: @@ -1564,7 +1613,7 @@ def mark_recommendation_succeeded( etag: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Marks the Recommendation State as Succeeded. Users can use this method to indicate to the Recommender API that they have applied @@ -1633,8 +1682,10 @@ def sample_mark_recommendation_succeeded(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.types.Recommendation: @@ -1706,7 +1757,7 @@ def mark_recommendation_failed( etag: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Marks the Recommendation State as Failed. Users can use this method to indicate to the Recommender API that they have applied @@ -1775,8 +1826,10 @@ def sample_mark_recommendation_failed(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.types.Recommendation: @@ -1844,7 +1897,7 @@ def get_recommender_config( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommender_config.RecommenderConfig: r"""Gets the requested Recommender Config. There is only one instance of the config for each Recommender. @@ -1895,8 +1948,10 @@ def sample_get_recommender_config(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.types.RecommenderConfig: @@ -1955,7 +2010,7 @@ def update_recommender_config( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> gcr_recommender_config.RecommenderConfig: r"""Updates a Recommender Config. This will create a new revision of the config. @@ -2003,8 +2058,10 @@ def sample_update_recommender_config(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.types.RecommenderConfig: @@ -2068,7 +2125,7 @@ def get_insight_type_config( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> insight_type_config.InsightTypeConfig: r"""Gets the requested InsightTypeConfig. There is only one instance of the config for each InsightType. @@ -2119,8 +2176,10 @@ def sample_get_insight_type_config(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.types.InsightTypeConfig: @@ -2179,7 +2238,7 @@ def update_insight_type_config( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> gcr_insight_type_config.InsightTypeConfig: r"""Updates an InsightTypeConfig change. This will create a new revision of the config. @@ -2227,8 +2286,10 @@ def sample_update_insight_type_config(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.types.InsightTypeConfig: @@ -2291,7 +2352,7 @@ def list_recommenders( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListRecommendersPager: r"""Lists all available Recommenders. No IAM permissions are required. @@ -2328,8 +2389,10 @@ def sample_list_recommenders(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.services.recommender.pagers.ListRecommendersPager: @@ -2382,7 +2445,7 @@ def list_insight_types( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListInsightTypesPager: r"""Lists available InsightTypes. No IAM permissions are required. @@ -2419,8 +2482,10 @@ def sample_list_insight_types(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.recommender_v1beta1.services.recommender.pagers.ListInsightTypesPager: diff --git a/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/pagers.py b/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/pagers.py index 92bfd5756b95..951eb50ab9b2 100644 --- a/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/pagers.py +++ b/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/pagers.py @@ -71,7 +71,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -85,8 +85,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recommender_service.ListInsightsRequest(request) @@ -145,7 +147,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -159,8 +161,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recommender_service.ListInsightsRequest(request) @@ -223,7 +227,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -237,8 +241,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recommender_service.ListRecommendationsRequest(request) @@ -299,7 +305,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -313,8 +319,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recommender_service.ListRecommendationsRequest(request) @@ -379,7 +387,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -393,8 +401,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recommender_service.ListRecommendersRequest(request) @@ -453,7 +463,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -467,8 +477,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recommender_service.ListRecommendersRequest(request) @@ -533,7 +545,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -547,8 +559,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recommender_service.ListInsightTypesRequest(request) @@ -607,7 +621,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -621,8 +635,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = recommender_service.ListInsightTypesRequest(request) diff --git a/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/transports/grpc.py b/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/transports/grpc.py index 2fa1f60fe5ff..7b0058c552bf 100644 --- a/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/transports/grpc.py +++ b/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -20,7 +23,10 @@ import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.recommender_v1beta1.types import ( insight_type_config as gcr_insight_type_config, @@ -36,6 +42,81 @@ from .base import DEFAULT_CLIENT_INFO, RecommenderTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class RecommenderGrpcTransport(RecommenderTransport): """gRPC backend transport for Recommender. @@ -193,7 +274,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -272,7 +358,7 @@ def list_insights( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_insights" not in self._stubs: - self._stubs["list_insights"] = self.grpc_channel.unary_unary( + self._stubs["list_insights"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/ListInsights", request_serializer=recommender_service.ListInsightsRequest.serialize, response_deserializer=recommender_service.ListInsightsResponse.deserialize, @@ -299,7 +385,7 @@ def get_insight( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_insight" not in self._stubs: - self._stubs["get_insight"] = self.grpc_channel.unary_unary( + self._stubs["get_insight"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/GetInsight", request_serializer=recommender_service.GetInsightRequest.serialize, response_deserializer=insight.Insight.deserialize, @@ -332,7 +418,7 @@ def mark_insight_accepted( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "mark_insight_accepted" not in self._stubs: - self._stubs["mark_insight_accepted"] = self.grpc_channel.unary_unary( + self._stubs["mark_insight_accepted"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/MarkInsightAccepted", request_serializer=recommender_service.MarkInsightAcceptedRequest.serialize, response_deserializer=insight.Insight.deserialize, @@ -363,7 +449,7 @@ def list_recommendations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_recommendations" not in self._stubs: - self._stubs["list_recommendations"] = self.grpc_channel.unary_unary( + self._stubs["list_recommendations"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/ListRecommendations", request_serializer=recommender_service.ListRecommendationsRequest.serialize, response_deserializer=recommender_service.ListRecommendationsResponse.deserialize, @@ -392,7 +478,7 @@ def get_recommendation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_recommendation" not in self._stubs: - self._stubs["get_recommendation"] = self.grpc_channel.unary_unary( + self._stubs["get_recommendation"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/GetRecommendation", request_serializer=recommender_service.GetRecommendationRequest.serialize, response_deserializer=recommendation.Recommendation.deserialize, @@ -431,7 +517,9 @@ def mark_recommendation_claimed( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "mark_recommendation_claimed" not in self._stubs: - self._stubs["mark_recommendation_claimed"] = self.grpc_channel.unary_unary( + self._stubs[ + "mark_recommendation_claimed" + ] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/MarkRecommendationClaimed", request_serializer=recommender_service.MarkRecommendationClaimedRequest.serialize, response_deserializer=recommendation.Recommendation.deserialize, @@ -472,7 +560,7 @@ def mark_recommendation_succeeded( if "mark_recommendation_succeeded" not in self._stubs: self._stubs[ "mark_recommendation_succeeded" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/MarkRecommendationSucceeded", request_serializer=recommender_service.MarkRecommendationSucceededRequest.serialize, response_deserializer=recommendation.Recommendation.deserialize, @@ -511,7 +599,9 @@ def mark_recommendation_failed( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "mark_recommendation_failed" not in self._stubs: - self._stubs["mark_recommendation_failed"] = self.grpc_channel.unary_unary( + self._stubs[ + "mark_recommendation_failed" + ] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/MarkRecommendationFailed", request_serializer=recommender_service.MarkRecommendationFailedRequest.serialize, response_deserializer=recommendation.Recommendation.deserialize, @@ -541,7 +631,7 @@ def get_recommender_config( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_recommender_config" not in self._stubs: - self._stubs["get_recommender_config"] = self.grpc_channel.unary_unary( + self._stubs["get_recommender_config"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/GetRecommenderConfig", request_serializer=recommender_service.GetRecommenderConfigRequest.serialize, response_deserializer=recommender_config.RecommenderConfig.deserialize, @@ -571,7 +661,7 @@ def update_recommender_config( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_recommender_config" not in self._stubs: - self._stubs["update_recommender_config"] = self.grpc_channel.unary_unary( + self._stubs["update_recommender_config"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/UpdateRecommenderConfig", request_serializer=recommender_service.UpdateRecommenderConfigRequest.serialize, response_deserializer=gcr_recommender_config.RecommenderConfig.deserialize, @@ -601,7 +691,7 @@ def get_insight_type_config( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_insight_type_config" not in self._stubs: - self._stubs["get_insight_type_config"] = self.grpc_channel.unary_unary( + self._stubs["get_insight_type_config"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/GetInsightTypeConfig", request_serializer=recommender_service.GetInsightTypeConfigRequest.serialize, response_deserializer=insight_type_config.InsightTypeConfig.deserialize, @@ -631,7 +721,9 @@ def update_insight_type_config( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_insight_type_config" not in self._stubs: - self._stubs["update_insight_type_config"] = self.grpc_channel.unary_unary( + self._stubs[ + "update_insight_type_config" + ] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/UpdateInsightTypeConfig", request_serializer=recommender_service.UpdateInsightTypeConfigRequest.serialize, response_deserializer=gcr_insight_type_config.InsightTypeConfig.deserialize, @@ -661,7 +753,7 @@ def list_recommenders( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_recommenders" not in self._stubs: - self._stubs["list_recommenders"] = self.grpc_channel.unary_unary( + self._stubs["list_recommenders"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/ListRecommenders", request_serializer=recommender_service.ListRecommendersRequest.serialize, response_deserializer=recommender_service.ListRecommendersResponse.deserialize, @@ -691,7 +783,7 @@ def list_insight_types( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_insight_types" not in self._stubs: - self._stubs["list_insight_types"] = self.grpc_channel.unary_unary( + self._stubs["list_insight_types"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/ListInsightTypes", request_serializer=recommender_service.ListInsightTypesRequest.serialize, response_deserializer=recommender_service.ListInsightTypesResponse.deserialize, @@ -699,7 +791,7 @@ def list_insight_types( return self._stubs["list_insight_types"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/transports/grpc_asyncio.py b/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/transports/grpc_asyncio.py index c3d1f32f3027..cdbd77549166 100644 --- a/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/transports/grpc_asyncio.py +++ b/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -22,8 +25,11 @@ from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.recommender_v1beta1.types import ( insight_type_config as gcr_insight_type_config, @@ -40,6 +46,82 @@ from .base import DEFAULT_CLIENT_INFO, RecommenderTransport from .grpc import RecommenderGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class RecommenderGrpcAsyncIOTransport(RecommenderTransport): """gRPC AsyncIO backend transport for Recommender. @@ -240,10 +322,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -280,7 +365,7 @@ def list_insights( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_insights" not in self._stubs: - self._stubs["list_insights"] = self.grpc_channel.unary_unary( + self._stubs["list_insights"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/ListInsights", request_serializer=recommender_service.ListInsightsRequest.serialize, response_deserializer=recommender_service.ListInsightsResponse.deserialize, @@ -307,7 +392,7 @@ def get_insight( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_insight" not in self._stubs: - self._stubs["get_insight"] = self.grpc_channel.unary_unary( + self._stubs["get_insight"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/GetInsight", request_serializer=recommender_service.GetInsightRequest.serialize, response_deserializer=insight.Insight.deserialize, @@ -342,7 +427,7 @@ def mark_insight_accepted( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "mark_insight_accepted" not in self._stubs: - self._stubs["mark_insight_accepted"] = self.grpc_channel.unary_unary( + self._stubs["mark_insight_accepted"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/MarkInsightAccepted", request_serializer=recommender_service.MarkInsightAcceptedRequest.serialize, response_deserializer=insight.Insight.deserialize, @@ -373,7 +458,7 @@ def list_recommendations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_recommendations" not in self._stubs: - self._stubs["list_recommendations"] = self.grpc_channel.unary_unary( + self._stubs["list_recommendations"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/ListRecommendations", request_serializer=recommender_service.ListRecommendationsRequest.serialize, response_deserializer=recommender_service.ListRecommendationsResponse.deserialize, @@ -403,7 +488,7 @@ def get_recommendation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_recommendation" not in self._stubs: - self._stubs["get_recommendation"] = self.grpc_channel.unary_unary( + self._stubs["get_recommendation"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/GetRecommendation", request_serializer=recommender_service.GetRecommendationRequest.serialize, response_deserializer=recommendation.Recommendation.deserialize, @@ -442,7 +527,9 @@ def mark_recommendation_claimed( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "mark_recommendation_claimed" not in self._stubs: - self._stubs["mark_recommendation_claimed"] = self.grpc_channel.unary_unary( + self._stubs[ + "mark_recommendation_claimed" + ] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/MarkRecommendationClaimed", request_serializer=recommender_service.MarkRecommendationClaimedRequest.serialize, response_deserializer=recommendation.Recommendation.deserialize, @@ -483,7 +570,7 @@ def mark_recommendation_succeeded( if "mark_recommendation_succeeded" not in self._stubs: self._stubs[ "mark_recommendation_succeeded" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/MarkRecommendationSucceeded", request_serializer=recommender_service.MarkRecommendationSucceededRequest.serialize, response_deserializer=recommendation.Recommendation.deserialize, @@ -522,7 +609,9 @@ def mark_recommendation_failed( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "mark_recommendation_failed" not in self._stubs: - self._stubs["mark_recommendation_failed"] = self.grpc_channel.unary_unary( + self._stubs[ + "mark_recommendation_failed" + ] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/MarkRecommendationFailed", request_serializer=recommender_service.MarkRecommendationFailedRequest.serialize, response_deserializer=recommendation.Recommendation.deserialize, @@ -552,7 +641,7 @@ def get_recommender_config( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_recommender_config" not in self._stubs: - self._stubs["get_recommender_config"] = self.grpc_channel.unary_unary( + self._stubs["get_recommender_config"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/GetRecommenderConfig", request_serializer=recommender_service.GetRecommenderConfigRequest.serialize, response_deserializer=recommender_config.RecommenderConfig.deserialize, @@ -582,7 +671,7 @@ def update_recommender_config( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_recommender_config" not in self._stubs: - self._stubs["update_recommender_config"] = self.grpc_channel.unary_unary( + self._stubs["update_recommender_config"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/UpdateRecommenderConfig", request_serializer=recommender_service.UpdateRecommenderConfigRequest.serialize, response_deserializer=gcr_recommender_config.RecommenderConfig.deserialize, @@ -612,7 +701,7 @@ def get_insight_type_config( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_insight_type_config" not in self._stubs: - self._stubs["get_insight_type_config"] = self.grpc_channel.unary_unary( + self._stubs["get_insight_type_config"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/GetInsightTypeConfig", request_serializer=recommender_service.GetInsightTypeConfigRequest.serialize, response_deserializer=insight_type_config.InsightTypeConfig.deserialize, @@ -642,7 +731,9 @@ def update_insight_type_config( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_insight_type_config" not in self._stubs: - self._stubs["update_insight_type_config"] = self.grpc_channel.unary_unary( + self._stubs[ + "update_insight_type_config" + ] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/UpdateInsightTypeConfig", request_serializer=recommender_service.UpdateInsightTypeConfigRequest.serialize, response_deserializer=gcr_insight_type_config.InsightTypeConfig.deserialize, @@ -672,7 +763,7 @@ def list_recommenders( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_recommenders" not in self._stubs: - self._stubs["list_recommenders"] = self.grpc_channel.unary_unary( + self._stubs["list_recommenders"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/ListRecommenders", request_serializer=recommender_service.ListRecommendersRequest.serialize, response_deserializer=recommender_service.ListRecommendersResponse.deserialize, @@ -702,7 +793,7 @@ def list_insight_types( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_insight_types" not in self._stubs: - self._stubs["list_insight_types"] = self.grpc_channel.unary_unary( + self._stubs["list_insight_types"] = self._logged_channel.unary_unary( "/google.cloud.recommender.v1beta1.Recommender/ListInsightTypes", request_serializer=recommender_service.ListInsightTypesRequest.serialize, response_deserializer=recommender_service.ListInsightTypesResponse.deserialize, @@ -830,7 +921,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/transports/rest.py b/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/transports/rest.py index 67ca1b6a737f..8d6380149d10 100644 --- a/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/transports/rest.py +++ b/packages/google-cloud-recommender/google/cloud/recommender_v1beta1/services/recommender/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -47,6 +47,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -191,8 +199,10 @@ def post_update_recommender_config(self, response): def pre_get_insight( self, request: recommender_service.GetInsightRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[recommender_service.GetInsightRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + recommender_service.GetInsightRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_insight Override in a subclass to manipulate the request or metadata @@ -212,9 +222,10 @@ def post_get_insight(self, response: insight.Insight) -> insight.Insight: def pre_get_insight_type_config( self, request: recommender_service.GetInsightTypeConfigRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - recommender_service.GetInsightTypeConfigRequest, Sequence[Tuple[str, str]] + recommender_service.GetInsightTypeConfigRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for get_insight_type_config @@ -237,8 +248,11 @@ def post_get_insight_type_config( def pre_get_recommendation( self, request: recommender_service.GetRecommendationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[recommender_service.GetRecommendationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + recommender_service.GetRecommendationRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for get_recommendation Override in a subclass to manipulate the request or metadata @@ -260,9 +274,10 @@ def post_get_recommendation( def pre_get_recommender_config( self, request: recommender_service.GetRecommenderConfigRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - recommender_service.GetRecommenderConfigRequest, Sequence[Tuple[str, str]] + recommender_service.GetRecommenderConfigRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for get_recommender_config @@ -285,8 +300,10 @@ def post_get_recommender_config( def pre_list_insights( self, request: recommender_service.ListInsightsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[recommender_service.ListInsightsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + recommender_service.ListInsightsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_insights Override in a subclass to manipulate the request or metadata @@ -308,8 +325,11 @@ def post_list_insights( def pre_list_insight_types( self, request: recommender_service.ListInsightTypesRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[recommender_service.ListInsightTypesRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + recommender_service.ListInsightTypesRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for list_insight_types Override in a subclass to manipulate the request or metadata @@ -331,9 +351,10 @@ def post_list_insight_types( def pre_list_recommendations( self, request: recommender_service.ListRecommendationsRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - recommender_service.ListRecommendationsRequest, Sequence[Tuple[str, str]] + recommender_service.ListRecommendationsRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for list_recommendations @@ -356,8 +377,11 @@ def post_list_recommendations( def pre_list_recommenders( self, request: recommender_service.ListRecommendersRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[recommender_service.ListRecommendersRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + recommender_service.ListRecommendersRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for list_recommenders Override in a subclass to manipulate the request or metadata @@ -379,9 +403,10 @@ def post_list_recommenders( def pre_mark_insight_accepted( self, request: recommender_service.MarkInsightAcceptedRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - recommender_service.MarkInsightAcceptedRequest, Sequence[Tuple[str, str]] + recommender_service.MarkInsightAcceptedRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for mark_insight_accepted @@ -402,9 +427,10 @@ def post_mark_insight_accepted(self, response: insight.Insight) -> insight.Insig def pre_mark_recommendation_claimed( self, request: recommender_service.MarkRecommendationClaimedRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - recommender_service.MarkRecommendationClaimedRequest, Sequence[Tuple[str, str]] + recommender_service.MarkRecommendationClaimedRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for mark_recommendation_claimed @@ -427,9 +453,10 @@ def post_mark_recommendation_claimed( def pre_mark_recommendation_failed( self, request: recommender_service.MarkRecommendationFailedRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - recommender_service.MarkRecommendationFailedRequest, Sequence[Tuple[str, str]] + recommender_service.MarkRecommendationFailedRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for mark_recommendation_failed @@ -452,10 +479,10 @@ def post_mark_recommendation_failed( def pre_mark_recommendation_succeeded( self, request: recommender_service.MarkRecommendationSucceededRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ recommender_service.MarkRecommendationSucceededRequest, - Sequence[Tuple[str, str]], + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for mark_recommendation_succeeded @@ -478,9 +505,10 @@ def post_mark_recommendation_succeeded( def pre_update_insight_type_config( self, request: recommender_service.UpdateInsightTypeConfigRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - recommender_service.UpdateInsightTypeConfigRequest, Sequence[Tuple[str, str]] + recommender_service.UpdateInsightTypeConfigRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for update_insight_type_config @@ -503,9 +531,10 @@ def post_update_insight_type_config( def pre_update_recommender_config( self, request: recommender_service.UpdateRecommenderConfigRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - recommender_service.UpdateRecommenderConfigRequest, Sequence[Tuple[str, str]] + recommender_service.UpdateRecommenderConfigRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for update_recommender_config @@ -650,7 +679,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> insight.Insight: r"""Call the get insight method over HTTP. @@ -660,8 +689,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.insight.Insight: @@ -675,6 +706,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseGetInsight._get_http_options() ) + request, metadata = self._interceptor.pre_get_insight(request, metadata) transcoded_request = ( _BaseRecommenderRestTransport._BaseGetInsight._get_transcoded_request( @@ -689,6 +721,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1beta1.RecommenderClient.GetInsight", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "GetInsight", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RecommenderRestTransport._GetInsight._get_response( self._host, @@ -709,7 +768,29 @@ def __call__( pb_resp = insight.Insight.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_insight(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = insight.Insight.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1beta1.RecommenderClient.get_insight", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "GetInsight", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetInsightTypeConfig( @@ -746,7 +827,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> insight_type_config.InsightTypeConfig: r"""Call the get insight type config method over HTTP. @@ -756,8 +837,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.insight_type_config.InsightTypeConfig: @@ -767,6 +850,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseGetInsightTypeConfig._get_http_options() ) + request, metadata = self._interceptor.pre_get_insight_type_config( request, metadata ) @@ -779,6 +863,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1beta1.RecommenderClient.GetInsightTypeConfig", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "GetInsightTypeConfig", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RecommenderRestTransport._GetInsightTypeConfig._get_response( self._host, @@ -799,7 +910,31 @@ def __call__( pb_resp = insight_type_config.InsightTypeConfig.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_insight_type_config(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = insight_type_config.InsightTypeConfig.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1beta1.RecommenderClient.get_insight_type_config", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "GetInsightTypeConfig", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetRecommendation( @@ -836,7 +971,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Call the get recommendation method over HTTP. @@ -846,8 +981,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.recommendation.Recommendation: @@ -861,6 +998,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseGetRecommendation._get_http_options() ) + request, metadata = self._interceptor.pre_get_recommendation( request, metadata ) @@ -873,6 +1011,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1beta1.RecommenderClient.GetRecommendation", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "GetRecommendation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RecommenderRestTransport._GetRecommendation._get_response( self._host, @@ -893,7 +1058,29 @@ def __call__( pb_resp = recommendation.Recommendation.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_recommendation(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = recommendation.Recommendation.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1beta1.RecommenderClient.get_recommendation", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "GetRecommendation", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetRecommenderConfig( @@ -930,7 +1117,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommender_config.RecommenderConfig: r"""Call the get recommender config method over HTTP. @@ -940,8 +1127,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.recommender_config.RecommenderConfig: @@ -951,6 +1140,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseGetRecommenderConfig._get_http_options() ) + request, metadata = self._interceptor.pre_get_recommender_config( request, metadata ) @@ -963,6 +1153,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1beta1.RecommenderClient.GetRecommenderConfig", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "GetRecommenderConfig", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RecommenderRestTransport._GetRecommenderConfig._get_response( self._host, @@ -983,7 +1200,31 @@ def __call__( pb_resp = recommender_config.RecommenderConfig.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_recommender_config(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = recommender_config.RecommenderConfig.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1beta1.RecommenderClient.get_recommender_config", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "GetRecommenderConfig", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListInsights( @@ -1020,7 +1261,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommender_service.ListInsightsResponse: r"""Call the list insights method over HTTP. @@ -1030,8 +1271,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.recommender_service.ListInsightsResponse: @@ -1041,6 +1284,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseListInsights._get_http_options() ) + request, metadata = self._interceptor.pre_list_insights(request, metadata) transcoded_request = ( _BaseRecommenderRestTransport._BaseListInsights._get_transcoded_request( @@ -1055,6 +1299,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1beta1.RecommenderClient.ListInsights", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "ListInsights", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RecommenderRestTransport._ListInsights._get_response( self._host, @@ -1075,7 +1346,31 @@ def __call__( pb_resp = recommender_service.ListInsightsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_insights(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = recommender_service.ListInsightsResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1beta1.RecommenderClient.list_insights", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "ListInsights", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListInsightTypes( @@ -1112,7 +1407,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommender_service.ListInsightTypesResponse: r"""Call the list insight types method over HTTP. @@ -1122,8 +1417,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.recommender_service.ListInsightTypesResponse: @@ -1133,6 +1430,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseListInsightTypes._get_http_options() ) + request, metadata = self._interceptor.pre_list_insight_types( request, metadata ) @@ -1145,6 +1443,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1beta1.RecommenderClient.ListInsightTypes", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "ListInsightTypes", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RecommenderRestTransport._ListInsightTypes._get_response( self._host, @@ -1165,7 +1490,31 @@ def __call__( pb_resp = recommender_service.ListInsightTypesResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_insight_types(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + recommender_service.ListInsightTypesResponse.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1beta1.RecommenderClient.list_insight_types", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "ListInsightTypes", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListRecommendations( @@ -1202,7 +1551,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommender_service.ListRecommendationsResponse: r"""Call the list recommendations method over HTTP. @@ -1212,8 +1561,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.recommender_service.ListRecommendationsResponse: @@ -1223,6 +1574,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseListRecommendations._get_http_options() ) + request, metadata = self._interceptor.pre_list_recommendations( request, metadata ) @@ -1235,6 +1587,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1beta1.RecommenderClient.ListRecommendations", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "ListRecommendations", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RecommenderRestTransport._ListRecommendations._get_response( self._host, @@ -1255,7 +1634,33 @@ def __call__( pb_resp = recommender_service.ListRecommendationsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_recommendations(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + recommender_service.ListRecommendationsResponse.to_json( + response + ) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1beta1.RecommenderClient.list_recommendations", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "ListRecommendations", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListRecommenders( @@ -1292,7 +1697,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommender_service.ListRecommendersResponse: r"""Call the list recommenders method over HTTP. @@ -1302,8 +1707,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.recommender_service.ListRecommendersResponse: @@ -1313,6 +1720,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseListRecommenders._get_http_options() ) + request, metadata = self._interceptor.pre_list_recommenders( request, metadata ) @@ -1325,6 +1733,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1beta1.RecommenderClient.ListRecommenders", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "ListRecommenders", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RecommenderRestTransport._ListRecommenders._get_response( self._host, @@ -1345,7 +1780,31 @@ def __call__( pb_resp = recommender_service.ListRecommendersResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_recommenders(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + recommender_service.ListRecommendersResponse.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1beta1.RecommenderClient.list_recommenders", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "ListRecommenders", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _MarkInsightAccepted( @@ -1383,7 +1842,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> insight.Insight: r"""Call the mark insight accepted method over HTTP. @@ -1393,8 +1852,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.insight.Insight: @@ -1408,6 +1869,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseMarkInsightAccepted._get_http_options() ) + request, metadata = self._interceptor.pre_mark_insight_accepted( request, metadata ) @@ -1424,6 +1886,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1beta1.RecommenderClient.MarkInsightAccepted", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "MarkInsightAccepted", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RecommenderRestTransport._MarkInsightAccepted._get_response( self._host, @@ -1445,7 +1934,29 @@ def __call__( pb_resp = insight.Insight.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_mark_insight_accepted(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = insight.Insight.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1beta1.RecommenderClient.mark_insight_accepted", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "MarkInsightAccepted", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _MarkRecommendationClaimed( @@ -1484,7 +1995,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Call the mark recommendation claimed method over HTTP. @@ -1495,8 +2006,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.recommendation.Recommendation: @@ -1510,6 +2023,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseMarkRecommendationClaimed._get_http_options() ) + request, metadata = self._interceptor.pre_mark_recommendation_claimed( request, metadata ) @@ -1526,6 +2040,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1beta1.RecommenderClient.MarkRecommendationClaimed", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "MarkRecommendationClaimed", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( RecommenderRestTransport._MarkRecommendationClaimed._get_response( @@ -1549,7 +2090,29 @@ def __call__( pb_resp = recommendation.Recommendation.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_mark_recommendation_claimed(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = recommendation.Recommendation.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1beta1.RecommenderClient.mark_recommendation_claimed", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "MarkRecommendationClaimed", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _MarkRecommendationFailed( @@ -1587,7 +2150,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Call the mark recommendation failed method over HTTP. @@ -1598,8 +2161,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.recommendation.Recommendation: @@ -1613,6 +2178,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseMarkRecommendationFailed._get_http_options() ) + request, metadata = self._interceptor.pre_mark_recommendation_failed( request, metadata ) @@ -1629,6 +2195,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1beta1.RecommenderClient.MarkRecommendationFailed", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "MarkRecommendationFailed", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RecommenderRestTransport._MarkRecommendationFailed._get_response( self._host, @@ -1650,7 +2243,29 @@ def __call__( pb_resp = recommendation.Recommendation.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_mark_recommendation_failed(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = recommendation.Recommendation.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1beta1.RecommenderClient.mark_recommendation_failed", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "MarkRecommendationFailed", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _MarkRecommendationSucceeded( @@ -1689,7 +2304,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> recommendation.Recommendation: r"""Call the mark recommendation succeeded method over HTTP. @@ -1700,8 +2315,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.recommendation.Recommendation: @@ -1715,6 +2332,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseMarkRecommendationSucceeded._get_http_options() ) + request, metadata = self._interceptor.pre_mark_recommendation_succeeded( request, metadata ) @@ -1731,6 +2349,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1beta1.RecommenderClient.MarkRecommendationSucceeded", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "MarkRecommendationSucceeded", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( RecommenderRestTransport._MarkRecommendationSucceeded._get_response( @@ -1754,7 +2399,29 @@ def __call__( pb_resp = recommendation.Recommendation.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_mark_recommendation_succeeded(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = recommendation.Recommendation.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1beta1.RecommenderClient.mark_recommendation_succeeded", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "MarkRecommendationSucceeded", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateInsightTypeConfig( @@ -1792,7 +2459,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> gcr_insight_type_config.InsightTypeConfig: r"""Call the update insight type config method over HTTP. @@ -1803,8 +2470,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.gcr_insight_type_config.InsightTypeConfig: @@ -1814,6 +2483,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseUpdateInsightTypeConfig._get_http_options() ) + request, metadata = self._interceptor.pre_update_insight_type_config( request, metadata ) @@ -1830,6 +2500,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1beta1.RecommenderClient.UpdateInsightTypeConfig", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "UpdateInsightTypeConfig", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RecommenderRestTransport._UpdateInsightTypeConfig._get_response( self._host, @@ -1851,7 +2548,31 @@ def __call__( pb_resp = gcr_insight_type_config.InsightTypeConfig.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_insight_type_config(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + gcr_insight_type_config.InsightTypeConfig.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1beta1.RecommenderClient.update_insight_type_config", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "UpdateInsightTypeConfig", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateRecommenderConfig( @@ -1889,7 +2610,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> gcr_recommender_config.RecommenderConfig: r"""Call the update recommender config method over HTTP. @@ -1899,8 +2620,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.gcr_recommender_config.RecommenderConfig: @@ -1910,6 +2633,7 @@ def __call__( http_options = ( _BaseRecommenderRestTransport._BaseUpdateRecommenderConfig._get_http_options() ) + request, metadata = self._interceptor.pre_update_recommender_config( request, metadata ) @@ -1926,6 +2650,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.recommender_v1beta1.RecommenderClient.UpdateRecommenderConfig", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "UpdateRecommenderConfig", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = RecommenderRestTransport._UpdateRecommenderConfig._get_response( self._host, @@ -1947,7 +2698,31 @@ def __call__( pb_resp = gcr_recommender_config.RecommenderConfig.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_recommender_config(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = gcr_recommender_config.RecommenderConfig.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.recommender_v1beta1.RecommenderClient.update_recommender_config", + extra={ + "serviceName": "google.cloud.recommender.v1beta1.Recommender", + "rpcName": "UpdateRecommenderConfig", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property diff --git a/packages/google-cloud-recommender/samples/generated_samples/snippet_metadata_google.cloud.recommender.v1.json b/packages/google-cloud-recommender/samples/generated_samples/snippet_metadata_google.cloud.recommender.v1.json index b2b87bc1bf10..3ccf1bb20a47 100644 --- a/packages/google-cloud-recommender/samples/generated_samples/snippet_metadata_google.cloud.recommender.v1.json +++ b/packages/google-cloud-recommender/samples/generated_samples/snippet_metadata_google.cloud.recommender.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-recommender", - "version": "2.16.1" + "version": "0.1.0" }, "snippets": [ { @@ -47,7 +47,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.types.InsightTypeConfig", @@ -127,7 +127,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.types.InsightTypeConfig", @@ -208,7 +208,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.types.Insight", @@ -288,7 +288,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.types.Insight", @@ -369,7 +369,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.types.Recommendation", @@ -449,7 +449,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.types.Recommendation", @@ -530,7 +530,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.types.RecommenderConfig", @@ -610,7 +610,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.types.RecommenderConfig", @@ -691,7 +691,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.services.recommender.pagers.ListInsightsAsyncPager", @@ -771,7 +771,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.services.recommender.pagers.ListInsightsPager", @@ -856,7 +856,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.services.recommender.pagers.ListRecommendationsAsyncPager", @@ -940,7 +940,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.services.recommender.pagers.ListRecommendationsPager", @@ -1029,7 +1029,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.types.Insight", @@ -1117,7 +1117,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.types.Insight", @@ -1206,7 +1206,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.types.Recommendation", @@ -1294,7 +1294,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.types.Recommendation", @@ -1371,7 +1371,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.types.Recommendation", @@ -1447,7 +1447,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.types.Recommendation", @@ -1536,7 +1536,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.types.Recommendation", @@ -1624,7 +1624,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.types.Recommendation", @@ -1713,7 +1713,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.types.Recommendation", @@ -1801,7 +1801,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.types.Recommendation", @@ -1886,7 +1886,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.types.InsightTypeConfig", @@ -1970,7 +1970,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.types.InsightTypeConfig", @@ -2055,7 +2055,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.types.RecommenderConfig", @@ -2139,7 +2139,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1.types.RecommenderConfig", diff --git a/packages/google-cloud-recommender/samples/generated_samples/snippet_metadata_google.cloud.recommender.v1beta1.json b/packages/google-cloud-recommender/samples/generated_samples/snippet_metadata_google.cloud.recommender.v1beta1.json index 46ac91fbdd72..01d4bcaa2c08 100644 --- a/packages/google-cloud-recommender/samples/generated_samples/snippet_metadata_google.cloud.recommender.v1beta1.json +++ b/packages/google-cloud-recommender/samples/generated_samples/snippet_metadata_google.cloud.recommender.v1beta1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-recommender", - "version": "2.16.1" + "version": "0.1.0" }, "snippets": [ { @@ -47,7 +47,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.types.InsightTypeConfig", @@ -127,7 +127,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.types.InsightTypeConfig", @@ -208,7 +208,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.types.Insight", @@ -288,7 +288,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.types.Insight", @@ -369,7 +369,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.types.Recommendation", @@ -449,7 +449,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.types.Recommendation", @@ -530,7 +530,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.types.RecommenderConfig", @@ -610,7 +610,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.types.RecommenderConfig", @@ -687,7 +687,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.services.recommender.pagers.ListInsightTypesAsyncPager", @@ -763,7 +763,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.services.recommender.pagers.ListInsightTypesPager", @@ -844,7 +844,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.services.recommender.pagers.ListInsightsAsyncPager", @@ -924,7 +924,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.services.recommender.pagers.ListInsightsPager", @@ -1009,7 +1009,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.services.recommender.pagers.ListRecommendationsAsyncPager", @@ -1093,7 +1093,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.services.recommender.pagers.ListRecommendationsPager", @@ -1170,7 +1170,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.services.recommender.pagers.ListRecommendersAsyncPager", @@ -1246,7 +1246,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.services.recommender.pagers.ListRecommendersPager", @@ -1335,7 +1335,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.types.Insight", @@ -1423,7 +1423,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.types.Insight", @@ -1512,7 +1512,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.types.Recommendation", @@ -1600,7 +1600,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.types.Recommendation", @@ -1689,7 +1689,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.types.Recommendation", @@ -1777,7 +1777,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.types.Recommendation", @@ -1866,7 +1866,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.types.Recommendation", @@ -1954,7 +1954,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.types.Recommendation", @@ -2039,7 +2039,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.types.InsightTypeConfig", @@ -2123,7 +2123,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.types.InsightTypeConfig", @@ -2208,7 +2208,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.types.RecommenderConfig", @@ -2292,7 +2292,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.recommender_v1beta1.types.RecommenderConfig", diff --git a/packages/google-cloud-recommender/tests/unit/gapic/recommender_v1/test_recommender.py b/packages/google-cloud-recommender/tests/unit/gapic/recommender_v1/test_recommender.py index 8555512be416..982c9ede4b09 100644 --- a/packages/google-cloud-recommender/tests/unit/gapic/recommender_v1/test_recommender.py +++ b/packages/google-cloud-recommender/tests/unit/gapic/recommender_v1/test_recommender.py @@ -6199,6 +6199,7 @@ def test_list_insights_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_insights(request) @@ -6255,6 +6256,7 @@ def test_list_insights_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_insights(**mock_args) @@ -6451,6 +6453,7 @@ def test_get_insight_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_insight(request) @@ -6498,6 +6501,7 @@ def test_get_insight_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_insight(**mock_args) @@ -6639,6 +6643,7 @@ def test_mark_insight_accepted_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.mark_insight_accepted(request) @@ -6696,6 +6701,7 @@ def test_mark_insight_accepted_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.mark_insight_accepted(**mock_args) @@ -6843,6 +6849,7 @@ def test_list_recommendations_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_recommendations(request) @@ -6900,6 +6907,7 @@ def test_list_recommendations_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_recommendations(**mock_args) @@ -7101,6 +7109,7 @@ def test_get_recommendation_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_recommendation(request) @@ -7148,6 +7157,7 @@ def test_get_recommendation_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_recommendation(**mock_args) @@ -7285,6 +7295,7 @@ def test_mark_recommendation_dismissed_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.mark_recommendation_dismissed(request) @@ -7416,6 +7427,7 @@ def test_mark_recommendation_claimed_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.mark_recommendation_claimed(request) @@ -7473,6 +7485,7 @@ def test_mark_recommendation_claimed_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.mark_recommendation_claimed(**mock_args) @@ -7616,6 +7629,7 @@ def test_mark_recommendation_succeeded_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.mark_recommendation_succeeded(request) @@ -7675,6 +7689,7 @@ def test_mark_recommendation_succeeded_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.mark_recommendation_succeeded(**mock_args) @@ -7818,6 +7833,7 @@ def test_mark_recommendation_failed_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.mark_recommendation_failed(request) @@ -7875,6 +7891,7 @@ def test_mark_recommendation_failed_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.mark_recommendation_failed(**mock_args) @@ -8013,6 +8030,7 @@ def test_get_recommender_config_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_recommender_config(request) @@ -8060,6 +8078,7 @@ def test_get_recommender_config_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_recommender_config(**mock_args) @@ -8199,6 +8218,7 @@ def test_update_recommender_config_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_recommender_config(request) @@ -8259,6 +8279,7 @@ def test_update_recommender_config_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_recommender_config(**mock_args) @@ -8398,6 +8419,7 @@ def test_get_insight_type_config_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_insight_type_config(request) @@ -8445,6 +8467,7 @@ def test_get_insight_type_config_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_insight_type_config(**mock_args) @@ -8584,6 +8607,7 @@ def test_update_insight_type_config_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_insight_type_config(request) @@ -8644,6 +8668,7 @@ def test_update_insight_type_config_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_insight_type_config(**mock_args) @@ -9541,6 +9566,7 @@ def test_list_insights_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_insights(request) @@ -9576,6 +9602,7 @@ def test_list_insights_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_insights(request) # Establish that the response is the type that we expect. @@ -9616,6 +9643,7 @@ def test_list_insights_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = recommender_service.ListInsightsResponse.to_json( recommender_service.ListInsightsResponse() ) @@ -9664,6 +9692,7 @@ def test_get_insight_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_insight(request) @@ -9707,6 +9736,7 @@ def test_get_insight_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_insight(request) # Establish that the response is the type that we expect. @@ -9753,6 +9783,7 @@ def test_get_insight_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = insight.Insight.to_json(insight.Insight()) req.return_value.content = return_value @@ -9799,6 +9830,7 @@ def test_mark_insight_accepted_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.mark_insight_accepted(request) @@ -9842,6 +9874,7 @@ def test_mark_insight_accepted_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.mark_insight_accepted(request) # Establish that the response is the type that we expect. @@ -9888,6 +9921,7 @@ def test_mark_insight_accepted_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = insight.Insight.to_json(insight.Insight()) req.return_value.content = return_value @@ -9932,6 +9966,7 @@ def test_list_recommendations_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_recommendations(request) @@ -9967,6 +10002,7 @@ def test_list_recommendations_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_recommendations(request) # Establish that the response is the type that we expect. @@ -10007,6 +10043,7 @@ def test_list_recommendations_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = recommender_service.ListRecommendationsResponse.to_json( recommender_service.ListRecommendationsResponse() ) @@ -10055,6 +10092,7 @@ def test_get_recommendation_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_recommendation(request) @@ -10097,6 +10135,7 @@ def test_get_recommendation_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_recommendation(request) # Establish that the response is the type that we expect. @@ -10142,6 +10181,7 @@ def test_get_recommendation_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = recommendation.Recommendation.to_json( recommendation.Recommendation() ) @@ -10190,6 +10230,7 @@ def test_mark_recommendation_dismissed_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.mark_recommendation_dismissed(request) @@ -10232,6 +10273,7 @@ def test_mark_recommendation_dismissed_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.mark_recommendation_dismissed(request) # Establish that the response is the type that we expect. @@ -10277,6 +10319,7 @@ def test_mark_recommendation_dismissed_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = recommendation.Recommendation.to_json( recommendation.Recommendation() ) @@ -10325,6 +10368,7 @@ def test_mark_recommendation_claimed_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.mark_recommendation_claimed(request) @@ -10367,6 +10411,7 @@ def test_mark_recommendation_claimed_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.mark_recommendation_claimed(request) # Establish that the response is the type that we expect. @@ -10412,6 +10457,7 @@ def test_mark_recommendation_claimed_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = recommendation.Recommendation.to_json( recommendation.Recommendation() ) @@ -10460,6 +10506,7 @@ def test_mark_recommendation_succeeded_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.mark_recommendation_succeeded(request) @@ -10502,6 +10549,7 @@ def test_mark_recommendation_succeeded_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.mark_recommendation_succeeded(request) # Establish that the response is the type that we expect. @@ -10547,6 +10595,7 @@ def test_mark_recommendation_succeeded_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = recommendation.Recommendation.to_json( recommendation.Recommendation() ) @@ -10595,6 +10644,7 @@ def test_mark_recommendation_failed_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.mark_recommendation_failed(request) @@ -10637,6 +10687,7 @@ def test_mark_recommendation_failed_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.mark_recommendation_failed(request) # Establish that the response is the type that we expect. @@ -10682,6 +10733,7 @@ def test_mark_recommendation_failed_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = recommendation.Recommendation.to_json( recommendation.Recommendation() ) @@ -10730,6 +10782,7 @@ def test_get_recommender_config_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_recommender_config(request) @@ -10770,6 +10823,7 @@ def test_get_recommender_config_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_recommender_config(request) # Establish that the response is the type that we expect. @@ -10813,6 +10867,7 @@ def test_get_recommender_config_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = recommender_config.RecommenderConfig.to_json( recommender_config.RecommenderConfig() ) @@ -10863,6 +10918,7 @@ def test_update_recommender_config_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_recommender_config(request) @@ -10983,6 +11039,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_recommender_config(request) # Establish that the response is the type that we expect. @@ -11026,6 +11083,7 @@ def test_update_recommender_config_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = gcr_recommender_config.RecommenderConfig.to_json( gcr_recommender_config.RecommenderConfig() ) @@ -11074,6 +11132,7 @@ def test_get_insight_type_config_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_insight_type_config(request) @@ -11114,6 +11173,7 @@ def test_get_insight_type_config_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_insight_type_config(request) # Establish that the response is the type that we expect. @@ -11157,6 +11217,7 @@ def test_get_insight_type_config_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = insight_type_config.InsightTypeConfig.to_json( insight_type_config.InsightTypeConfig() ) @@ -11207,6 +11268,7 @@ def test_update_insight_type_config_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_insight_type_config(request) @@ -11327,6 +11389,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_insight_type_config(request) # Establish that the response is the type that we expect. @@ -11370,6 +11433,7 @@ def test_update_insight_type_config_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = gcr_insight_type_config.InsightTypeConfig.to_json( gcr_insight_type_config.InsightTypeConfig() ) diff --git a/packages/google-cloud-recommender/tests/unit/gapic/recommender_v1beta1/test_recommender.py b/packages/google-cloud-recommender/tests/unit/gapic/recommender_v1beta1/test_recommender.py index 99e4cc88d75b..afac04746868 100644 --- a/packages/google-cloud-recommender/tests/unit/gapic/recommender_v1beta1/test_recommender.py +++ b/packages/google-cloud-recommender/tests/unit/gapic/recommender_v1beta1/test_recommender.py @@ -6698,6 +6698,7 @@ def test_list_insights_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_insights(request) @@ -6754,6 +6755,7 @@ def test_list_insights_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_insights(**mock_args) @@ -6950,6 +6952,7 @@ def test_get_insight_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_insight(request) @@ -6997,6 +7000,7 @@ def test_get_insight_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_insight(**mock_args) @@ -7138,6 +7142,7 @@ def test_mark_insight_accepted_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.mark_insight_accepted(request) @@ -7195,6 +7200,7 @@ def test_mark_insight_accepted_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.mark_insight_accepted(**mock_args) @@ -7342,6 +7348,7 @@ def test_list_recommendations_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_recommendations(request) @@ -7399,6 +7406,7 @@ def test_list_recommendations_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_recommendations(**mock_args) @@ -7600,6 +7608,7 @@ def test_get_recommendation_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_recommendation(request) @@ -7647,6 +7656,7 @@ def test_get_recommendation_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_recommendation(**mock_args) @@ -7788,6 +7798,7 @@ def test_mark_recommendation_claimed_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.mark_recommendation_claimed(request) @@ -7845,6 +7856,7 @@ def test_mark_recommendation_claimed_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.mark_recommendation_claimed(**mock_args) @@ -7988,6 +8000,7 @@ def test_mark_recommendation_succeeded_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.mark_recommendation_succeeded(request) @@ -8047,6 +8060,7 @@ def test_mark_recommendation_succeeded_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.mark_recommendation_succeeded(**mock_args) @@ -8190,6 +8204,7 @@ def test_mark_recommendation_failed_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.mark_recommendation_failed(request) @@ -8247,6 +8262,7 @@ def test_mark_recommendation_failed_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.mark_recommendation_failed(**mock_args) @@ -8385,6 +8401,7 @@ def test_get_recommender_config_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_recommender_config(request) @@ -8432,6 +8449,7 @@ def test_get_recommender_config_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_recommender_config(**mock_args) @@ -8571,6 +8589,7 @@ def test_update_recommender_config_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_recommender_config(request) @@ -8631,6 +8650,7 @@ def test_update_recommender_config_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_recommender_config(**mock_args) @@ -8770,6 +8790,7 @@ def test_get_insight_type_config_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_insight_type_config(request) @@ -8817,6 +8838,7 @@ def test_get_insight_type_config_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_insight_type_config(**mock_args) @@ -8956,6 +8978,7 @@ def test_update_insight_type_config_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_insight_type_config(request) @@ -9016,6 +9039,7 @@ def test_update_insight_type_config_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_insight_type_config(**mock_args) @@ -10164,6 +10188,7 @@ def test_list_insights_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_insights(request) @@ -10199,6 +10224,7 @@ def test_list_insights_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_insights(request) # Establish that the response is the type that we expect. @@ -10239,6 +10265,7 @@ def test_list_insights_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = recommender_service.ListInsightsResponse.to_json( recommender_service.ListInsightsResponse() ) @@ -10287,6 +10314,7 @@ def test_get_insight_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_insight(request) @@ -10330,6 +10358,7 @@ def test_get_insight_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_insight(request) # Establish that the response is the type that we expect. @@ -10376,6 +10405,7 @@ def test_get_insight_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = insight.Insight.to_json(insight.Insight()) req.return_value.content = return_value @@ -10422,6 +10452,7 @@ def test_mark_insight_accepted_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.mark_insight_accepted(request) @@ -10465,6 +10496,7 @@ def test_mark_insight_accepted_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.mark_insight_accepted(request) # Establish that the response is the type that we expect. @@ -10511,6 +10543,7 @@ def test_mark_insight_accepted_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = insight.Insight.to_json(insight.Insight()) req.return_value.content = return_value @@ -10555,6 +10588,7 @@ def test_list_recommendations_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_recommendations(request) @@ -10590,6 +10624,7 @@ def test_list_recommendations_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_recommendations(request) # Establish that the response is the type that we expect. @@ -10630,6 +10665,7 @@ def test_list_recommendations_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = recommender_service.ListRecommendationsResponse.to_json( recommender_service.ListRecommendationsResponse() ) @@ -10678,6 +10714,7 @@ def test_get_recommendation_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_recommendation(request) @@ -10720,6 +10757,7 @@ def test_get_recommendation_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_recommendation(request) # Establish that the response is the type that we expect. @@ -10765,6 +10803,7 @@ def test_get_recommendation_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = recommendation.Recommendation.to_json( recommendation.Recommendation() ) @@ -10813,6 +10852,7 @@ def test_mark_recommendation_claimed_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.mark_recommendation_claimed(request) @@ -10855,6 +10895,7 @@ def test_mark_recommendation_claimed_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.mark_recommendation_claimed(request) # Establish that the response is the type that we expect. @@ -10900,6 +10941,7 @@ def test_mark_recommendation_claimed_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = recommendation.Recommendation.to_json( recommendation.Recommendation() ) @@ -10948,6 +10990,7 @@ def test_mark_recommendation_succeeded_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.mark_recommendation_succeeded(request) @@ -10990,6 +11033,7 @@ def test_mark_recommendation_succeeded_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.mark_recommendation_succeeded(request) # Establish that the response is the type that we expect. @@ -11035,6 +11079,7 @@ def test_mark_recommendation_succeeded_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = recommendation.Recommendation.to_json( recommendation.Recommendation() ) @@ -11083,6 +11128,7 @@ def test_mark_recommendation_failed_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.mark_recommendation_failed(request) @@ -11125,6 +11171,7 @@ def test_mark_recommendation_failed_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.mark_recommendation_failed(request) # Establish that the response is the type that we expect. @@ -11170,6 +11217,7 @@ def test_mark_recommendation_failed_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = recommendation.Recommendation.to_json( recommendation.Recommendation() ) @@ -11218,6 +11266,7 @@ def test_get_recommender_config_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_recommender_config(request) @@ -11258,6 +11307,7 @@ def test_get_recommender_config_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_recommender_config(request) # Establish that the response is the type that we expect. @@ -11301,6 +11351,7 @@ def test_get_recommender_config_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = recommender_config.RecommenderConfig.to_json( recommender_config.RecommenderConfig() ) @@ -11351,6 +11402,7 @@ def test_update_recommender_config_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_recommender_config(request) @@ -11471,6 +11523,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_recommender_config(request) # Establish that the response is the type that we expect. @@ -11514,6 +11567,7 @@ def test_update_recommender_config_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = gcr_recommender_config.RecommenderConfig.to_json( gcr_recommender_config.RecommenderConfig() ) @@ -11562,6 +11616,7 @@ def test_get_insight_type_config_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_insight_type_config(request) @@ -11602,6 +11657,7 @@ def test_get_insight_type_config_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_insight_type_config(request) # Establish that the response is the type that we expect. @@ -11645,6 +11701,7 @@ def test_get_insight_type_config_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = insight_type_config.InsightTypeConfig.to_json( insight_type_config.InsightTypeConfig() ) @@ -11695,6 +11752,7 @@ def test_update_insight_type_config_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_insight_type_config(request) @@ -11815,6 +11873,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_insight_type_config(request) # Establish that the response is the type that we expect. @@ -11858,6 +11917,7 @@ def test_update_insight_type_config_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = gcr_insight_type_config.InsightTypeConfig.to_json( gcr_insight_type_config.InsightTypeConfig() ) @@ -11904,6 +11964,7 @@ def test_list_recommenders_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_recommenders(request) @@ -11939,6 +12000,7 @@ def test_list_recommenders_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_recommenders(request) # Establish that the response is the type that we expect. @@ -11979,6 +12041,7 @@ def test_list_recommenders_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = recommender_service.ListRecommendersResponse.to_json( recommender_service.ListRecommendersResponse() ) @@ -12025,6 +12088,7 @@ def test_list_insight_types_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_insight_types(request) @@ -12060,6 +12124,7 @@ def test_list_insight_types_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_insight_types(request) # Establish that the response is the type that we expect. @@ -12100,6 +12165,7 @@ def test_list_insight_types_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = recommender_service.ListInsightTypesResponse.to_json( recommender_service.ListInsightTypesResponse() ) diff --git a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster/gapic_version.py b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster/gapic_version.py index 9413c3341313..558c8aab67c5 100644 --- a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster/gapic_version.py +++ b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.1.10" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/gapic_version.py b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/gapic_version.py index 9413c3341313..558c8aab67c5 100644 --- a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/gapic_version.py +++ b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.1.10" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/async_client.py b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/async_client.py index 51d889d7c98d..fb648e78d281 100644 --- a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/async_client.py +++ b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -58,6 +59,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, CloudRedisClusterTransport from .transports.grpc_asyncio import CloudRedisClusterGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class CloudRedisClusterAsyncClient: """Configures and manages Cloud Memorystore for Redis clusters @@ -301,6 +311,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.redis.cluster_v1.CloudRedisClusterAsyncClient`.", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "credentialsType": None, + }, + ) + async def list_clusters( self, request: Optional[Union[cloud_redis_cluster.ListClustersRequest, dict]] = None, @@ -308,7 +340,7 @@ async def list_clusters( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListClustersAsyncPager: r"""Lists all Redis clusters owned by a project in either the specified location (region) or all locations. @@ -363,8 +395,10 @@ async def sample_list_clusters(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_cluster_v1.services.cloud_redis_cluster.pagers.ListClustersAsyncPager: @@ -438,7 +472,7 @@ async def get_cluster( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis_cluster.Cluster: r"""Gets the details of a specific Redis cluster. @@ -482,8 +516,10 @@ async def sample_get_cluster(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_cluster_v1.types.Cluster: @@ -543,7 +579,7 @@ async def update_cluster( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Updates the metadata and configuration of a specific Redis cluster. @@ -611,8 +647,10 @@ async def sample_update_cluster(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -688,7 +726,7 @@ async def delete_cluster( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a specific Redis cluster. Cluster stops serving and data is deleted. @@ -737,8 +775,10 @@ async def sample_delete_cluster(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -819,7 +859,7 @@ async def create_cluster( cluster_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Creates a Redis cluster based on the specified properties. The creation is executed asynchronously and @@ -904,8 +944,10 @@ async def sample_create_cluster(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -983,7 +1025,7 @@ async def get_cluster_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis_cluster.CertificateAuthority: r"""Gets the details of certificate authority information for Redis cluster. @@ -1030,8 +1072,10 @@ async def sample_get_cluster_certificate_authority(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_cluster_v1.types.CertificateAuthority: @@ -1091,7 +1135,7 @@ async def list_operations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Lists operations that match the specified filter in the request. @@ -1102,8 +1146,10 @@ async def list_operations( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.ListOperationsResponse: Response message for ``ListOperations`` method. @@ -1144,7 +1190,7 @@ async def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -1155,8 +1201,10 @@ async def get_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. @@ -1197,7 +1245,7 @@ async def delete_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Deletes a long-running operation. @@ -1213,8 +1261,10 @@ async def delete_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: None """ @@ -1251,7 +1301,7 @@ async def cancel_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Starts asynchronous cancellation on a long-running operation. @@ -1266,8 +1316,10 @@ async def cancel_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: None """ @@ -1304,7 +1356,7 @@ async def get_location( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.Location: r"""Gets information about a location. @@ -1315,8 +1367,10 @@ async def get_location( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.Location: Location object. @@ -1357,7 +1411,7 @@ async def list_locations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.ListLocationsResponse: r"""Lists information about the supported locations for this service. @@ -1368,8 +1422,10 @@ async def list_locations( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.ListLocationsResponse: Response message for ``ListLocations`` method. diff --git a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/client.py b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/client.py index 69db7419de72..21cf424a0ca4 100644 --- a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/client.py +++ b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.location import locations_pb2 # type: ignore @@ -641,6 +651,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -707,6 +721,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.redis.cluster_v1.CloudRedisClusterClient`.", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "credentialsType": None, + }, + ) + def list_clusters( self, request: Optional[Union[cloud_redis_cluster.ListClustersRequest, dict]] = None, @@ -714,7 +751,7 @@ def list_clusters( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListClustersPager: r"""Lists all Redis clusters owned by a project in either the specified location (region) or all locations. @@ -769,8 +806,10 @@ def sample_list_clusters(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_cluster_v1.services.cloud_redis_cluster.pagers.ListClustersPager: @@ -841,7 +880,7 @@ def get_cluster( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis_cluster.Cluster: r"""Gets the details of a specific Redis cluster. @@ -885,8 +924,10 @@ def sample_get_cluster(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_cluster_v1.types.Cluster: @@ -943,7 +984,7 @@ def update_cluster( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Updates the metadata and configuration of a specific Redis cluster. @@ -1011,8 +1052,10 @@ def sample_update_cluster(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1085,7 +1128,7 @@ def delete_cluster( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Deletes a specific Redis cluster. Cluster stops serving and data is deleted. @@ -1134,8 +1177,10 @@ def sample_delete_cluster(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1213,7 +1258,7 @@ def create_cluster( cluster_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Creates a Redis cluster based on the specified properties. The creation is executed asynchronously and @@ -1298,8 +1343,10 @@ def sample_create_cluster(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1374,7 +1421,7 @@ def get_cluster_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis_cluster.CertificateAuthority: r"""Gets the details of certificate authority information for Redis cluster. @@ -1421,8 +1468,10 @@ def sample_get_cluster_certificate_authority(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_cluster_v1.types.CertificateAuthority: @@ -1494,7 +1543,7 @@ def list_operations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Lists operations that match the specified filter in the request. @@ -1505,8 +1554,10 @@ def list_operations( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.ListOperationsResponse: Response message for ``ListOperations`` method. @@ -1547,7 +1598,7 @@ def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -1558,8 +1609,10 @@ def get_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. @@ -1600,7 +1653,7 @@ def delete_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Deletes a long-running operation. @@ -1616,8 +1669,10 @@ def delete_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: None """ @@ -1654,7 +1709,7 @@ def cancel_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Starts asynchronous cancellation on a long-running operation. @@ -1669,8 +1724,10 @@ def cancel_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: None """ @@ -1707,7 +1764,7 @@ def get_location( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.Location: r"""Gets information about a location. @@ -1718,8 +1775,10 @@ def get_location( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.Location: Location object. @@ -1760,7 +1819,7 @@ def list_locations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.ListLocationsResponse: r"""Lists information about the supported locations for this service. @@ -1771,8 +1830,10 @@ def list_locations( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.ListLocationsResponse: Response message for ``ListLocations`` method. diff --git a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/pagers.py b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/pagers.py index c6caa11b280c..8f166d332f73 100644 --- a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/pagers.py +++ b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -81,8 +81,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = cloud_redis_cluster.ListClustersRequest(request) @@ -141,7 +143,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -155,8 +157,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = cloud_redis_cluster.ListClustersRequest(request) diff --git a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/transports/grpc.py b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/transports/grpc.py index 8be76b51d33d..10af31c026d4 100644 --- a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/transports/grpc.py +++ b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -22,12 +25,90 @@ from google.auth.transport.grpc import SslCredentials # type: ignore from google.cloud.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.redis_cluster_v1.types import cloud_redis_cluster from .base import DEFAULT_CLIENT_INFO, CloudRedisClusterTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class CloudRedisClusterGrpcTransport(CloudRedisClusterTransport): """gRPC backend transport for CloudRedisCluster. @@ -209,7 +290,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -273,7 +359,9 @@ def operations_client(self) -> operations_v1.OperationsClient: """ # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + self._operations_client = operations_v1.OperationsClient( + self._logged_channel + ) # Return the client from cache. return self._operations_client @@ -309,7 +397,7 @@ def list_clusters( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_clusters" not in self._stubs: - self._stubs["list_clusters"] = self.grpc_channel.unary_unary( + self._stubs["list_clusters"] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1.CloudRedisCluster/ListClusters", request_serializer=cloud_redis_cluster.ListClustersRequest.serialize, response_deserializer=cloud_redis_cluster.ListClustersResponse.deserialize, @@ -335,7 +423,7 @@ def get_cluster( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_cluster" not in self._stubs: - self._stubs["get_cluster"] = self.grpc_channel.unary_unary( + self._stubs["get_cluster"] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1.CloudRedisCluster/GetCluster", request_serializer=cloud_redis_cluster.GetClusterRequest.serialize, response_deserializer=cloud_redis_cluster.Cluster.deserialize, @@ -366,7 +454,7 @@ def update_cluster( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_cluster" not in self._stubs: - self._stubs["update_cluster"] = self.grpc_channel.unary_unary( + self._stubs["update_cluster"] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1.CloudRedisCluster/UpdateCluster", request_serializer=cloud_redis_cluster.UpdateClusterRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -393,7 +481,7 @@ def delete_cluster( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_cluster" not in self._stubs: - self._stubs["delete_cluster"] = self.grpc_channel.unary_unary( + self._stubs["delete_cluster"] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1.CloudRedisCluster/DeleteCluster", request_serializer=cloud_redis_cluster.DeleteClusterRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -428,7 +516,7 @@ def create_cluster( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_cluster" not in self._stubs: - self._stubs["create_cluster"] = self.grpc_channel.unary_unary( + self._stubs["create_cluster"] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1.CloudRedisCluster/CreateCluster", request_serializer=cloud_redis_cluster.CreateClusterRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -461,7 +549,7 @@ def get_cluster_certificate_authority( if "get_cluster_certificate_authority" not in self._stubs: self._stubs[ "get_cluster_certificate_authority" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1.CloudRedisCluster/GetClusterCertificateAuthority", request_serializer=cloud_redis_cluster.GetClusterCertificateAuthorityRequest.serialize, response_deserializer=cloud_redis_cluster.CertificateAuthority.deserialize, @@ -469,7 +557,7 @@ def get_cluster_certificate_authority( return self._stubs["get_cluster_certificate_authority"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def delete_operation( @@ -481,7 +569,7 @@ def delete_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_operation" not in self._stubs: - self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + self._stubs["delete_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/DeleteOperation", request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, response_deserializer=None, @@ -498,7 +586,7 @@ def cancel_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "cancel_operation" not in self._stubs: - self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + self._stubs["cancel_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/CancelOperation", request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, response_deserializer=None, @@ -515,7 +603,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, @@ -534,7 +622,7 @@ def list_operations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_operations" not in self._stubs: - self._stubs["list_operations"] = self.grpc_channel.unary_unary( + self._stubs["list_operations"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/ListOperations", request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, response_deserializer=operations_pb2.ListOperationsResponse.FromString, @@ -553,7 +641,7 @@ def list_locations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_locations" not in self._stubs: - self._stubs["list_locations"] = self.grpc_channel.unary_unary( + self._stubs["list_locations"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/ListLocations", request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, response_deserializer=locations_pb2.ListLocationsResponse.FromString, @@ -570,7 +658,7 @@ def get_location( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_location" not in self._stubs: - self._stubs["get_location"] = self.grpc_channel.unary_unary( + self._stubs["get_location"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/GetLocation", request_serializer=locations_pb2.GetLocationRequest.SerializeToString, response_deserializer=locations_pb2.Location.FromString, diff --git a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/transports/grpc_asyncio.py b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/transports/grpc_asyncio.py index 774b8036f7b5..f8a1b30295e5 100644 --- a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/transports/grpc_asyncio.py +++ b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -24,14 +27,93 @@ from google.auth.transport.grpc import SslCredentials # type: ignore from google.cloud.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.redis_cluster_v1.types import cloud_redis_cluster from .base import DEFAULT_CLIENT_INFO, CloudRedisClusterTransport from .grpc import CloudRedisClusterGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class CloudRedisClusterGrpcAsyncIOTransport(CloudRedisClusterTransport): """gRPC AsyncIO backend transport for CloudRedisCluster. @@ -256,10 +338,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -282,7 +367,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel + self._logged_channel ) # Return the client from cache. @@ -319,7 +404,7 @@ def list_clusters( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_clusters" not in self._stubs: - self._stubs["list_clusters"] = self.grpc_channel.unary_unary( + self._stubs["list_clusters"] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1.CloudRedisCluster/ListClusters", request_serializer=cloud_redis_cluster.ListClustersRequest.serialize, response_deserializer=cloud_redis_cluster.ListClustersResponse.deserialize, @@ -347,7 +432,7 @@ def get_cluster( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_cluster" not in self._stubs: - self._stubs["get_cluster"] = self.grpc_channel.unary_unary( + self._stubs["get_cluster"] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1.CloudRedisCluster/GetCluster", request_serializer=cloud_redis_cluster.GetClusterRequest.serialize, response_deserializer=cloud_redis_cluster.Cluster.deserialize, @@ -380,7 +465,7 @@ def update_cluster( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_cluster" not in self._stubs: - self._stubs["update_cluster"] = self.grpc_channel.unary_unary( + self._stubs["update_cluster"] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1.CloudRedisCluster/UpdateCluster", request_serializer=cloud_redis_cluster.UpdateClusterRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -409,7 +494,7 @@ def delete_cluster( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_cluster" not in self._stubs: - self._stubs["delete_cluster"] = self.grpc_channel.unary_unary( + self._stubs["delete_cluster"] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1.CloudRedisCluster/DeleteCluster", request_serializer=cloud_redis_cluster.DeleteClusterRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -446,7 +531,7 @@ def create_cluster( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_cluster" not in self._stubs: - self._stubs["create_cluster"] = self.grpc_channel.unary_unary( + self._stubs["create_cluster"] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1.CloudRedisCluster/CreateCluster", request_serializer=cloud_redis_cluster.CreateClusterRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -479,7 +564,7 @@ def get_cluster_certificate_authority( if "get_cluster_certificate_authority" not in self._stubs: self._stubs[ "get_cluster_certificate_authority" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1.CloudRedisCluster/GetClusterCertificateAuthority", request_serializer=cloud_redis_cluster.GetClusterCertificateAuthorityRequest.serialize, response_deserializer=cloud_redis_cluster.CertificateAuthority.deserialize, @@ -557,7 +642,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: @@ -573,7 +658,7 @@ def delete_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_operation" not in self._stubs: - self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + self._stubs["delete_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/DeleteOperation", request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, response_deserializer=None, @@ -590,7 +675,7 @@ def cancel_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "cancel_operation" not in self._stubs: - self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + self._stubs["cancel_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/CancelOperation", request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, response_deserializer=None, @@ -607,7 +692,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, @@ -626,7 +711,7 @@ def list_operations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_operations" not in self._stubs: - self._stubs["list_operations"] = self.grpc_channel.unary_unary( + self._stubs["list_operations"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/ListOperations", request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, response_deserializer=operations_pb2.ListOperationsResponse.FromString, @@ -645,7 +730,7 @@ def list_locations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_locations" not in self._stubs: - self._stubs["list_locations"] = self.grpc_channel.unary_unary( + self._stubs["list_locations"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/ListLocations", request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, response_deserializer=locations_pb2.ListLocationsResponse.FromString, @@ -662,7 +747,7 @@ def get_location( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_location" not in self._stubs: - self._stubs["get_location"] = self.grpc_channel.unary_unary( + self._stubs["get_location"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/GetLocation", request_serializer=locations_pb2.GetLocationRequest.SerializeToString, response_deserializer=locations_pb2.Location.FromString, diff --git a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/transports/rest.py b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/transports/rest.py index 1c0659689366..8b2a43ddb877 100644 --- a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/transports/rest.py +++ b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1/services/cloud_redis_cluster/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -39,6 +39,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -119,8 +127,11 @@ def post_update_cluster(self, response): def pre_create_cluster( self, request: cloud_redis_cluster.CreateClusterRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis_cluster.CreateClusterRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis_cluster.CreateClusterRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for create_cluster Override in a subclass to manipulate the request or metadata @@ -142,8 +153,11 @@ def post_create_cluster( def pre_delete_cluster( self, request: cloud_redis_cluster.DeleteClusterRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis_cluster.DeleteClusterRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis_cluster.DeleteClusterRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for delete_cluster Override in a subclass to manipulate the request or metadata @@ -165,8 +179,10 @@ def post_delete_cluster( def pre_get_cluster( self, request: cloud_redis_cluster.GetClusterRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis_cluster.GetClusterRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis_cluster.GetClusterRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_cluster Override in a subclass to manipulate the request or metadata @@ -188,10 +204,10 @@ def post_get_cluster( def pre_get_cluster_certificate_authority( self, request: cloud_redis_cluster.GetClusterCertificateAuthorityRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ cloud_redis_cluster.GetClusterCertificateAuthorityRequest, - Sequence[Tuple[str, str]], + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for get_cluster_certificate_authority @@ -214,8 +230,10 @@ def post_get_cluster_certificate_authority( def pre_list_clusters( self, request: cloud_redis_cluster.ListClustersRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis_cluster.ListClustersRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis_cluster.ListClustersRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_clusters Override in a subclass to manipulate the request or metadata @@ -237,8 +255,11 @@ def post_list_clusters( def pre_update_cluster( self, request: cloud_redis_cluster.UpdateClusterRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis_cluster.UpdateClusterRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis_cluster.UpdateClusterRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for update_cluster Override in a subclass to manipulate the request or metadata @@ -260,8 +281,10 @@ def post_update_cluster( def pre_get_location( self, request: locations_pb2.GetLocationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[locations_pb2.GetLocationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + locations_pb2.GetLocationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_location Override in a subclass to manipulate the request or metadata @@ -283,8 +306,10 @@ def post_get_location( def pre_list_locations( self, request: locations_pb2.ListLocationsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[locations_pb2.ListLocationsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + locations_pb2.ListLocationsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_locations Override in a subclass to manipulate the request or metadata @@ -306,8 +331,10 @@ def post_list_locations( def pre_cancel_operation( self, request: operations_pb2.CancelOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.CancelOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.CancelOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for cancel_operation Override in a subclass to manipulate the request or metadata @@ -327,8 +354,10 @@ def post_cancel_operation(self, response: None) -> None: def pre_delete_operation( self, request: operations_pb2.DeleteOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.DeleteOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.DeleteOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for delete_operation Override in a subclass to manipulate the request or metadata @@ -348,8 +377,10 @@ def post_delete_operation(self, response: None) -> None: def pre_get_operation( self, request: operations_pb2.GetOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.GetOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.GetOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_operation Override in a subclass to manipulate the request or metadata @@ -371,8 +402,10 @@ def post_get_operation( def pre_list_operations( self, request: operations_pb2.ListOperationsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.ListOperationsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.ListOperationsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_operations Override in a subclass to manipulate the request or metadata @@ -594,7 +627,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the create cluster method over HTTP. @@ -604,8 +637,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -618,6 +653,7 @@ def __call__( http_options = ( _BaseCloudRedisClusterRestTransport._BaseCreateCluster._get_http_options() ) + request, metadata = self._interceptor.pre_create_cluster(request, metadata) transcoded_request = _BaseCloudRedisClusterRestTransport._BaseCreateCluster._get_transcoded_request( http_options, request @@ -632,6 +668,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1.CloudRedisClusterClient.CreateCluster", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": "CreateCluster", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._CreateCluster._get_response( self._host, @@ -651,7 +714,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_cluster(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis.cluster_v1.CloudRedisClusterClient.create_cluster", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": "CreateCluster", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DeleteCluster( @@ -689,7 +774,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the delete cluster method over HTTP. @@ -699,8 +784,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -713,6 +800,7 @@ def __call__( http_options = ( _BaseCloudRedisClusterRestTransport._BaseDeleteCluster._get_http_options() ) + request, metadata = self._interceptor.pre_delete_cluster(request, metadata) transcoded_request = _BaseCloudRedisClusterRestTransport._BaseDeleteCluster._get_transcoded_request( http_options, request @@ -723,6 +811,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1.CloudRedisClusterClient.DeleteCluster", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": "DeleteCluster", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._DeleteCluster._get_response( self._host, @@ -741,7 +856,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_delete_cluster(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis.cluster_v1.CloudRedisClusterClient.delete_cluster", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": "DeleteCluster", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetCluster( @@ -778,7 +915,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis_cluster.Cluster: r"""Call the get cluster method over HTTP. @@ -788,8 +925,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.cloud_redis_cluster.Cluster: @@ -799,6 +938,7 @@ def __call__( http_options = ( _BaseCloudRedisClusterRestTransport._BaseGetCluster._get_http_options() ) + request, metadata = self._interceptor.pre_get_cluster(request, metadata) transcoded_request = _BaseCloudRedisClusterRestTransport._BaseGetCluster._get_transcoded_request( http_options, request @@ -809,6 +949,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1.CloudRedisClusterClient.GetCluster", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": "GetCluster", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._GetCluster._get_response( self._host, @@ -829,7 +996,29 @@ def __call__( pb_resp = cloud_redis_cluster.Cluster.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_cluster(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = cloud_redis_cluster.Cluster.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis.cluster_v1.CloudRedisClusterClient.get_cluster", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": "GetCluster", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetClusterCertificateAuthority( @@ -867,7 +1056,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis_cluster.CertificateAuthority: r"""Call the get cluster certificate authority method over HTTP. @@ -879,8 +1068,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.cloud_redis_cluster.CertificateAuthority: @@ -890,6 +1081,7 @@ def __call__( http_options = ( _BaseCloudRedisClusterRestTransport._BaseGetClusterCertificateAuthority._get_http_options() ) + request, metadata = self._interceptor.pre_get_cluster_certificate_authority( request, metadata ) @@ -902,6 +1094,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1.CloudRedisClusterClient.GetClusterCertificateAuthority", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": "GetClusterCertificateAuthority", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._GetClusterCertificateAuthority._get_response( self._host, @@ -922,7 +1141,31 @@ def __call__( pb_resp = cloud_redis_cluster.CertificateAuthority.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_cluster_certificate_authority(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = cloud_redis_cluster.CertificateAuthority.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis.cluster_v1.CloudRedisClusterClient.get_cluster_certificate_authority", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": "GetClusterCertificateAuthority", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListClusters( @@ -959,7 +1202,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis_cluster.ListClustersResponse: r"""Call the list clusters method over HTTP. @@ -969,8 +1212,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.cloud_redis_cluster.ListClustersResponse: @@ -980,6 +1225,7 @@ def __call__( http_options = ( _BaseCloudRedisClusterRestTransport._BaseListClusters._get_http_options() ) + request, metadata = self._interceptor.pre_list_clusters(request, metadata) transcoded_request = _BaseCloudRedisClusterRestTransport._BaseListClusters._get_transcoded_request( http_options, request @@ -990,6 +1236,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1.CloudRedisClusterClient.ListClusters", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": "ListClusters", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._ListClusters._get_response( self._host, @@ -1010,7 +1283,31 @@ def __call__( pb_resp = cloud_redis_cluster.ListClustersResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_clusters(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = cloud_redis_cluster.ListClustersResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis.cluster_v1.CloudRedisClusterClient.list_clusters", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": "ListClusters", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateCluster( @@ -1049,7 +1346,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the update cluster method over HTTP. @@ -1059,8 +1356,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1073,6 +1372,7 @@ def __call__( http_options = ( _BaseCloudRedisClusterRestTransport._BaseUpdateCluster._get_http_options() ) + request, metadata = self._interceptor.pre_update_cluster(request, metadata) transcoded_request = _BaseCloudRedisClusterRestTransport._BaseUpdateCluster._get_transcoded_request( http_options, request @@ -1087,6 +1387,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1.CloudRedisClusterClient.UpdateCluster", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": "UpdateCluster", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._UpdateCluster._get_response( self._host, @@ -1106,7 +1433,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_cluster(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis.cluster_v1.CloudRedisClusterClient.update_cluster", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": "UpdateCluster", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property @@ -1201,7 +1550,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.Location: r"""Call the get location method over HTTP. @@ -1211,8 +1560,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: locations_pb2.Location: Response from GetLocation method. @@ -1221,6 +1572,7 @@ def __call__( http_options = ( _BaseCloudRedisClusterRestTransport._BaseGetLocation._get_http_options() ) + request, metadata = self._interceptor.pre_get_location(request, metadata) transcoded_request = _BaseCloudRedisClusterRestTransport._BaseGetLocation._get_transcoded_request( http_options, request @@ -1231,6 +1583,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1.CloudRedisClusterClient.GetLocation", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": "GetLocation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._GetLocation._get_response( self._host, @@ -1250,6 +1629,27 @@ def __call__( resp = locations_pb2.Location() resp = json_format.Parse(content, resp) resp = self._interceptor.post_get_location(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis.cluster_v1.CloudRedisClusterAsyncClient.GetLocation", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": "GetLocation", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property @@ -1291,7 +1691,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.ListLocationsResponse: r"""Call the list locations method over HTTP. @@ -1301,8 +1701,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: locations_pb2.ListLocationsResponse: Response from ListLocations method. @@ -1311,6 +1713,7 @@ def __call__( http_options = ( _BaseCloudRedisClusterRestTransport._BaseListLocations._get_http_options() ) + request, metadata = self._interceptor.pre_list_locations(request, metadata) transcoded_request = _BaseCloudRedisClusterRestTransport._BaseListLocations._get_transcoded_request( http_options, request @@ -1321,6 +1724,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1.CloudRedisClusterClient.ListLocations", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": "ListLocations", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._ListLocations._get_response( self._host, @@ -1340,6 +1770,27 @@ def __call__( resp = locations_pb2.ListLocationsResponse() resp = json_format.Parse(content, resp) resp = self._interceptor.post_list_locations(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis.cluster_v1.CloudRedisClusterAsyncClient.ListLocations", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": "ListLocations", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property @@ -1381,7 +1832,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Call the cancel operation method over HTTP. @@ -1391,13 +1842,16 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ http_options = ( _BaseCloudRedisClusterRestTransport._BaseCancelOperation._get_http_options() ) + request, metadata = self._interceptor.pre_cancel_operation( request, metadata ) @@ -1410,6 +1864,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1.CloudRedisClusterClient.CancelOperation", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": "CancelOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._CancelOperation._get_response( self._host, @@ -1466,7 +1947,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Call the delete operation method over HTTP. @@ -1476,13 +1957,16 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ http_options = ( _BaseCloudRedisClusterRestTransport._BaseDeleteOperation._get_http_options() ) + request, metadata = self._interceptor.pre_delete_operation( request, metadata ) @@ -1495,6 +1979,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1.CloudRedisClusterClient.DeleteOperation", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": "DeleteOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._DeleteOperation._get_response( self._host, @@ -1550,7 +2061,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the get operation method over HTTP. @@ -1560,8 +2071,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: operations_pb2.Operation: Response from GetOperation method. @@ -1570,6 +2083,7 @@ def __call__( http_options = ( _BaseCloudRedisClusterRestTransport._BaseGetOperation._get_http_options() ) + request, metadata = self._interceptor.pre_get_operation(request, metadata) transcoded_request = _BaseCloudRedisClusterRestTransport._BaseGetOperation._get_transcoded_request( http_options, request @@ -1580,6 +2094,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1.CloudRedisClusterClient.GetOperation", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": "GetOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._GetOperation._get_response( self._host, @@ -1599,6 +2140,27 @@ def __call__( resp = operations_pb2.Operation() resp = json_format.Parse(content, resp) resp = self._interceptor.post_get_operation(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis.cluster_v1.CloudRedisClusterAsyncClient.GetOperation", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": "GetOperation", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property @@ -1640,7 +2202,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Call the list operations method over HTTP. @@ -1650,8 +2212,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: operations_pb2.ListOperationsResponse: Response from ListOperations method. @@ -1660,6 +2224,7 @@ def __call__( http_options = ( _BaseCloudRedisClusterRestTransport._BaseListOperations._get_http_options() ) + request, metadata = self._interceptor.pre_list_operations(request, metadata) transcoded_request = _BaseCloudRedisClusterRestTransport._BaseListOperations._get_transcoded_request( http_options, request @@ -1670,6 +2235,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1.CloudRedisClusterClient.ListOperations", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": "ListOperations", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._ListOperations._get_response( self._host, @@ -1689,6 +2281,27 @@ def __call__( resp = operations_pb2.ListOperationsResponse() resp = json_format.Parse(content, resp) resp = self._interceptor.post_list_operations(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis.cluster_v1.CloudRedisClusterAsyncClient.ListOperations", + extra={ + "serviceName": "google.cloud.redis.cluster.v1.CloudRedisCluster", + "rpcName": "ListOperations", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property diff --git a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/gapic_version.py b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/gapic_version.py index 9413c3341313..558c8aab67c5 100644 --- a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/gapic_version.py +++ b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.1.10" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/async_client.py b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/async_client.py index 7a209fb1d5f3..24e0cd182052 100644 --- a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/async_client.py +++ b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -58,6 +59,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, CloudRedisClusterTransport from .transports.grpc_asyncio import CloudRedisClusterGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class CloudRedisClusterAsyncClient: """Configures and manages Cloud Memorystore for Redis clusters @@ -301,6 +311,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.redis.cluster_v1beta1.CloudRedisClusterAsyncClient`.", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "credentialsType": None, + }, + ) + async def list_clusters( self, request: Optional[Union[cloud_redis_cluster.ListClustersRequest, dict]] = None, @@ -308,7 +340,7 @@ async def list_clusters( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListClustersAsyncPager: r"""Lists all Redis clusters owned by a project in either the specified location (region) or all locations. @@ -363,8 +395,10 @@ async def sample_list_clusters(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_cluster_v1beta1.services.cloud_redis_cluster.pagers.ListClustersAsyncPager: @@ -438,7 +472,7 @@ async def get_cluster( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis_cluster.Cluster: r"""Gets the details of a specific Redis cluster. @@ -482,8 +516,10 @@ async def sample_get_cluster(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_cluster_v1beta1.types.Cluster: @@ -543,7 +579,7 @@ async def update_cluster( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Updates the metadata and configuration of a specific Redis cluster. @@ -611,8 +647,10 @@ async def sample_update_cluster(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -688,7 +726,7 @@ async def delete_cluster( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a specific Redis cluster. Cluster stops serving and data is deleted. @@ -737,8 +775,10 @@ async def sample_delete_cluster(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -819,7 +859,7 @@ async def create_cluster( cluster_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Creates a Redis cluster based on the specified properties. The creation is executed asynchronously and @@ -904,8 +944,10 @@ async def sample_create_cluster(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -983,7 +1025,7 @@ async def get_cluster_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis_cluster.CertificateAuthority: r"""Gets the details of certificate authority information for Redis cluster. @@ -1030,8 +1072,10 @@ async def sample_get_cluster_certificate_authority(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_cluster_v1beta1.types.CertificateAuthority: @@ -1091,7 +1135,7 @@ async def list_operations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Lists operations that match the specified filter in the request. @@ -1102,8 +1146,10 @@ async def list_operations( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.ListOperationsResponse: Response message for ``ListOperations`` method. @@ -1144,7 +1190,7 @@ async def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -1155,8 +1201,10 @@ async def get_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. @@ -1197,7 +1245,7 @@ async def delete_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Deletes a long-running operation. @@ -1213,8 +1261,10 @@ async def delete_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: None """ @@ -1251,7 +1301,7 @@ async def cancel_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Starts asynchronous cancellation on a long-running operation. @@ -1266,8 +1316,10 @@ async def cancel_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: None """ @@ -1304,7 +1356,7 @@ async def get_location( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.Location: r"""Gets information about a location. @@ -1315,8 +1367,10 @@ async def get_location( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.Location: Location object. @@ -1357,7 +1411,7 @@ async def list_locations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.ListLocationsResponse: r"""Lists information about the supported locations for this service. @@ -1368,8 +1422,10 @@ async def list_locations( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.ListLocationsResponse: Response message for ``ListLocations`` method. diff --git a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/client.py b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/client.py index 6d523c048087..d06e8d2d505a 100644 --- a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/client.py +++ b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.location import locations_pb2 # type: ignore @@ -641,6 +651,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -707,6 +721,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.redis.cluster_v1beta1.CloudRedisClusterClient`.", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "credentialsType": None, + }, + ) + def list_clusters( self, request: Optional[Union[cloud_redis_cluster.ListClustersRequest, dict]] = None, @@ -714,7 +751,7 @@ def list_clusters( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListClustersPager: r"""Lists all Redis clusters owned by a project in either the specified location (region) or all locations. @@ -769,8 +806,10 @@ def sample_list_clusters(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_cluster_v1beta1.services.cloud_redis_cluster.pagers.ListClustersPager: @@ -841,7 +880,7 @@ def get_cluster( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis_cluster.Cluster: r"""Gets the details of a specific Redis cluster. @@ -885,8 +924,10 @@ def sample_get_cluster(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_cluster_v1beta1.types.Cluster: @@ -943,7 +984,7 @@ def update_cluster( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Updates the metadata and configuration of a specific Redis cluster. @@ -1011,8 +1052,10 @@ def sample_update_cluster(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1085,7 +1128,7 @@ def delete_cluster( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Deletes a specific Redis cluster. Cluster stops serving and data is deleted. @@ -1134,8 +1177,10 @@ def sample_delete_cluster(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1213,7 +1258,7 @@ def create_cluster( cluster_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Creates a Redis cluster based on the specified properties. The creation is executed asynchronously and @@ -1298,8 +1343,10 @@ def sample_create_cluster(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1374,7 +1421,7 @@ def get_cluster_certificate_authority( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis_cluster.CertificateAuthority: r"""Gets the details of certificate authority information for Redis cluster. @@ -1421,8 +1468,10 @@ def sample_get_cluster_certificate_authority(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_cluster_v1beta1.types.CertificateAuthority: @@ -1494,7 +1543,7 @@ def list_operations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Lists operations that match the specified filter in the request. @@ -1505,8 +1554,10 @@ def list_operations( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.ListOperationsResponse: Response message for ``ListOperations`` method. @@ -1547,7 +1598,7 @@ def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -1558,8 +1609,10 @@ def get_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. @@ -1600,7 +1653,7 @@ def delete_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Deletes a long-running operation. @@ -1616,8 +1669,10 @@ def delete_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: None """ @@ -1654,7 +1709,7 @@ def cancel_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Starts asynchronous cancellation on a long-running operation. @@ -1669,8 +1724,10 @@ def cancel_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: None """ @@ -1707,7 +1764,7 @@ def get_location( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.Location: r"""Gets information about a location. @@ -1718,8 +1775,10 @@ def get_location( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.Location: Location object. @@ -1760,7 +1819,7 @@ def list_locations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.ListLocationsResponse: r"""Lists information about the supported locations for this service. @@ -1771,8 +1830,10 @@ def list_locations( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.ListLocationsResponse: Response message for ``ListLocations`` method. diff --git a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/pagers.py b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/pagers.py index 552f00641a4c..1e80ee4a2e4f 100644 --- a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/pagers.py +++ b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -81,8 +81,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = cloud_redis_cluster.ListClustersRequest(request) @@ -141,7 +143,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -155,8 +157,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = cloud_redis_cluster.ListClustersRequest(request) diff --git a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/transports/grpc.py b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/transports/grpc.py index 0a4571230163..b53d2adf0e70 100644 --- a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/transports/grpc.py +++ b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -22,12 +25,90 @@ from google.auth.transport.grpc import SslCredentials # type: ignore from google.cloud.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.redis_cluster_v1beta1.types import cloud_redis_cluster from .base import DEFAULT_CLIENT_INFO, CloudRedisClusterTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class CloudRedisClusterGrpcTransport(CloudRedisClusterTransport): """gRPC backend transport for CloudRedisCluster. @@ -209,7 +290,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -273,7 +359,9 @@ def operations_client(self) -> operations_v1.OperationsClient: """ # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + self._operations_client = operations_v1.OperationsClient( + self._logged_channel + ) # Return the client from cache. return self._operations_client @@ -309,7 +397,7 @@ def list_clusters( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_clusters" not in self._stubs: - self._stubs["list_clusters"] = self.grpc_channel.unary_unary( + self._stubs["list_clusters"] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1beta1.CloudRedisCluster/ListClusters", request_serializer=cloud_redis_cluster.ListClustersRequest.serialize, response_deserializer=cloud_redis_cluster.ListClustersResponse.deserialize, @@ -335,7 +423,7 @@ def get_cluster( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_cluster" not in self._stubs: - self._stubs["get_cluster"] = self.grpc_channel.unary_unary( + self._stubs["get_cluster"] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1beta1.CloudRedisCluster/GetCluster", request_serializer=cloud_redis_cluster.GetClusterRequest.serialize, response_deserializer=cloud_redis_cluster.Cluster.deserialize, @@ -366,7 +454,7 @@ def update_cluster( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_cluster" not in self._stubs: - self._stubs["update_cluster"] = self.grpc_channel.unary_unary( + self._stubs["update_cluster"] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1beta1.CloudRedisCluster/UpdateCluster", request_serializer=cloud_redis_cluster.UpdateClusterRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -393,7 +481,7 @@ def delete_cluster( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_cluster" not in self._stubs: - self._stubs["delete_cluster"] = self.grpc_channel.unary_unary( + self._stubs["delete_cluster"] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1beta1.CloudRedisCluster/DeleteCluster", request_serializer=cloud_redis_cluster.DeleteClusterRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -428,7 +516,7 @@ def create_cluster( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_cluster" not in self._stubs: - self._stubs["create_cluster"] = self.grpc_channel.unary_unary( + self._stubs["create_cluster"] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1beta1.CloudRedisCluster/CreateCluster", request_serializer=cloud_redis_cluster.CreateClusterRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -461,7 +549,7 @@ def get_cluster_certificate_authority( if "get_cluster_certificate_authority" not in self._stubs: self._stubs[ "get_cluster_certificate_authority" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1beta1.CloudRedisCluster/GetClusterCertificateAuthority", request_serializer=cloud_redis_cluster.GetClusterCertificateAuthorityRequest.serialize, response_deserializer=cloud_redis_cluster.CertificateAuthority.deserialize, @@ -469,7 +557,7 @@ def get_cluster_certificate_authority( return self._stubs["get_cluster_certificate_authority"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def delete_operation( @@ -481,7 +569,7 @@ def delete_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_operation" not in self._stubs: - self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + self._stubs["delete_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/DeleteOperation", request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, response_deserializer=None, @@ -498,7 +586,7 @@ def cancel_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "cancel_operation" not in self._stubs: - self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + self._stubs["cancel_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/CancelOperation", request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, response_deserializer=None, @@ -515,7 +603,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, @@ -534,7 +622,7 @@ def list_operations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_operations" not in self._stubs: - self._stubs["list_operations"] = self.grpc_channel.unary_unary( + self._stubs["list_operations"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/ListOperations", request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, response_deserializer=operations_pb2.ListOperationsResponse.FromString, @@ -553,7 +641,7 @@ def list_locations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_locations" not in self._stubs: - self._stubs["list_locations"] = self.grpc_channel.unary_unary( + self._stubs["list_locations"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/ListLocations", request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, response_deserializer=locations_pb2.ListLocationsResponse.FromString, @@ -570,7 +658,7 @@ def get_location( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_location" not in self._stubs: - self._stubs["get_location"] = self.grpc_channel.unary_unary( + self._stubs["get_location"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/GetLocation", request_serializer=locations_pb2.GetLocationRequest.SerializeToString, response_deserializer=locations_pb2.Location.FromString, diff --git a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/transports/grpc_asyncio.py b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/transports/grpc_asyncio.py index b1fc12751d6e..18809713fd2d 100644 --- a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/transports/grpc_asyncio.py +++ b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -24,14 +27,93 @@ from google.auth.transport.grpc import SslCredentials # type: ignore from google.cloud.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.redis_cluster_v1beta1.types import cloud_redis_cluster from .base import DEFAULT_CLIENT_INFO, CloudRedisClusterTransport from .grpc import CloudRedisClusterGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class CloudRedisClusterGrpcAsyncIOTransport(CloudRedisClusterTransport): """gRPC AsyncIO backend transport for CloudRedisCluster. @@ -256,10 +338,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -282,7 +367,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel + self._logged_channel ) # Return the client from cache. @@ -319,7 +404,7 @@ def list_clusters( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_clusters" not in self._stubs: - self._stubs["list_clusters"] = self.grpc_channel.unary_unary( + self._stubs["list_clusters"] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1beta1.CloudRedisCluster/ListClusters", request_serializer=cloud_redis_cluster.ListClustersRequest.serialize, response_deserializer=cloud_redis_cluster.ListClustersResponse.deserialize, @@ -347,7 +432,7 @@ def get_cluster( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_cluster" not in self._stubs: - self._stubs["get_cluster"] = self.grpc_channel.unary_unary( + self._stubs["get_cluster"] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1beta1.CloudRedisCluster/GetCluster", request_serializer=cloud_redis_cluster.GetClusterRequest.serialize, response_deserializer=cloud_redis_cluster.Cluster.deserialize, @@ -380,7 +465,7 @@ def update_cluster( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_cluster" not in self._stubs: - self._stubs["update_cluster"] = self.grpc_channel.unary_unary( + self._stubs["update_cluster"] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1beta1.CloudRedisCluster/UpdateCluster", request_serializer=cloud_redis_cluster.UpdateClusterRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -409,7 +494,7 @@ def delete_cluster( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_cluster" not in self._stubs: - self._stubs["delete_cluster"] = self.grpc_channel.unary_unary( + self._stubs["delete_cluster"] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1beta1.CloudRedisCluster/DeleteCluster", request_serializer=cloud_redis_cluster.DeleteClusterRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -446,7 +531,7 @@ def create_cluster( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_cluster" not in self._stubs: - self._stubs["create_cluster"] = self.grpc_channel.unary_unary( + self._stubs["create_cluster"] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1beta1.CloudRedisCluster/CreateCluster", request_serializer=cloud_redis_cluster.CreateClusterRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -479,7 +564,7 @@ def get_cluster_certificate_authority( if "get_cluster_certificate_authority" not in self._stubs: self._stubs[ "get_cluster_certificate_authority" - ] = self.grpc_channel.unary_unary( + ] = self._logged_channel.unary_unary( "/google.cloud.redis.cluster.v1beta1.CloudRedisCluster/GetClusterCertificateAuthority", request_serializer=cloud_redis_cluster.GetClusterCertificateAuthorityRequest.serialize, response_deserializer=cloud_redis_cluster.CertificateAuthority.deserialize, @@ -557,7 +642,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: @@ -573,7 +658,7 @@ def delete_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_operation" not in self._stubs: - self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + self._stubs["delete_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/DeleteOperation", request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, response_deserializer=None, @@ -590,7 +675,7 @@ def cancel_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "cancel_operation" not in self._stubs: - self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + self._stubs["cancel_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/CancelOperation", request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, response_deserializer=None, @@ -607,7 +692,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, @@ -626,7 +711,7 @@ def list_operations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_operations" not in self._stubs: - self._stubs["list_operations"] = self.grpc_channel.unary_unary( + self._stubs["list_operations"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/ListOperations", request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, response_deserializer=operations_pb2.ListOperationsResponse.FromString, @@ -645,7 +730,7 @@ def list_locations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_locations" not in self._stubs: - self._stubs["list_locations"] = self.grpc_channel.unary_unary( + self._stubs["list_locations"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/ListLocations", request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, response_deserializer=locations_pb2.ListLocationsResponse.FromString, @@ -662,7 +747,7 @@ def get_location( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_location" not in self._stubs: - self._stubs["get_location"] = self.grpc_channel.unary_unary( + self._stubs["get_location"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/GetLocation", request_serializer=locations_pb2.GetLocationRequest.SerializeToString, response_deserializer=locations_pb2.Location.FromString, diff --git a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/transports/rest.py b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/transports/rest.py index a86975b08c8f..2578278227c1 100644 --- a/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/transports/rest.py +++ b/packages/google-cloud-redis-cluster/google/cloud/redis_cluster_v1beta1/services/cloud_redis_cluster/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -39,6 +39,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -119,8 +127,11 @@ def post_update_cluster(self, response): def pre_create_cluster( self, request: cloud_redis_cluster.CreateClusterRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis_cluster.CreateClusterRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis_cluster.CreateClusterRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for create_cluster Override in a subclass to manipulate the request or metadata @@ -142,8 +153,11 @@ def post_create_cluster( def pre_delete_cluster( self, request: cloud_redis_cluster.DeleteClusterRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis_cluster.DeleteClusterRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis_cluster.DeleteClusterRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for delete_cluster Override in a subclass to manipulate the request or metadata @@ -165,8 +179,10 @@ def post_delete_cluster( def pre_get_cluster( self, request: cloud_redis_cluster.GetClusterRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis_cluster.GetClusterRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis_cluster.GetClusterRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_cluster Override in a subclass to manipulate the request or metadata @@ -188,10 +204,10 @@ def post_get_cluster( def pre_get_cluster_certificate_authority( self, request: cloud_redis_cluster.GetClusterCertificateAuthorityRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ cloud_redis_cluster.GetClusterCertificateAuthorityRequest, - Sequence[Tuple[str, str]], + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for get_cluster_certificate_authority @@ -214,8 +230,10 @@ def post_get_cluster_certificate_authority( def pre_list_clusters( self, request: cloud_redis_cluster.ListClustersRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis_cluster.ListClustersRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis_cluster.ListClustersRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_clusters Override in a subclass to manipulate the request or metadata @@ -237,8 +255,11 @@ def post_list_clusters( def pre_update_cluster( self, request: cloud_redis_cluster.UpdateClusterRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis_cluster.UpdateClusterRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis_cluster.UpdateClusterRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for update_cluster Override in a subclass to manipulate the request or metadata @@ -260,8 +281,10 @@ def post_update_cluster( def pre_get_location( self, request: locations_pb2.GetLocationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[locations_pb2.GetLocationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + locations_pb2.GetLocationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_location Override in a subclass to manipulate the request or metadata @@ -283,8 +306,10 @@ def post_get_location( def pre_list_locations( self, request: locations_pb2.ListLocationsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[locations_pb2.ListLocationsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + locations_pb2.ListLocationsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_locations Override in a subclass to manipulate the request or metadata @@ -306,8 +331,10 @@ def post_list_locations( def pre_cancel_operation( self, request: operations_pb2.CancelOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.CancelOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.CancelOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for cancel_operation Override in a subclass to manipulate the request or metadata @@ -327,8 +354,10 @@ def post_cancel_operation(self, response: None) -> None: def pre_delete_operation( self, request: operations_pb2.DeleteOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.DeleteOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.DeleteOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for delete_operation Override in a subclass to manipulate the request or metadata @@ -348,8 +377,10 @@ def post_delete_operation(self, response: None) -> None: def pre_get_operation( self, request: operations_pb2.GetOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.GetOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.GetOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_operation Override in a subclass to manipulate the request or metadata @@ -371,8 +402,10 @@ def post_get_operation( def pre_list_operations( self, request: operations_pb2.ListOperationsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.ListOperationsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.ListOperationsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_operations Override in a subclass to manipulate the request or metadata @@ -594,7 +627,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the create cluster method over HTTP. @@ -604,8 +637,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -618,6 +653,7 @@ def __call__( http_options = ( _BaseCloudRedisClusterRestTransport._BaseCreateCluster._get_http_options() ) + request, metadata = self._interceptor.pre_create_cluster(request, metadata) transcoded_request = _BaseCloudRedisClusterRestTransport._BaseCreateCluster._get_transcoded_request( http_options, request @@ -632,6 +668,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1beta1.CloudRedisClusterClient.CreateCluster", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": "CreateCluster", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._CreateCluster._get_response( self._host, @@ -651,7 +714,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_cluster(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis.cluster_v1beta1.CloudRedisClusterClient.create_cluster", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": "CreateCluster", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DeleteCluster( @@ -689,7 +774,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the delete cluster method over HTTP. @@ -699,8 +784,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -713,6 +800,7 @@ def __call__( http_options = ( _BaseCloudRedisClusterRestTransport._BaseDeleteCluster._get_http_options() ) + request, metadata = self._interceptor.pre_delete_cluster(request, metadata) transcoded_request = _BaseCloudRedisClusterRestTransport._BaseDeleteCluster._get_transcoded_request( http_options, request @@ -723,6 +811,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1beta1.CloudRedisClusterClient.DeleteCluster", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": "DeleteCluster", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._DeleteCluster._get_response( self._host, @@ -741,7 +856,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_delete_cluster(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis.cluster_v1beta1.CloudRedisClusterClient.delete_cluster", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": "DeleteCluster", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetCluster( @@ -778,7 +915,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis_cluster.Cluster: r"""Call the get cluster method over HTTP. @@ -788,8 +925,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.cloud_redis_cluster.Cluster: @@ -799,6 +938,7 @@ def __call__( http_options = ( _BaseCloudRedisClusterRestTransport._BaseGetCluster._get_http_options() ) + request, metadata = self._interceptor.pre_get_cluster(request, metadata) transcoded_request = _BaseCloudRedisClusterRestTransport._BaseGetCluster._get_transcoded_request( http_options, request @@ -809,6 +949,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1beta1.CloudRedisClusterClient.GetCluster", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": "GetCluster", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._GetCluster._get_response( self._host, @@ -829,7 +996,29 @@ def __call__( pb_resp = cloud_redis_cluster.Cluster.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_cluster(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = cloud_redis_cluster.Cluster.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis.cluster_v1beta1.CloudRedisClusterClient.get_cluster", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": "GetCluster", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetClusterCertificateAuthority( @@ -867,7 +1056,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis_cluster.CertificateAuthority: r"""Call the get cluster certificate authority method over HTTP. @@ -879,8 +1068,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.cloud_redis_cluster.CertificateAuthority: @@ -890,6 +1081,7 @@ def __call__( http_options = ( _BaseCloudRedisClusterRestTransport._BaseGetClusterCertificateAuthority._get_http_options() ) + request, metadata = self._interceptor.pre_get_cluster_certificate_authority( request, metadata ) @@ -902,6 +1094,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1beta1.CloudRedisClusterClient.GetClusterCertificateAuthority", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": "GetClusterCertificateAuthority", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._GetClusterCertificateAuthority._get_response( self._host, @@ -922,7 +1141,31 @@ def __call__( pb_resp = cloud_redis_cluster.CertificateAuthority.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_cluster_certificate_authority(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = cloud_redis_cluster.CertificateAuthority.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis.cluster_v1beta1.CloudRedisClusterClient.get_cluster_certificate_authority", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": "GetClusterCertificateAuthority", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListClusters( @@ -959,7 +1202,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis_cluster.ListClustersResponse: r"""Call the list clusters method over HTTP. @@ -969,8 +1212,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.cloud_redis_cluster.ListClustersResponse: @@ -980,6 +1225,7 @@ def __call__( http_options = ( _BaseCloudRedisClusterRestTransport._BaseListClusters._get_http_options() ) + request, metadata = self._interceptor.pre_list_clusters(request, metadata) transcoded_request = _BaseCloudRedisClusterRestTransport._BaseListClusters._get_transcoded_request( http_options, request @@ -990,6 +1236,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1beta1.CloudRedisClusterClient.ListClusters", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": "ListClusters", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._ListClusters._get_response( self._host, @@ -1010,7 +1283,31 @@ def __call__( pb_resp = cloud_redis_cluster.ListClustersResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_clusters(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = cloud_redis_cluster.ListClustersResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis.cluster_v1beta1.CloudRedisClusterClient.list_clusters", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": "ListClusters", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateCluster( @@ -1049,7 +1346,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the update cluster method over HTTP. @@ -1059,8 +1356,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1073,6 +1372,7 @@ def __call__( http_options = ( _BaseCloudRedisClusterRestTransport._BaseUpdateCluster._get_http_options() ) + request, metadata = self._interceptor.pre_update_cluster(request, metadata) transcoded_request = _BaseCloudRedisClusterRestTransport._BaseUpdateCluster._get_transcoded_request( http_options, request @@ -1087,6 +1387,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1beta1.CloudRedisClusterClient.UpdateCluster", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": "UpdateCluster", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._UpdateCluster._get_response( self._host, @@ -1106,7 +1433,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_cluster(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis.cluster_v1beta1.CloudRedisClusterClient.update_cluster", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": "UpdateCluster", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property @@ -1201,7 +1550,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.Location: r"""Call the get location method over HTTP. @@ -1211,8 +1560,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: locations_pb2.Location: Response from GetLocation method. @@ -1221,6 +1572,7 @@ def __call__( http_options = ( _BaseCloudRedisClusterRestTransport._BaseGetLocation._get_http_options() ) + request, metadata = self._interceptor.pre_get_location(request, metadata) transcoded_request = _BaseCloudRedisClusterRestTransport._BaseGetLocation._get_transcoded_request( http_options, request @@ -1231,6 +1583,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1beta1.CloudRedisClusterClient.GetLocation", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": "GetLocation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._GetLocation._get_response( self._host, @@ -1250,6 +1629,27 @@ def __call__( resp = locations_pb2.Location() resp = json_format.Parse(content, resp) resp = self._interceptor.post_get_location(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis.cluster_v1beta1.CloudRedisClusterAsyncClient.GetLocation", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": "GetLocation", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property @@ -1291,7 +1691,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.ListLocationsResponse: r"""Call the list locations method over HTTP. @@ -1301,8 +1701,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: locations_pb2.ListLocationsResponse: Response from ListLocations method. @@ -1311,6 +1713,7 @@ def __call__( http_options = ( _BaseCloudRedisClusterRestTransport._BaseListLocations._get_http_options() ) + request, metadata = self._interceptor.pre_list_locations(request, metadata) transcoded_request = _BaseCloudRedisClusterRestTransport._BaseListLocations._get_transcoded_request( http_options, request @@ -1321,6 +1724,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1beta1.CloudRedisClusterClient.ListLocations", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": "ListLocations", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._ListLocations._get_response( self._host, @@ -1340,6 +1770,27 @@ def __call__( resp = locations_pb2.ListLocationsResponse() resp = json_format.Parse(content, resp) resp = self._interceptor.post_list_locations(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis.cluster_v1beta1.CloudRedisClusterAsyncClient.ListLocations", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": "ListLocations", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property @@ -1381,7 +1832,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Call the cancel operation method over HTTP. @@ -1391,13 +1842,16 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ http_options = ( _BaseCloudRedisClusterRestTransport._BaseCancelOperation._get_http_options() ) + request, metadata = self._interceptor.pre_cancel_operation( request, metadata ) @@ -1410,6 +1864,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1beta1.CloudRedisClusterClient.CancelOperation", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": "CancelOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._CancelOperation._get_response( self._host, @@ -1466,7 +1947,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Call the delete operation method over HTTP. @@ -1476,13 +1957,16 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ http_options = ( _BaseCloudRedisClusterRestTransport._BaseDeleteOperation._get_http_options() ) + request, metadata = self._interceptor.pre_delete_operation( request, metadata ) @@ -1495,6 +1979,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1beta1.CloudRedisClusterClient.DeleteOperation", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": "DeleteOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._DeleteOperation._get_response( self._host, @@ -1550,7 +2061,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the get operation method over HTTP. @@ -1560,8 +2071,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: operations_pb2.Operation: Response from GetOperation method. @@ -1570,6 +2083,7 @@ def __call__( http_options = ( _BaseCloudRedisClusterRestTransport._BaseGetOperation._get_http_options() ) + request, metadata = self._interceptor.pre_get_operation(request, metadata) transcoded_request = _BaseCloudRedisClusterRestTransport._BaseGetOperation._get_transcoded_request( http_options, request @@ -1580,6 +2094,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1beta1.CloudRedisClusterClient.GetOperation", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": "GetOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._GetOperation._get_response( self._host, @@ -1599,6 +2140,27 @@ def __call__( resp = operations_pb2.Operation() resp = json_format.Parse(content, resp) resp = self._interceptor.post_get_operation(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis.cluster_v1beta1.CloudRedisClusterAsyncClient.GetOperation", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": "GetOperation", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property @@ -1640,7 +2202,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Call the list operations method over HTTP. @@ -1650,8 +2212,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: operations_pb2.ListOperationsResponse: Response from ListOperations method. @@ -1660,6 +2224,7 @@ def __call__( http_options = ( _BaseCloudRedisClusterRestTransport._BaseListOperations._get_http_options() ) + request, metadata = self._interceptor.pre_list_operations(request, metadata) transcoded_request = _BaseCloudRedisClusterRestTransport._BaseListOperations._get_transcoded_request( http_options, request @@ -1670,6 +2235,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis.cluster_v1beta1.CloudRedisClusterClient.ListOperations", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": "ListOperations", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisClusterRestTransport._ListOperations._get_response( self._host, @@ -1689,6 +2281,27 @@ def __call__( resp = operations_pb2.ListOperationsResponse() resp = json_format.Parse(content, resp) resp = self._interceptor.post_list_operations(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis.cluster_v1beta1.CloudRedisClusterAsyncClient.ListOperations", + extra={ + "serviceName": "google.cloud.redis.cluster.v1beta1.CloudRedisCluster", + "rpcName": "ListOperations", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property diff --git a/packages/google-cloud-redis-cluster/samples/generated_samples/snippet_metadata_google.cloud.redis.cluster.v1.json b/packages/google-cloud-redis-cluster/samples/generated_samples/snippet_metadata_google.cloud.redis.cluster.v1.json index 4b2d29fd84d8..e63fbaacc385 100644 --- a/packages/google-cloud-redis-cluster/samples/generated_samples/snippet_metadata_google.cloud.redis.cluster.v1.json +++ b/packages/google-cloud-redis-cluster/samples/generated_samples/snippet_metadata_google.cloud.redis.cluster.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-redis-cluster", - "version": "0.1.10" + "version": "0.1.0" }, "snippets": [ { @@ -55,7 +55,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -143,7 +143,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -224,7 +224,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -304,7 +304,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -385,7 +385,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_cluster_v1.types.CertificateAuthority", @@ -465,7 +465,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_cluster_v1.types.CertificateAuthority", @@ -546,7 +546,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_cluster_v1.types.Cluster", @@ -626,7 +626,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_cluster_v1.types.Cluster", @@ -707,7 +707,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_cluster_v1.services.cloud_redis_cluster.pagers.ListClustersAsyncPager", @@ -787,7 +787,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_cluster_v1.services.cloud_redis_cluster.pagers.ListClustersPager", @@ -872,7 +872,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -956,7 +956,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", diff --git a/packages/google-cloud-redis-cluster/samples/generated_samples/snippet_metadata_google.cloud.redis.cluster.v1beta1.json b/packages/google-cloud-redis-cluster/samples/generated_samples/snippet_metadata_google.cloud.redis.cluster.v1beta1.json index 4760e34e310f..65c1106a88db 100644 --- a/packages/google-cloud-redis-cluster/samples/generated_samples/snippet_metadata_google.cloud.redis.cluster.v1beta1.json +++ b/packages/google-cloud-redis-cluster/samples/generated_samples/snippet_metadata_google.cloud.redis.cluster.v1beta1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-redis-cluster", - "version": "0.1.10" + "version": "0.1.0" }, "snippets": [ { @@ -55,7 +55,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -143,7 +143,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -224,7 +224,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -304,7 +304,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -385,7 +385,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_cluster_v1beta1.types.CertificateAuthority", @@ -465,7 +465,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_cluster_v1beta1.types.CertificateAuthority", @@ -546,7 +546,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_cluster_v1beta1.types.Cluster", @@ -626,7 +626,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_cluster_v1beta1.types.Cluster", @@ -707,7 +707,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_cluster_v1beta1.services.cloud_redis_cluster.pagers.ListClustersAsyncPager", @@ -787,7 +787,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_cluster_v1beta1.services.cloud_redis_cluster.pagers.ListClustersPager", @@ -872,7 +872,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -956,7 +956,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", diff --git a/packages/google-cloud-redis-cluster/tests/unit/gapic/redis_cluster_v1/test_cloud_redis_cluster.py b/packages/google-cloud-redis-cluster/tests/unit/gapic/redis_cluster_v1/test_cloud_redis_cluster.py index 5fdb46860d8c..4da6af6a0ea7 100644 --- a/packages/google-cloud-redis-cluster/tests/unit/gapic/redis_cluster_v1/test_cloud_redis_cluster.py +++ b/packages/google-cloud-redis-cluster/tests/unit/gapic/redis_cluster_v1/test_cloud_redis_cluster.py @@ -3484,6 +3484,7 @@ def test_list_clusters_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_clusters(request) @@ -3537,6 +3538,7 @@ def test_list_clusters_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_clusters(**mock_args) @@ -3730,6 +3732,7 @@ def test_get_cluster_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_cluster(request) @@ -3775,6 +3778,7 @@ def test_get_cluster_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_cluster(**mock_args) @@ -3909,6 +3913,7 @@ def test_update_cluster_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_cluster(request) @@ -3968,6 +3973,7 @@ def test_update_cluster_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_cluster(**mock_args) @@ -4103,6 +4109,7 @@ def test_delete_cluster_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_cluster(request) @@ -4146,6 +4153,7 @@ def test_delete_cluster_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_cluster(**mock_args) @@ -4292,6 +4300,7 @@ def test_create_cluster_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_cluster(request) @@ -4357,6 +4366,7 @@ def test_create_cluster_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_cluster(**mock_args) @@ -4494,6 +4504,7 @@ def test_get_cluster_certificate_authority_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_cluster_certificate_authority(request) @@ -4543,6 +4554,7 @@ def test_get_cluster_certificate_authority_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_cluster_certificate_authority(**mock_args) @@ -5019,6 +5031,7 @@ def test_list_clusters_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_clusters(request) @@ -5055,6 +5068,7 @@ def test_list_clusters_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_clusters(request) # Establish that the response is the type that we expect. @@ -5096,6 +5110,7 @@ def test_list_clusters_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = cloud_redis_cluster.ListClustersResponse.to_json( cloud_redis_cluster.ListClustersResponse() ) @@ -5142,6 +5157,7 @@ def test_get_cluster_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_cluster(request) @@ -5187,6 +5203,7 @@ def test_get_cluster_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_cluster(request) # Establish that the response is the type that we expect. @@ -5243,6 +5260,7 @@ def test_get_cluster_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = cloud_redis_cluster.Cluster.to_json( cloud_redis_cluster.Cluster() ) @@ -5291,6 +5309,7 @@ def test_update_cluster_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_cluster(request) @@ -5427,6 +5446,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_cluster(request) # Establish that the response is the type that we expect. @@ -5468,6 +5488,7 @@ def test_update_cluster_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -5512,6 +5533,7 @@ def test_delete_cluster_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_cluster(request) @@ -5542,6 +5564,7 @@ def test_delete_cluster_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_cluster(request) # Establish that the response is the type that we expect. @@ -5583,6 +5606,7 @@ def test_delete_cluster_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -5627,6 +5651,7 @@ def test_create_cluster_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_cluster(request) @@ -5761,6 +5786,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_cluster(request) # Establish that the response is the type that we expect. @@ -5802,6 +5828,7 @@ def test_create_cluster_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -5848,6 +5875,7 @@ def test_get_cluster_certificate_authority_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_cluster_certificate_authority(request) @@ -5885,6 +5913,7 @@ def test_get_cluster_certificate_authority_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_cluster_certificate_authority(request) # Establish that the response is the type that we expect. @@ -5927,6 +5956,7 @@ def test_get_cluster_certificate_authority_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = cloud_redis_cluster.CertificateAuthority.to_json( cloud_redis_cluster.CertificateAuthority() ) @@ -5973,6 +6003,7 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_location(request) @@ -6003,6 +6034,7 @@ def test_get_location_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_location(request) @@ -6031,6 +6063,7 @@ def test_list_locations_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_locations(request) @@ -6061,6 +6094,7 @@ def test_list_locations_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_locations(request) @@ -6091,6 +6125,7 @@ def test_cancel_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.cancel_operation(request) @@ -6121,6 +6156,7 @@ def test_cancel_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.cancel_operation(request) @@ -6151,6 +6187,7 @@ def test_delete_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_operation(request) @@ -6181,6 +6218,7 @@ def test_delete_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_operation(request) @@ -6211,6 +6249,7 @@ def test_get_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_operation(request) @@ -6241,6 +6280,7 @@ def test_get_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_operation(request) @@ -6271,6 +6311,7 @@ def test_list_operations_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_operations(request) @@ -6301,6 +6342,7 @@ def test_list_operations_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_operations(request) diff --git a/packages/google-cloud-redis-cluster/tests/unit/gapic/redis_cluster_v1beta1/test_cloud_redis_cluster.py b/packages/google-cloud-redis-cluster/tests/unit/gapic/redis_cluster_v1beta1/test_cloud_redis_cluster.py index d520191b1aec..9b5986dc0140 100644 --- a/packages/google-cloud-redis-cluster/tests/unit/gapic/redis_cluster_v1beta1/test_cloud_redis_cluster.py +++ b/packages/google-cloud-redis-cluster/tests/unit/gapic/redis_cluster_v1beta1/test_cloud_redis_cluster.py @@ -3484,6 +3484,7 @@ def test_list_clusters_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_clusters(request) @@ -3537,6 +3538,7 @@ def test_list_clusters_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_clusters(**mock_args) @@ -3731,6 +3733,7 @@ def test_get_cluster_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_cluster(request) @@ -3776,6 +3779,7 @@ def test_get_cluster_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_cluster(**mock_args) @@ -3911,6 +3915,7 @@ def test_update_cluster_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_cluster(request) @@ -3970,6 +3975,7 @@ def test_update_cluster_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_cluster(**mock_args) @@ -4105,6 +4111,7 @@ def test_delete_cluster_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_cluster(request) @@ -4148,6 +4155,7 @@ def test_delete_cluster_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_cluster(**mock_args) @@ -4295,6 +4303,7 @@ def test_create_cluster_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_cluster(request) @@ -4360,6 +4369,7 @@ def test_create_cluster_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_cluster(**mock_args) @@ -4498,6 +4508,7 @@ def test_get_cluster_certificate_authority_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_cluster_certificate_authority(request) @@ -4547,6 +4558,7 @@ def test_get_cluster_certificate_authority_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_cluster_certificate_authority(**mock_args) @@ -5023,6 +5035,7 @@ def test_list_clusters_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_clusters(request) @@ -5059,6 +5072,7 @@ def test_list_clusters_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_clusters(request) # Establish that the response is the type that we expect. @@ -5100,6 +5114,7 @@ def test_list_clusters_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = cloud_redis_cluster.ListClustersResponse.to_json( cloud_redis_cluster.ListClustersResponse() ) @@ -5146,6 +5161,7 @@ def test_get_cluster_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_cluster(request) @@ -5191,6 +5207,7 @@ def test_get_cluster_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_cluster(request) # Establish that the response is the type that we expect. @@ -5247,6 +5264,7 @@ def test_get_cluster_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = cloud_redis_cluster.Cluster.to_json( cloud_redis_cluster.Cluster() ) @@ -5295,6 +5313,7 @@ def test_update_cluster_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_cluster(request) @@ -5431,6 +5450,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_cluster(request) # Establish that the response is the type that we expect. @@ -5472,6 +5492,7 @@ def test_update_cluster_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -5516,6 +5537,7 @@ def test_delete_cluster_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_cluster(request) @@ -5546,6 +5568,7 @@ def test_delete_cluster_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_cluster(request) # Establish that the response is the type that we expect. @@ -5587,6 +5610,7 @@ def test_delete_cluster_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -5631,6 +5655,7 @@ def test_create_cluster_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_cluster(request) @@ -5765,6 +5790,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_cluster(request) # Establish that the response is the type that we expect. @@ -5806,6 +5832,7 @@ def test_create_cluster_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -5852,6 +5879,7 @@ def test_get_cluster_certificate_authority_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_cluster_certificate_authority(request) @@ -5889,6 +5917,7 @@ def test_get_cluster_certificate_authority_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_cluster_certificate_authority(request) # Establish that the response is the type that we expect. @@ -5931,6 +5960,7 @@ def test_get_cluster_certificate_authority_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = cloud_redis_cluster.CertificateAuthority.to_json( cloud_redis_cluster.CertificateAuthority() ) @@ -5977,6 +6007,7 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_location(request) @@ -6007,6 +6038,7 @@ def test_get_location_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_location(request) @@ -6035,6 +6067,7 @@ def test_list_locations_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_locations(request) @@ -6065,6 +6098,7 @@ def test_list_locations_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_locations(request) @@ -6095,6 +6129,7 @@ def test_cancel_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.cancel_operation(request) @@ -6125,6 +6160,7 @@ def test_cancel_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.cancel_operation(request) @@ -6155,6 +6191,7 @@ def test_delete_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_operation(request) @@ -6185,6 +6222,7 @@ def test_delete_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_operation(request) @@ -6215,6 +6253,7 @@ def test_get_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_operation(request) @@ -6245,6 +6284,7 @@ def test_get_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_operation(request) @@ -6275,6 +6315,7 @@ def test_list_operations_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_operations(request) @@ -6305,6 +6346,7 @@ def test_list_operations_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_operations(request) diff --git a/packages/google-cloud-redis/google/cloud/redis/gapic_version.py b/packages/google-cloud-redis/google/cloud/redis/gapic_version.py index 1230672bab9e..558c8aab67c5 100644 --- a/packages/google-cloud-redis/google/cloud/redis/gapic_version.py +++ b/packages/google-cloud-redis/google/cloud/redis/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.16.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-redis/google/cloud/redis_v1/gapic_version.py b/packages/google-cloud-redis/google/cloud/redis_v1/gapic_version.py index 1230672bab9e..558c8aab67c5 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1/gapic_version.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.16.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/async_client.py b/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/async_client.py index 2d8f440212ec..de10d33f58e0 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/async_client.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -57,6 +58,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, CloudRedisTransport from .transports.grpc_asyncio import CloudRedisGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class CloudRedisAsyncClient: """Configures and manages Cloud Memorystore for Redis instances @@ -277,6 +287,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.redis_v1.CloudRedisAsyncClient`.", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.redis.v1.CloudRedis", + "credentialsType": None, + }, + ) + async def list_instances( self, request: Optional[Union[cloud_redis.ListInstancesRequest, dict]] = None, @@ -284,7 +316,7 @@ async def list_instances( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListInstancesAsyncPager: r"""Lists all Redis instances owned by a project in either the specified location (region) or all locations. @@ -340,8 +372,10 @@ async def sample_list_instances(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_v1.services.cloud_redis.pagers.ListInstancesAsyncPager: @@ -416,7 +450,7 @@ async def get_instance( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis.Instance: r"""Gets the details of a specific Redis instance. @@ -461,8 +495,10 @@ async def sample_get_instance(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_v1.types.Instance: @@ -521,7 +557,7 @@ async def get_instance_auth_string( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis.InstanceAuthString: r"""Gets the AUTH string for a Redis instance. If AUTH is not enabled for the instance the response will be empty. @@ -569,8 +605,10 @@ async def sample_get_instance_auth_string(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_v1.types.InstanceAuthString: @@ -631,7 +669,7 @@ async def create_instance( instance: Optional[cloud_redis.Instance] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Creates a Redis instance based on the specified tier and memory size. @@ -720,8 +758,10 @@ async def sample_create_instance(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -798,7 +838,7 @@ async def update_instance( instance: Optional[cloud_redis.Instance] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Updates the metadata and configuration of a specific Redis instance. @@ -871,8 +911,10 @@ async def sample_update_instance(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -949,7 +991,7 @@ async def upgrade_instance( redis_version: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Upgrades Redis instance to the newer Redis version specified in the request. @@ -1007,8 +1049,10 @@ async def sample_upgrade_instance(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1083,7 +1127,7 @@ async def import_instance( input_config: Optional[cloud_redis.InputConfig] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Import a Redis RDB snapshot file from Cloud Storage into a Redis instance. @@ -1151,8 +1195,10 @@ async def sample_import_instance(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1227,7 +1273,7 @@ async def export_instance( output_config: Optional[cloud_redis.OutputConfig] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Export Redis instance data into a Redis RDB format file in Cloud Storage. @@ -1292,8 +1338,10 @@ async def sample_export_instance(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1370,7 +1418,7 @@ async def failover_instance( ] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Initiates a failover of the primary node to current replica node for a specific STANDARD tier Cloud @@ -1429,8 +1477,10 @@ async def sample_failover_instance(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1504,7 +1554,7 @@ async def delete_instance( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a specific Redis instance. Instance stops serving and data is deleted. @@ -1554,8 +1604,10 @@ async def sample_delete_instance(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1638,7 +1690,7 @@ async def reschedule_maintenance( schedule_time: Optional[timestamp_pb2.Timestamp] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Reschedule maintenance for a given instance in a given project and location. @@ -1704,8 +1756,10 @@ async def sample_reschedule_maintenance(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1780,7 +1834,7 @@ async def list_operations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Lists operations that match the specified filter in the request. @@ -1791,8 +1845,10 @@ async def list_operations( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.ListOperationsResponse: Response message for ``ListOperations`` method. @@ -1833,7 +1889,7 @@ async def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -1844,8 +1900,10 @@ async def get_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. @@ -1886,7 +1944,7 @@ async def delete_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Deletes a long-running operation. @@ -1902,8 +1960,10 @@ async def delete_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: None """ @@ -1940,7 +2000,7 @@ async def cancel_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Starts asynchronous cancellation on a long-running operation. @@ -1955,8 +2015,10 @@ async def cancel_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: None """ @@ -1993,7 +2055,7 @@ async def get_location( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.Location: r"""Gets information about a location. @@ -2004,8 +2066,10 @@ async def get_location( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.Location: Location object. @@ -2046,7 +2110,7 @@ async def list_locations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.ListLocationsResponse: r"""Lists information about the supported locations for this service. @@ -2057,8 +2121,10 @@ async def list_locations( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.ListLocationsResponse: Response message for ``ListLocations`` method. diff --git a/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/client.py b/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/client.py index a7183e652897..728d00e4a1e5 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/client.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.location import locations_pb2 # type: ignore @@ -605,6 +615,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -667,6 +681,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.redis_v1.CloudRedisClient`.", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.redis.v1.CloudRedis", + "credentialsType": None, + }, + ) + def list_instances( self, request: Optional[Union[cloud_redis.ListInstancesRequest, dict]] = None, @@ -674,7 +711,7 @@ def list_instances( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListInstancesPager: r"""Lists all Redis instances owned by a project in either the specified location (region) or all locations. @@ -730,8 +767,10 @@ def sample_list_instances(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_v1.services.cloud_redis.pagers.ListInstancesPager: @@ -803,7 +842,7 @@ def get_instance( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis.Instance: r"""Gets the details of a specific Redis instance. @@ -848,8 +887,10 @@ def sample_get_instance(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_v1.types.Instance: @@ -905,7 +946,7 @@ def get_instance_auth_string( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis.InstanceAuthString: r"""Gets the AUTH string for a Redis instance. If AUTH is not enabled for the instance the response will be empty. @@ -953,8 +994,10 @@ def sample_get_instance_auth_string(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_v1.types.InstanceAuthString: @@ -1012,7 +1055,7 @@ def create_instance( instance: Optional[cloud_redis.Instance] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Creates a Redis instance based on the specified tier and memory size. @@ -1101,8 +1144,10 @@ def sample_create_instance(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1176,7 +1221,7 @@ def update_instance( instance: Optional[cloud_redis.Instance] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Updates the metadata and configuration of a specific Redis instance. @@ -1249,8 +1294,10 @@ def sample_update_instance(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1324,7 +1371,7 @@ def upgrade_instance( redis_version: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Upgrades Redis instance to the newer Redis version specified in the request. @@ -1382,8 +1429,10 @@ def sample_upgrade_instance(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1455,7 +1504,7 @@ def import_instance( input_config: Optional[cloud_redis.InputConfig] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Import a Redis RDB snapshot file from Cloud Storage into a Redis instance. @@ -1523,8 +1572,10 @@ def sample_import_instance(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1596,7 +1647,7 @@ def export_instance( output_config: Optional[cloud_redis.OutputConfig] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Export Redis instance data into a Redis RDB format file in Cloud Storage. @@ -1661,8 +1712,10 @@ def sample_export_instance(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1736,7 +1789,7 @@ def failover_instance( ] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Initiates a failover of the primary node to current replica node for a specific STANDARD tier Cloud @@ -1795,8 +1848,10 @@ def sample_failover_instance(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1867,7 +1922,7 @@ def delete_instance( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Deletes a specific Redis instance. Instance stops serving and data is deleted. @@ -1917,8 +1972,10 @@ def sample_delete_instance(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1998,7 +2055,7 @@ def reschedule_maintenance( schedule_time: Optional[timestamp_pb2.Timestamp] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Reschedule maintenance for a given instance in a given project and location. @@ -2064,8 +2121,10 @@ def sample_reschedule_maintenance(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -2150,7 +2209,7 @@ def list_operations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Lists operations that match the specified filter in the request. @@ -2161,8 +2220,10 @@ def list_operations( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.ListOperationsResponse: Response message for ``ListOperations`` method. @@ -2203,7 +2264,7 @@ def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -2214,8 +2275,10 @@ def get_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. @@ -2256,7 +2319,7 @@ def delete_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Deletes a long-running operation. @@ -2272,8 +2335,10 @@ def delete_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: None """ @@ -2310,7 +2375,7 @@ def cancel_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Starts asynchronous cancellation on a long-running operation. @@ -2325,8 +2390,10 @@ def cancel_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: None """ @@ -2363,7 +2430,7 @@ def get_location( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.Location: r"""Gets information about a location. @@ -2374,8 +2441,10 @@ def get_location( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.Location: Location object. @@ -2416,7 +2485,7 @@ def list_locations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.ListLocationsResponse: r"""Lists information about the supported locations for this service. @@ -2427,8 +2496,10 @@ def list_locations( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.location_pb2.ListLocationsResponse: Response message for ``ListLocations`` method. diff --git a/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/pagers.py b/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/pagers.py index 4291ea1f45e9..7942c1e56ca1 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/pagers.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -81,8 +81,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = cloud_redis.ListInstancesRequest(request) @@ -141,7 +143,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -155,8 +157,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = cloud_redis.ListInstancesRequest(request) diff --git a/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py b/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py index 5048e4f4242e..3385355475af 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -22,12 +25,90 @@ from google.auth.transport.grpc import SslCredentials # type: ignore from google.cloud.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.redis_v1.types import cloud_redis from .base import DEFAULT_CLIENT_INFO, CloudRedisTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class CloudRedisGrpcTransport(CloudRedisTransport): """gRPC backend transport for CloudRedis. @@ -202,7 +283,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -266,7 +352,9 @@ def operations_client(self) -> operations_v1.OperationsClient: """ # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + self._operations_client = operations_v1.OperationsClient( + self._logged_channel + ) # Return the client from cache. return self._operations_client @@ -301,7 +389,7 @@ def list_instances( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_instances" not in self._stubs: - self._stubs["list_instances"] = self.grpc_channel.unary_unary( + self._stubs["list_instances"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/ListInstances", request_serializer=cloud_redis.ListInstancesRequest.serialize, response_deserializer=cloud_redis.ListInstancesResponse.deserialize, @@ -327,7 +415,7 @@ def get_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_instance" not in self._stubs: - self._stubs["get_instance"] = self.grpc_channel.unary_unary( + self._stubs["get_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/GetInstance", request_serializer=cloud_redis.GetInstanceRequest.serialize, response_deserializer=cloud_redis.Instance.deserialize, @@ -358,7 +446,7 @@ def get_instance_auth_string( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_instance_auth_string" not in self._stubs: - self._stubs["get_instance_auth_string"] = self.grpc_channel.unary_unary( + self._stubs["get_instance_auth_string"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/GetInstanceAuthString", request_serializer=cloud_redis.GetInstanceAuthStringRequest.serialize, response_deserializer=cloud_redis.InstanceAuthString.deserialize, @@ -397,7 +485,7 @@ def create_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_instance" not in self._stubs: - self._stubs["create_instance"] = self.grpc_channel.unary_unary( + self._stubs["create_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/CreateInstance", request_serializer=cloud_redis.CreateInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -428,7 +516,7 @@ def update_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_instance" not in self._stubs: - self._stubs["update_instance"] = self.grpc_channel.unary_unary( + self._stubs["update_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/UpdateInstance", request_serializer=cloud_redis.UpdateInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -455,7 +543,7 @@ def upgrade_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "upgrade_instance" not in self._stubs: - self._stubs["upgrade_instance"] = self.grpc_channel.unary_unary( + self._stubs["upgrade_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/UpgradeInstance", request_serializer=cloud_redis.UpgradeInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -489,7 +577,7 @@ def import_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "import_instance" not in self._stubs: - self._stubs["import_instance"] = self.grpc_channel.unary_unary( + self._stubs["import_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/ImportInstance", request_serializer=cloud_redis.ImportInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -520,7 +608,7 @@ def export_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "export_instance" not in self._stubs: - self._stubs["export_instance"] = self.grpc_channel.unary_unary( + self._stubs["export_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/ExportInstance", request_serializer=cloud_redis.ExportInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -548,7 +636,7 @@ def failover_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "failover_instance" not in self._stubs: - self._stubs["failover_instance"] = self.grpc_channel.unary_unary( + self._stubs["failover_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/FailoverInstance", request_serializer=cloud_redis.FailoverInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -575,7 +663,7 @@ def delete_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_instance" not in self._stubs: - self._stubs["delete_instance"] = self.grpc_channel.unary_unary( + self._stubs["delete_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/DeleteInstance", request_serializer=cloud_redis.DeleteInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -602,7 +690,7 @@ def reschedule_maintenance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "reschedule_maintenance" not in self._stubs: - self._stubs["reschedule_maintenance"] = self.grpc_channel.unary_unary( + self._stubs["reschedule_maintenance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/RescheduleMaintenance", request_serializer=cloud_redis.RescheduleMaintenanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -610,7 +698,7 @@ def reschedule_maintenance( return self._stubs["reschedule_maintenance"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def delete_operation( @@ -622,7 +710,7 @@ def delete_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_operation" not in self._stubs: - self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + self._stubs["delete_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/DeleteOperation", request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, response_deserializer=None, @@ -639,7 +727,7 @@ def cancel_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "cancel_operation" not in self._stubs: - self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + self._stubs["cancel_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/CancelOperation", request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, response_deserializer=None, @@ -656,7 +744,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, @@ -675,7 +763,7 @@ def list_operations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_operations" not in self._stubs: - self._stubs["list_operations"] = self.grpc_channel.unary_unary( + self._stubs["list_operations"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/ListOperations", request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, response_deserializer=operations_pb2.ListOperationsResponse.FromString, @@ -694,7 +782,7 @@ def list_locations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_locations" not in self._stubs: - self._stubs["list_locations"] = self.grpc_channel.unary_unary( + self._stubs["list_locations"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/ListLocations", request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, response_deserializer=locations_pb2.ListLocationsResponse.FromString, @@ -711,7 +799,7 @@ def get_location( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_location" not in self._stubs: - self._stubs["get_location"] = self.grpc_channel.unary_unary( + self._stubs["get_location"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/GetLocation", request_serializer=locations_pb2.GetLocationRequest.SerializeToString, response_deserializer=locations_pb2.Location.FromString, diff --git a/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py b/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py index 80737763497f..26b3f12f8425 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -24,14 +27,93 @@ from google.auth.transport.grpc import SslCredentials # type: ignore from google.cloud.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.redis_v1.types import cloud_redis from .base import DEFAULT_CLIENT_INFO, CloudRedisTransport from .grpc import CloudRedisGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class CloudRedisGrpcAsyncIOTransport(CloudRedisTransport): """gRPC AsyncIO backend transport for CloudRedis. @@ -249,10 +331,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -275,7 +360,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel + self._logged_channel ) # Return the client from cache. @@ -311,7 +396,7 @@ def list_instances( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_instances" not in self._stubs: - self._stubs["list_instances"] = self.grpc_channel.unary_unary( + self._stubs["list_instances"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/ListInstances", request_serializer=cloud_redis.ListInstancesRequest.serialize, response_deserializer=cloud_redis.ListInstancesResponse.deserialize, @@ -337,7 +422,7 @@ def get_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_instance" not in self._stubs: - self._stubs["get_instance"] = self.grpc_channel.unary_unary( + self._stubs["get_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/GetInstance", request_serializer=cloud_redis.GetInstanceRequest.serialize, response_deserializer=cloud_redis.Instance.deserialize, @@ -369,7 +454,7 @@ def get_instance_auth_string( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_instance_auth_string" not in self._stubs: - self._stubs["get_instance_auth_string"] = self.grpc_channel.unary_unary( + self._stubs["get_instance_auth_string"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/GetInstanceAuthString", request_serializer=cloud_redis.GetInstanceAuthStringRequest.serialize, response_deserializer=cloud_redis.InstanceAuthString.deserialize, @@ -410,7 +495,7 @@ def create_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_instance" not in self._stubs: - self._stubs["create_instance"] = self.grpc_channel.unary_unary( + self._stubs["create_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/CreateInstance", request_serializer=cloud_redis.CreateInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -443,7 +528,7 @@ def update_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_instance" not in self._stubs: - self._stubs["update_instance"] = self.grpc_channel.unary_unary( + self._stubs["update_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/UpdateInstance", request_serializer=cloud_redis.UpdateInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -472,7 +557,7 @@ def upgrade_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "upgrade_instance" not in self._stubs: - self._stubs["upgrade_instance"] = self.grpc_channel.unary_unary( + self._stubs["upgrade_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/UpgradeInstance", request_serializer=cloud_redis.UpgradeInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -508,7 +593,7 @@ def import_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "import_instance" not in self._stubs: - self._stubs["import_instance"] = self.grpc_channel.unary_unary( + self._stubs["import_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/ImportInstance", request_serializer=cloud_redis.ImportInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -541,7 +626,7 @@ def export_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "export_instance" not in self._stubs: - self._stubs["export_instance"] = self.grpc_channel.unary_unary( + self._stubs["export_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/ExportInstance", request_serializer=cloud_redis.ExportInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -571,7 +656,7 @@ def failover_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "failover_instance" not in self._stubs: - self._stubs["failover_instance"] = self.grpc_channel.unary_unary( + self._stubs["failover_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/FailoverInstance", request_serializer=cloud_redis.FailoverInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -600,7 +685,7 @@ def delete_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_instance" not in self._stubs: - self._stubs["delete_instance"] = self.grpc_channel.unary_unary( + self._stubs["delete_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/DeleteInstance", request_serializer=cloud_redis.DeleteInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -629,7 +714,7 @@ def reschedule_maintenance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "reschedule_maintenance" not in self._stubs: - self._stubs["reschedule_maintenance"] = self.grpc_channel.unary_unary( + self._stubs["reschedule_maintenance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1.CloudRedis/RescheduleMaintenance", request_serializer=cloud_redis.RescheduleMaintenanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -732,7 +817,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: @@ -748,7 +833,7 @@ def delete_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_operation" not in self._stubs: - self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + self._stubs["delete_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/DeleteOperation", request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, response_deserializer=None, @@ -765,7 +850,7 @@ def cancel_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "cancel_operation" not in self._stubs: - self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + self._stubs["cancel_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/CancelOperation", request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, response_deserializer=None, @@ -782,7 +867,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, @@ -801,7 +886,7 @@ def list_operations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_operations" not in self._stubs: - self._stubs["list_operations"] = self.grpc_channel.unary_unary( + self._stubs["list_operations"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/ListOperations", request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, response_deserializer=operations_pb2.ListOperationsResponse.FromString, @@ -820,7 +905,7 @@ def list_locations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_locations" not in self._stubs: - self._stubs["list_locations"] = self.grpc_channel.unary_unary( + self._stubs["list_locations"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/ListLocations", request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, response_deserializer=locations_pb2.ListLocationsResponse.FromString, @@ -837,7 +922,7 @@ def get_location( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_location" not in self._stubs: - self._stubs["get_location"] = self.grpc_channel.unary_unary( + self._stubs["get_location"] = self._logged_channel.unary_unary( "/google.cloud.location.Locations/GetLocation", request_serializer=locations_pb2.GetLocationRequest.SerializeToString, response_deserializer=locations_pb2.Location.FromString, diff --git a/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/transports/rest.py b/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/transports/rest.py index 004b3a441adc..69c204dddbf3 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/transports/rest.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1/services/cloud_redis/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -39,6 +39,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -159,8 +167,10 @@ def post_upgrade_instance(self, response): def pre_create_instance( self, request: cloud_redis.CreateInstanceRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis.CreateInstanceRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis.CreateInstanceRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for create_instance Override in a subclass to manipulate the request or metadata @@ -182,8 +192,10 @@ def post_create_instance( def pre_delete_instance( self, request: cloud_redis.DeleteInstanceRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis.DeleteInstanceRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis.DeleteInstanceRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for delete_instance Override in a subclass to manipulate the request or metadata @@ -205,8 +217,10 @@ def post_delete_instance( def pre_export_instance( self, request: cloud_redis.ExportInstanceRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis.ExportInstanceRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis.ExportInstanceRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for export_instance Override in a subclass to manipulate the request or metadata @@ -228,8 +242,10 @@ def post_export_instance( def pre_failover_instance( self, request: cloud_redis.FailoverInstanceRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis.FailoverInstanceRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis.FailoverInstanceRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for failover_instance Override in a subclass to manipulate the request or metadata @@ -251,8 +267,8 @@ def post_failover_instance( def pre_get_instance( self, request: cloud_redis.GetInstanceRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis.GetInstanceRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[cloud_redis.GetInstanceRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for get_instance Override in a subclass to manipulate the request or metadata @@ -272,8 +288,11 @@ def post_get_instance(self, response: cloud_redis.Instance) -> cloud_redis.Insta def pre_get_instance_auth_string( self, request: cloud_redis.GetInstanceAuthStringRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis.GetInstanceAuthStringRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis.GetInstanceAuthStringRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for get_instance_auth_string Override in a subclass to manipulate the request or metadata @@ -295,8 +314,10 @@ def post_get_instance_auth_string( def pre_import_instance( self, request: cloud_redis.ImportInstanceRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis.ImportInstanceRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis.ImportInstanceRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for import_instance Override in a subclass to manipulate the request or metadata @@ -318,8 +339,10 @@ def post_import_instance( def pre_list_instances( self, request: cloud_redis.ListInstancesRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis.ListInstancesRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis.ListInstancesRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_instances Override in a subclass to manipulate the request or metadata @@ -341,8 +364,11 @@ def post_list_instances( def pre_reschedule_maintenance( self, request: cloud_redis.RescheduleMaintenanceRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis.RescheduleMaintenanceRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis.RescheduleMaintenanceRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for reschedule_maintenance Override in a subclass to manipulate the request or metadata @@ -364,8 +390,10 @@ def post_reschedule_maintenance( def pre_update_instance( self, request: cloud_redis.UpdateInstanceRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis.UpdateInstanceRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis.UpdateInstanceRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for update_instance Override in a subclass to manipulate the request or metadata @@ -387,8 +415,10 @@ def post_update_instance( def pre_upgrade_instance( self, request: cloud_redis.UpgradeInstanceRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis.UpgradeInstanceRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis.UpgradeInstanceRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for upgrade_instance Override in a subclass to manipulate the request or metadata @@ -410,8 +440,10 @@ def post_upgrade_instance( def pre_get_location( self, request: locations_pb2.GetLocationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[locations_pb2.GetLocationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + locations_pb2.GetLocationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_location Override in a subclass to manipulate the request or metadata @@ -433,8 +465,10 @@ def post_get_location( def pre_list_locations( self, request: locations_pb2.ListLocationsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[locations_pb2.ListLocationsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + locations_pb2.ListLocationsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_locations Override in a subclass to manipulate the request or metadata @@ -456,8 +490,10 @@ def post_list_locations( def pre_cancel_operation( self, request: operations_pb2.CancelOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.CancelOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.CancelOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for cancel_operation Override in a subclass to manipulate the request or metadata @@ -477,8 +513,10 @@ def post_cancel_operation(self, response: None) -> None: def pre_delete_operation( self, request: operations_pb2.DeleteOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.DeleteOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.DeleteOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for delete_operation Override in a subclass to manipulate the request or metadata @@ -498,8 +536,10 @@ def post_delete_operation(self, response: None) -> None: def pre_get_operation( self, request: operations_pb2.GetOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.GetOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.GetOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_operation Override in a subclass to manipulate the request or metadata @@ -521,8 +561,10 @@ def post_get_operation( def pre_list_operations( self, request: operations_pb2.ListOperationsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.ListOperationsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.ListOperationsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_operations Override in a subclass to manipulate the request or metadata @@ -736,7 +778,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the create instance method over HTTP. @@ -747,8 +789,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -761,6 +805,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseCreateInstance._get_http_options() ) + request, metadata = self._interceptor.pre_create_instance(request, metadata) transcoded_request = _BaseCloudRedisRestTransport._BaseCreateInstance._get_transcoded_request( http_options, request @@ -779,6 +824,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1.CloudRedisClient.CreateInstance", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "CreateInstance", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._CreateInstance._get_response( self._host, @@ -798,7 +870,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_instance(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1.CloudRedisClient.create_instance", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "CreateInstance", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DeleteInstance( @@ -835,7 +929,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the delete instance method over HTTP. @@ -846,8 +940,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -860,6 +956,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseDeleteInstance._get_http_options() ) + request, metadata = self._interceptor.pre_delete_instance(request, metadata) transcoded_request = _BaseCloudRedisRestTransport._BaseDeleteInstance._get_transcoded_request( http_options, request @@ -872,6 +969,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1.CloudRedisClient.DeleteInstance", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "DeleteInstance", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._DeleteInstance._get_response( self._host, @@ -890,7 +1014,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_delete_instance(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1.CloudRedisClient.delete_instance", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "DeleteInstance", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ExportInstance( @@ -928,7 +1074,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the export instance method over HTTP. @@ -939,8 +1085,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -953,6 +1101,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseExportInstance._get_http_options() ) + request, metadata = self._interceptor.pre_export_instance(request, metadata) transcoded_request = _BaseCloudRedisRestTransport._BaseExportInstance._get_transcoded_request( http_options, request @@ -971,6 +1120,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1.CloudRedisClient.ExportInstance", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "ExportInstance", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._ExportInstance._get_response( self._host, @@ -990,7 +1166,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_export_instance(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1.CloudRedisClient.export_instance", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "ExportInstance", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _FailoverInstance( @@ -1028,7 +1226,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the failover instance method over HTTP. @@ -1039,8 +1237,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1053,6 +1253,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseFailoverInstance._get_http_options() ) + request, metadata = self._interceptor.pre_failover_instance( request, metadata ) @@ -1069,6 +1270,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1.CloudRedisClient.FailoverInstance", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "FailoverInstance", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._FailoverInstance._get_response( self._host, @@ -1088,7 +1316,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_failover_instance(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1.CloudRedisClient.failover_instance", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "FailoverInstance", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetInstance( @@ -1125,7 +1375,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis.Instance: r"""Call the get instance method over HTTP. @@ -1136,8 +1386,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.cloud_redis.Instance: @@ -1147,6 +1399,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseGetInstance._get_http_options() ) + request, metadata = self._interceptor.pre_get_instance(request, metadata) transcoded_request = ( _BaseCloudRedisRestTransport._BaseGetInstance._get_transcoded_request( @@ -1161,6 +1414,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1.CloudRedisClient.GetInstance", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "GetInstance", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._GetInstance._get_response( self._host, @@ -1181,7 +1461,29 @@ def __call__( pb_resp = cloud_redis.Instance.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_instance(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = cloud_redis.Instance.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1.CloudRedisClient.get_instance", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "GetInstance", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetInstanceAuthString( @@ -1218,7 +1520,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis.InstanceAuthString: r"""Call the get instance auth string method over HTTP. @@ -1229,8 +1531,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.cloud_redis.InstanceAuthString: @@ -1240,6 +1544,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseGetInstanceAuthString._get_http_options() ) + request, metadata = self._interceptor.pre_get_instance_auth_string( request, metadata ) @@ -1252,6 +1557,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1.CloudRedisClient.GetInstanceAuthString", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "GetInstanceAuthString", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._GetInstanceAuthString._get_response( self._host, @@ -1272,7 +1604,29 @@ def __call__( pb_resp = cloud_redis.InstanceAuthString.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_instance_auth_string(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = cloud_redis.InstanceAuthString.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1.CloudRedisClient.get_instance_auth_string", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "GetInstanceAuthString", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ImportInstance( @@ -1310,7 +1664,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the import instance method over HTTP. @@ -1321,8 +1675,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1335,6 +1691,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseImportInstance._get_http_options() ) + request, metadata = self._interceptor.pre_import_instance(request, metadata) transcoded_request = _BaseCloudRedisRestTransport._BaseImportInstance._get_transcoded_request( http_options, request @@ -1353,6 +1710,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1.CloudRedisClient.ImportInstance", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "ImportInstance", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._ImportInstance._get_response( self._host, @@ -1372,7 +1756,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_import_instance(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1.CloudRedisClient.import_instance", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "ImportInstance", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListInstances( @@ -1409,7 +1815,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis.ListInstancesResponse: r"""Call the list instances method over HTTP. @@ -1420,8 +1826,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.cloud_redis.ListInstancesResponse: @@ -1433,6 +1841,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseListInstances._get_http_options() ) + request, metadata = self._interceptor.pre_list_instances(request, metadata) transcoded_request = ( _BaseCloudRedisRestTransport._BaseListInstances._get_transcoded_request( @@ -1447,6 +1856,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1.CloudRedisClient.ListInstances", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "ListInstances", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._ListInstances._get_response( self._host, @@ -1467,7 +1903,31 @@ def __call__( pb_resp = cloud_redis.ListInstancesResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_instances(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = cloud_redis.ListInstancesResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1.CloudRedisClient.list_instances", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "ListInstances", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _RescheduleMaintenance( @@ -1505,7 +1965,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the reschedule maintenance method over HTTP. @@ -1516,8 +1976,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1530,6 +1992,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseRescheduleMaintenance._get_http_options() ) + request, metadata = self._interceptor.pre_reschedule_maintenance( request, metadata ) @@ -1546,6 +2009,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1.CloudRedisClient.RescheduleMaintenance", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "RescheduleMaintenance", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._RescheduleMaintenance._get_response( self._host, @@ -1565,7 +2055,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_reschedule_maintenance(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1.CloudRedisClient.reschedule_maintenance", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "RescheduleMaintenance", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateInstance( @@ -1603,7 +2115,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the update instance method over HTTP. @@ -1614,8 +2126,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1628,6 +2142,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseUpdateInstance._get_http_options() ) + request, metadata = self._interceptor.pre_update_instance(request, metadata) transcoded_request = _BaseCloudRedisRestTransport._BaseUpdateInstance._get_transcoded_request( http_options, request @@ -1646,6 +2161,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1.CloudRedisClient.UpdateInstance", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "UpdateInstance", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._UpdateInstance._get_response( self._host, @@ -1665,7 +2207,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_instance(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1.CloudRedisClient.update_instance", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "UpdateInstance", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpgradeInstance( @@ -1703,7 +2267,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the upgrade instance method over HTTP. @@ -1714,8 +2278,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1728,6 +2294,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseUpgradeInstance._get_http_options() ) + request, metadata = self._interceptor.pre_upgrade_instance( request, metadata ) @@ -1744,6 +2311,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1.CloudRedisClient.UpgradeInstance", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "UpgradeInstance", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._UpgradeInstance._get_response( self._host, @@ -1763,7 +2357,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_upgrade_instance(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1.CloudRedisClient.upgrade_instance", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "UpgradeInstance", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property @@ -1896,7 +2512,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.Location: r"""Call the get location method over HTTP. @@ -1906,8 +2522,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: locations_pb2.Location: Response from GetLocation method. @@ -1916,6 +2534,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseGetLocation._get_http_options() ) + request, metadata = self._interceptor.pre_get_location(request, metadata) transcoded_request = ( _BaseCloudRedisRestTransport._BaseGetLocation._get_transcoded_request( @@ -1930,6 +2549,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1.CloudRedisClient.GetLocation", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "GetLocation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._GetLocation._get_response( self._host, @@ -1949,6 +2595,27 @@ def __call__( resp = locations_pb2.Location() resp = json_format.Parse(content, resp) resp = self._interceptor.post_get_location(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1.CloudRedisAsyncClient.GetLocation", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "GetLocation", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property @@ -1989,7 +2656,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> locations_pb2.ListLocationsResponse: r"""Call the list locations method over HTTP. @@ -1999,8 +2666,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: locations_pb2.ListLocationsResponse: Response from ListLocations method. @@ -2009,6 +2678,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseListLocations._get_http_options() ) + request, metadata = self._interceptor.pre_list_locations(request, metadata) transcoded_request = ( _BaseCloudRedisRestTransport._BaseListLocations._get_transcoded_request( @@ -2023,6 +2693,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1.CloudRedisClient.ListLocations", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "ListLocations", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._ListLocations._get_response( self._host, @@ -2042,6 +2739,27 @@ def __call__( resp = locations_pb2.ListLocationsResponse() resp = json_format.Parse(content, resp) resp = self._interceptor.post_list_locations(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1.CloudRedisAsyncClient.ListLocations", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "ListLocations", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property @@ -2082,7 +2800,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Call the cancel operation method over HTTP. @@ -2092,13 +2810,16 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ http_options = ( _BaseCloudRedisRestTransport._BaseCancelOperation._get_http_options() ) + request, metadata = self._interceptor.pre_cancel_operation( request, metadata ) @@ -2111,6 +2832,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1.CloudRedisClient.CancelOperation", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "CancelOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._CancelOperation._get_response( self._host, @@ -2166,7 +2914,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> None: r"""Call the delete operation method over HTTP. @@ -2176,13 +2924,16 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ http_options = ( _BaseCloudRedisRestTransport._BaseDeleteOperation._get_http_options() ) + request, metadata = self._interceptor.pre_delete_operation( request, metadata ) @@ -2195,6 +2946,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1.CloudRedisClient.DeleteOperation", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "DeleteOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._DeleteOperation._get_response( self._host, @@ -2250,7 +3028,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the get operation method over HTTP. @@ -2260,8 +3038,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: operations_pb2.Operation: Response from GetOperation method. @@ -2270,6 +3050,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseGetOperation._get_http_options() ) + request, metadata = self._interceptor.pre_get_operation(request, metadata) transcoded_request = ( _BaseCloudRedisRestTransport._BaseGetOperation._get_transcoded_request( @@ -2284,6 +3065,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1.CloudRedisClient.GetOperation", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "GetOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._GetOperation._get_response( self._host, @@ -2303,6 +3111,27 @@ def __call__( resp = operations_pb2.Operation() resp = json_format.Parse(content, resp) resp = self._interceptor.post_get_operation(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1.CloudRedisAsyncClient.GetOperation", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "GetOperation", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property @@ -2343,7 +3172,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Call the list operations method over HTTP. @@ -2353,8 +3182,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: operations_pb2.ListOperationsResponse: Response from ListOperations method. @@ -2363,6 +3194,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseListOperations._get_http_options() ) + request, metadata = self._interceptor.pre_list_operations(request, metadata) transcoded_request = _BaseCloudRedisRestTransport._BaseListOperations._get_transcoded_request( http_options, request @@ -2375,6 +3207,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1.CloudRedisClient.ListOperations", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "ListOperations", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._ListOperations._get_response( self._host, @@ -2394,6 +3253,27 @@ def __call__( resp = operations_pb2.ListOperationsResponse() resp = json_format.Parse(content, resp) resp = self._interceptor.post_list_operations(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1.CloudRedisAsyncClient.ListOperations", + extra={ + "serviceName": "google.cloud.redis.v1.CloudRedis", + "rpcName": "ListOperations", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property diff --git a/packages/google-cloud-redis/google/cloud/redis_v1beta1/gapic_version.py b/packages/google-cloud-redis/google/cloud/redis_v1beta1/gapic_version.py index 1230672bab9e..558c8aab67c5 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1beta1/gapic_version.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1beta1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.16.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/async_client.py b/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/async_client.py index e53aa8945e14..8f5c9258f84b 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/async_client.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -56,6 +57,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, CloudRedisTransport from .transports.grpc_asyncio import CloudRedisGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class CloudRedisAsyncClient: """Configures and manages Cloud Memorystore for Redis instances @@ -276,6 +286,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.redis_v1beta1.CloudRedisAsyncClient`.", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "credentialsType": None, + }, + ) + async def list_instances( self, request: Optional[Union[cloud_redis.ListInstancesRequest, dict]] = None, @@ -283,7 +315,7 @@ async def list_instances( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListInstancesAsyncPager: r"""Lists all Redis instances owned by a project in either the specified location (region) or all locations. @@ -339,8 +371,10 @@ async def sample_list_instances(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_v1beta1.services.cloud_redis.pagers.ListInstancesAsyncPager: @@ -415,7 +449,7 @@ async def get_instance( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis.Instance: r"""Gets the details of a specific Redis instance. @@ -460,8 +494,10 @@ async def sample_get_instance(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_v1beta1.types.Instance: @@ -520,7 +556,7 @@ async def get_instance_auth_string( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis.InstanceAuthString: r"""Gets the AUTH string for a Redis instance. If AUTH is not enabled for the instance the response will be empty. @@ -568,8 +604,10 @@ async def sample_get_instance_auth_string(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_v1beta1.types.InstanceAuthString: @@ -630,7 +668,7 @@ async def create_instance( instance: Optional[cloud_redis.Instance] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Creates a Redis instance based on the specified tier and memory size. @@ -719,8 +757,10 @@ async def sample_create_instance(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -797,7 +837,7 @@ async def update_instance( instance: Optional[cloud_redis.Instance] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Updates the metadata and configuration of a specific Redis instance. @@ -870,8 +910,10 @@ async def sample_update_instance(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -948,7 +990,7 @@ async def upgrade_instance( redis_version: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Upgrades Redis instance to the newer Redis version specified in the request. @@ -1006,8 +1048,10 @@ async def sample_upgrade_instance(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1082,7 +1126,7 @@ async def import_instance( input_config: Optional[cloud_redis.InputConfig] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Import a Redis RDB snapshot file from Cloud Storage into a Redis instance. @@ -1150,8 +1194,10 @@ async def sample_import_instance(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1226,7 +1272,7 @@ async def export_instance( output_config: Optional[cloud_redis.OutputConfig] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Export Redis instance data into a Redis RDB format file in Cloud Storage. @@ -1291,8 +1337,10 @@ async def sample_export_instance(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1369,7 +1417,7 @@ async def failover_instance( ] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Initiates a failover of the primary node to current replica node for a specific STANDARD tier Cloud @@ -1428,8 +1476,10 @@ async def sample_failover_instance(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1503,7 +1553,7 @@ async def delete_instance( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a specific Redis instance. Instance stops serving and data is deleted. @@ -1553,8 +1603,10 @@ async def sample_delete_instance(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1637,7 +1689,7 @@ async def reschedule_maintenance( schedule_time: Optional[timestamp_pb2.Timestamp] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Reschedule maintenance for a given instance in a given project and location. @@ -1703,8 +1755,10 @@ async def sample_reschedule_maintenance(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: diff --git a/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/client.py b/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/client.py index 3c406edbf0ef..ed5ba91a16f3 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/client.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.protobuf import any_pb2 # type: ignore @@ -604,6 +614,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -666,6 +680,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.redis_v1beta1.CloudRedisClient`.", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "credentialsType": None, + }, + ) + def list_instances( self, request: Optional[Union[cloud_redis.ListInstancesRequest, dict]] = None, @@ -673,7 +710,7 @@ def list_instances( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListInstancesPager: r"""Lists all Redis instances owned by a project in either the specified location (region) or all locations. @@ -729,8 +766,10 @@ def sample_list_instances(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_v1beta1.services.cloud_redis.pagers.ListInstancesPager: @@ -802,7 +841,7 @@ def get_instance( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis.Instance: r"""Gets the details of a specific Redis instance. @@ -847,8 +886,10 @@ def sample_get_instance(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_v1beta1.types.Instance: @@ -904,7 +945,7 @@ def get_instance_auth_string( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis.InstanceAuthString: r"""Gets the AUTH string for a Redis instance. If AUTH is not enabled for the instance the response will be empty. @@ -952,8 +993,10 @@ def sample_get_instance_auth_string(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.redis_v1beta1.types.InstanceAuthString: @@ -1011,7 +1054,7 @@ def create_instance( instance: Optional[cloud_redis.Instance] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Creates a Redis instance based on the specified tier and memory size. @@ -1100,8 +1143,10 @@ def sample_create_instance(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1175,7 +1220,7 @@ def update_instance( instance: Optional[cloud_redis.Instance] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Updates the metadata and configuration of a specific Redis instance. @@ -1248,8 +1293,10 @@ def sample_update_instance(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1323,7 +1370,7 @@ def upgrade_instance( redis_version: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Upgrades Redis instance to the newer Redis version specified in the request. @@ -1381,8 +1428,10 @@ def sample_upgrade_instance(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1454,7 +1503,7 @@ def import_instance( input_config: Optional[cloud_redis.InputConfig] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Import a Redis RDB snapshot file from Cloud Storage into a Redis instance. @@ -1522,8 +1571,10 @@ def sample_import_instance(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1595,7 +1646,7 @@ def export_instance( output_config: Optional[cloud_redis.OutputConfig] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Export Redis instance data into a Redis RDB format file in Cloud Storage. @@ -1660,8 +1711,10 @@ def sample_export_instance(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1735,7 +1788,7 @@ def failover_instance( ] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Initiates a failover of the primary node to current replica node for a specific STANDARD tier Cloud @@ -1794,8 +1847,10 @@ def sample_failover_instance(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1866,7 +1921,7 @@ def delete_instance( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Deletes a specific Redis instance. Instance stops serving and data is deleted. @@ -1916,8 +1971,10 @@ def sample_delete_instance(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1997,7 +2054,7 @@ def reschedule_maintenance( schedule_time: Optional[timestamp_pb2.Timestamp] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Reschedule maintenance for a given instance in a given project and location. @@ -2063,8 +2120,10 @@ def sample_reschedule_maintenance(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: diff --git a/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/pagers.py b/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/pagers.py index d9e97a5f152c..e3d17ae9b5cc 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/pagers.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -81,8 +81,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = cloud_redis.ListInstancesRequest(request) @@ -141,7 +143,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -155,8 +157,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = cloud_redis.ListInstancesRequest(request) diff --git a/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc.py b/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc.py index 4b7d62bee262..c93d2e332049 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -21,12 +24,90 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.redis_v1beta1.types import cloud_redis from .base import DEFAULT_CLIENT_INFO, CloudRedisTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class CloudRedisGrpcTransport(CloudRedisTransport): """gRPC backend transport for CloudRedis. @@ -201,7 +282,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -265,7 +351,9 @@ def operations_client(self) -> operations_v1.OperationsClient: """ # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + self._operations_client = operations_v1.OperationsClient( + self._logged_channel + ) # Return the client from cache. return self._operations_client @@ -300,7 +388,7 @@ def list_instances( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_instances" not in self._stubs: - self._stubs["list_instances"] = self.grpc_channel.unary_unary( + self._stubs["list_instances"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/ListInstances", request_serializer=cloud_redis.ListInstancesRequest.serialize, response_deserializer=cloud_redis.ListInstancesResponse.deserialize, @@ -326,7 +414,7 @@ def get_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_instance" not in self._stubs: - self._stubs["get_instance"] = self.grpc_channel.unary_unary( + self._stubs["get_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/GetInstance", request_serializer=cloud_redis.GetInstanceRequest.serialize, response_deserializer=cloud_redis.Instance.deserialize, @@ -357,7 +445,7 @@ def get_instance_auth_string( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_instance_auth_string" not in self._stubs: - self._stubs["get_instance_auth_string"] = self.grpc_channel.unary_unary( + self._stubs["get_instance_auth_string"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/GetInstanceAuthString", request_serializer=cloud_redis.GetInstanceAuthStringRequest.serialize, response_deserializer=cloud_redis.InstanceAuthString.deserialize, @@ -396,7 +484,7 @@ def create_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_instance" not in self._stubs: - self._stubs["create_instance"] = self.grpc_channel.unary_unary( + self._stubs["create_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/CreateInstance", request_serializer=cloud_redis.CreateInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -427,7 +515,7 @@ def update_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_instance" not in self._stubs: - self._stubs["update_instance"] = self.grpc_channel.unary_unary( + self._stubs["update_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/UpdateInstance", request_serializer=cloud_redis.UpdateInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -454,7 +542,7 @@ def upgrade_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "upgrade_instance" not in self._stubs: - self._stubs["upgrade_instance"] = self.grpc_channel.unary_unary( + self._stubs["upgrade_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/UpgradeInstance", request_serializer=cloud_redis.UpgradeInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -488,7 +576,7 @@ def import_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "import_instance" not in self._stubs: - self._stubs["import_instance"] = self.grpc_channel.unary_unary( + self._stubs["import_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/ImportInstance", request_serializer=cloud_redis.ImportInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -519,7 +607,7 @@ def export_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "export_instance" not in self._stubs: - self._stubs["export_instance"] = self.grpc_channel.unary_unary( + self._stubs["export_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/ExportInstance", request_serializer=cloud_redis.ExportInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -547,7 +635,7 @@ def failover_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "failover_instance" not in self._stubs: - self._stubs["failover_instance"] = self.grpc_channel.unary_unary( + self._stubs["failover_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/FailoverInstance", request_serializer=cloud_redis.FailoverInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -574,7 +662,7 @@ def delete_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_instance" not in self._stubs: - self._stubs["delete_instance"] = self.grpc_channel.unary_unary( + self._stubs["delete_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/DeleteInstance", request_serializer=cloud_redis.DeleteInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -601,7 +689,7 @@ def reschedule_maintenance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "reschedule_maintenance" not in self._stubs: - self._stubs["reschedule_maintenance"] = self.grpc_channel.unary_unary( + self._stubs["reschedule_maintenance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/RescheduleMaintenance", request_serializer=cloud_redis.RescheduleMaintenanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -609,7 +697,7 @@ def reschedule_maintenance( return self._stubs["reschedule_maintenance"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc_asyncio.py b/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc_asyncio.py index 03281c8cb333..b8a63f40be58 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc_asyncio.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -23,14 +26,93 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.redis_v1beta1.types import cloud_redis from .base import DEFAULT_CLIENT_INFO, CloudRedisTransport from .grpc import CloudRedisGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class CloudRedisGrpcAsyncIOTransport(CloudRedisTransport): """gRPC AsyncIO backend transport for CloudRedis. @@ -248,10 +330,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -274,7 +359,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel + self._logged_channel ) # Return the client from cache. @@ -310,7 +395,7 @@ def list_instances( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_instances" not in self._stubs: - self._stubs["list_instances"] = self.grpc_channel.unary_unary( + self._stubs["list_instances"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/ListInstances", request_serializer=cloud_redis.ListInstancesRequest.serialize, response_deserializer=cloud_redis.ListInstancesResponse.deserialize, @@ -336,7 +421,7 @@ def get_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_instance" not in self._stubs: - self._stubs["get_instance"] = self.grpc_channel.unary_unary( + self._stubs["get_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/GetInstance", request_serializer=cloud_redis.GetInstanceRequest.serialize, response_deserializer=cloud_redis.Instance.deserialize, @@ -368,7 +453,7 @@ def get_instance_auth_string( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_instance_auth_string" not in self._stubs: - self._stubs["get_instance_auth_string"] = self.grpc_channel.unary_unary( + self._stubs["get_instance_auth_string"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/GetInstanceAuthString", request_serializer=cloud_redis.GetInstanceAuthStringRequest.serialize, response_deserializer=cloud_redis.InstanceAuthString.deserialize, @@ -409,7 +494,7 @@ def create_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_instance" not in self._stubs: - self._stubs["create_instance"] = self.grpc_channel.unary_unary( + self._stubs["create_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/CreateInstance", request_serializer=cloud_redis.CreateInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -442,7 +527,7 @@ def update_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_instance" not in self._stubs: - self._stubs["update_instance"] = self.grpc_channel.unary_unary( + self._stubs["update_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/UpdateInstance", request_serializer=cloud_redis.UpdateInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -471,7 +556,7 @@ def upgrade_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "upgrade_instance" not in self._stubs: - self._stubs["upgrade_instance"] = self.grpc_channel.unary_unary( + self._stubs["upgrade_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/UpgradeInstance", request_serializer=cloud_redis.UpgradeInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -507,7 +592,7 @@ def import_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "import_instance" not in self._stubs: - self._stubs["import_instance"] = self.grpc_channel.unary_unary( + self._stubs["import_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/ImportInstance", request_serializer=cloud_redis.ImportInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -540,7 +625,7 @@ def export_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "export_instance" not in self._stubs: - self._stubs["export_instance"] = self.grpc_channel.unary_unary( + self._stubs["export_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/ExportInstance", request_serializer=cloud_redis.ExportInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -570,7 +655,7 @@ def failover_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "failover_instance" not in self._stubs: - self._stubs["failover_instance"] = self.grpc_channel.unary_unary( + self._stubs["failover_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/FailoverInstance", request_serializer=cloud_redis.FailoverInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -599,7 +684,7 @@ def delete_instance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_instance" not in self._stubs: - self._stubs["delete_instance"] = self.grpc_channel.unary_unary( + self._stubs["delete_instance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/DeleteInstance", request_serializer=cloud_redis.DeleteInstanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -628,7 +713,7 @@ def reschedule_maintenance( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "reschedule_maintenance" not in self._stubs: - self._stubs["reschedule_maintenance"] = self.grpc_channel.unary_unary( + self._stubs["reschedule_maintenance"] = self._logged_channel.unary_unary( "/google.cloud.redis.v1beta1.CloudRedis/RescheduleMaintenance", request_serializer=cloud_redis.RescheduleMaintenanceRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -701,7 +786,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/transports/rest.py b/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/transports/rest.py index c149776eb342..c3d6149ea416 100644 --- a/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/transports/rest.py +++ b/packages/google-cloud-redis/google/cloud/redis_v1beta1/services/cloud_redis/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -38,6 +38,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -158,8 +166,10 @@ def post_upgrade_instance(self, response): def pre_create_instance( self, request: cloud_redis.CreateInstanceRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis.CreateInstanceRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis.CreateInstanceRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for create_instance Override in a subclass to manipulate the request or metadata @@ -181,8 +191,10 @@ def post_create_instance( def pre_delete_instance( self, request: cloud_redis.DeleteInstanceRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis.DeleteInstanceRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis.DeleteInstanceRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for delete_instance Override in a subclass to manipulate the request or metadata @@ -204,8 +216,10 @@ def post_delete_instance( def pre_export_instance( self, request: cloud_redis.ExportInstanceRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis.ExportInstanceRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis.ExportInstanceRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for export_instance Override in a subclass to manipulate the request or metadata @@ -227,8 +241,10 @@ def post_export_instance( def pre_failover_instance( self, request: cloud_redis.FailoverInstanceRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis.FailoverInstanceRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis.FailoverInstanceRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for failover_instance Override in a subclass to manipulate the request or metadata @@ -250,8 +266,8 @@ def post_failover_instance( def pre_get_instance( self, request: cloud_redis.GetInstanceRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis.GetInstanceRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[cloud_redis.GetInstanceRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for get_instance Override in a subclass to manipulate the request or metadata @@ -271,8 +287,11 @@ def post_get_instance(self, response: cloud_redis.Instance) -> cloud_redis.Insta def pre_get_instance_auth_string( self, request: cloud_redis.GetInstanceAuthStringRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis.GetInstanceAuthStringRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis.GetInstanceAuthStringRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for get_instance_auth_string Override in a subclass to manipulate the request or metadata @@ -294,8 +313,10 @@ def post_get_instance_auth_string( def pre_import_instance( self, request: cloud_redis.ImportInstanceRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis.ImportInstanceRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis.ImportInstanceRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for import_instance Override in a subclass to manipulate the request or metadata @@ -317,8 +338,10 @@ def post_import_instance( def pre_list_instances( self, request: cloud_redis.ListInstancesRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis.ListInstancesRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis.ListInstancesRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_instances Override in a subclass to manipulate the request or metadata @@ -340,8 +363,11 @@ def post_list_instances( def pre_reschedule_maintenance( self, request: cloud_redis.RescheduleMaintenanceRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis.RescheduleMaintenanceRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis.RescheduleMaintenanceRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for reschedule_maintenance Override in a subclass to manipulate the request or metadata @@ -363,8 +389,10 @@ def post_reschedule_maintenance( def pre_update_instance( self, request: cloud_redis.UpdateInstanceRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis.UpdateInstanceRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis.UpdateInstanceRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for update_instance Override in a subclass to manipulate the request or metadata @@ -386,8 +414,10 @@ def post_update_instance( def pre_upgrade_instance( self, request: cloud_redis.UpgradeInstanceRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[cloud_redis.UpgradeInstanceRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + cloud_redis.UpgradeInstanceRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for upgrade_instance Override in a subclass to manipulate the request or metadata @@ -601,7 +631,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the create instance method over HTTP. @@ -612,8 +642,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -626,6 +658,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseCreateInstance._get_http_options() ) + request, metadata = self._interceptor.pre_create_instance(request, metadata) transcoded_request = _BaseCloudRedisRestTransport._BaseCreateInstance._get_transcoded_request( http_options, request @@ -644,6 +677,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1beta1.CloudRedisClient.CreateInstance", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": "CreateInstance", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._CreateInstance._get_response( self._host, @@ -663,7 +723,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_instance(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1beta1.CloudRedisClient.create_instance", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": "CreateInstance", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DeleteInstance( @@ -700,7 +782,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the delete instance method over HTTP. @@ -711,8 +793,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -725,6 +809,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseDeleteInstance._get_http_options() ) + request, metadata = self._interceptor.pre_delete_instance(request, metadata) transcoded_request = _BaseCloudRedisRestTransport._BaseDeleteInstance._get_transcoded_request( http_options, request @@ -737,6 +822,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1beta1.CloudRedisClient.DeleteInstance", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": "DeleteInstance", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._DeleteInstance._get_response( self._host, @@ -755,7 +867,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_delete_instance(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1beta1.CloudRedisClient.delete_instance", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": "DeleteInstance", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ExportInstance( @@ -793,7 +927,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the export instance method over HTTP. @@ -804,8 +938,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -818,6 +954,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseExportInstance._get_http_options() ) + request, metadata = self._interceptor.pre_export_instance(request, metadata) transcoded_request = _BaseCloudRedisRestTransport._BaseExportInstance._get_transcoded_request( http_options, request @@ -836,6 +973,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1beta1.CloudRedisClient.ExportInstance", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": "ExportInstance", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._ExportInstance._get_response( self._host, @@ -855,7 +1019,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_export_instance(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1beta1.CloudRedisClient.export_instance", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": "ExportInstance", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _FailoverInstance( @@ -893,7 +1079,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the failover instance method over HTTP. @@ -904,8 +1090,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -918,6 +1106,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseFailoverInstance._get_http_options() ) + request, metadata = self._interceptor.pre_failover_instance( request, metadata ) @@ -934,6 +1123,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1beta1.CloudRedisClient.FailoverInstance", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": "FailoverInstance", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._FailoverInstance._get_response( self._host, @@ -953,7 +1169,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_failover_instance(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1beta1.CloudRedisClient.failover_instance", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": "FailoverInstance", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetInstance( @@ -990,7 +1228,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis.Instance: r"""Call the get instance method over HTTP. @@ -1001,8 +1239,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.cloud_redis.Instance: @@ -1012,6 +1252,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseGetInstance._get_http_options() ) + request, metadata = self._interceptor.pre_get_instance(request, metadata) transcoded_request = ( _BaseCloudRedisRestTransport._BaseGetInstance._get_transcoded_request( @@ -1026,6 +1267,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1beta1.CloudRedisClient.GetInstance", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": "GetInstance", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._GetInstance._get_response( self._host, @@ -1046,7 +1314,29 @@ def __call__( pb_resp = cloud_redis.Instance.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_instance(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = cloud_redis.Instance.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1beta1.CloudRedisClient.get_instance", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": "GetInstance", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetInstanceAuthString( @@ -1083,7 +1373,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis.InstanceAuthString: r"""Call the get instance auth string method over HTTP. @@ -1094,8 +1384,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.cloud_redis.InstanceAuthString: @@ -1105,6 +1397,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseGetInstanceAuthString._get_http_options() ) + request, metadata = self._interceptor.pre_get_instance_auth_string( request, metadata ) @@ -1117,6 +1410,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1beta1.CloudRedisClient.GetInstanceAuthString", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": "GetInstanceAuthString", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._GetInstanceAuthString._get_response( self._host, @@ -1137,7 +1457,29 @@ def __call__( pb_resp = cloud_redis.InstanceAuthString.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_instance_auth_string(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = cloud_redis.InstanceAuthString.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1beta1.CloudRedisClient.get_instance_auth_string", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": "GetInstanceAuthString", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ImportInstance( @@ -1175,7 +1517,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the import instance method over HTTP. @@ -1186,8 +1528,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1200,6 +1544,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseImportInstance._get_http_options() ) + request, metadata = self._interceptor.pre_import_instance(request, metadata) transcoded_request = _BaseCloudRedisRestTransport._BaseImportInstance._get_transcoded_request( http_options, request @@ -1218,6 +1563,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1beta1.CloudRedisClient.ImportInstance", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": "ImportInstance", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._ImportInstance._get_response( self._host, @@ -1237,7 +1609,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_import_instance(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1beta1.CloudRedisClient.import_instance", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": "ImportInstance", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListInstances( @@ -1274,7 +1668,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cloud_redis.ListInstancesResponse: r"""Call the list instances method over HTTP. @@ -1285,8 +1679,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.cloud_redis.ListInstancesResponse: @@ -1298,6 +1694,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseListInstances._get_http_options() ) + request, metadata = self._interceptor.pre_list_instances(request, metadata) transcoded_request = ( _BaseCloudRedisRestTransport._BaseListInstances._get_transcoded_request( @@ -1312,6 +1709,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1beta1.CloudRedisClient.ListInstances", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": "ListInstances", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._ListInstances._get_response( self._host, @@ -1332,7 +1756,31 @@ def __call__( pb_resp = cloud_redis.ListInstancesResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_instances(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = cloud_redis.ListInstancesResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1beta1.CloudRedisClient.list_instances", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": "ListInstances", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _RescheduleMaintenance( @@ -1370,7 +1818,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the reschedule maintenance method over HTTP. @@ -1381,8 +1829,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1395,6 +1845,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseRescheduleMaintenance._get_http_options() ) + request, metadata = self._interceptor.pre_reschedule_maintenance( request, metadata ) @@ -1411,6 +1862,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1beta1.CloudRedisClient.RescheduleMaintenance", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": "RescheduleMaintenance", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._RescheduleMaintenance._get_response( self._host, @@ -1430,7 +1908,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_reschedule_maintenance(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1beta1.CloudRedisClient.reschedule_maintenance", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": "RescheduleMaintenance", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateInstance( @@ -1468,7 +1968,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the update instance method over HTTP. @@ -1479,8 +1979,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1493,6 +1995,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseUpdateInstance._get_http_options() ) + request, metadata = self._interceptor.pre_update_instance(request, metadata) transcoded_request = _BaseCloudRedisRestTransport._BaseUpdateInstance._get_transcoded_request( http_options, request @@ -1511,6 +2014,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1beta1.CloudRedisClient.UpdateInstance", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": "UpdateInstance", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._UpdateInstance._get_response( self._host, @@ -1530,7 +2060,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_instance(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1beta1.CloudRedisClient.update_instance", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": "UpdateInstance", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpgradeInstance( @@ -1568,7 +2120,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the upgrade instance method over HTTP. @@ -1579,8 +2131,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1593,6 +2147,7 @@ def __call__( http_options = ( _BaseCloudRedisRestTransport._BaseUpgradeInstance._get_http_options() ) + request, metadata = self._interceptor.pre_upgrade_instance( request, metadata ) @@ -1609,6 +2164,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.redis_v1beta1.CloudRedisClient.UpgradeInstance", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": "UpgradeInstance", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = CloudRedisRestTransport._UpgradeInstance._get_response( self._host, @@ -1628,7 +2210,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_upgrade_instance(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.redis_v1beta1.CloudRedisClient.upgrade_instance", + extra={ + "serviceName": "google.cloud.redis.v1beta1.CloudRedis", + "rpcName": "UpgradeInstance", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property diff --git a/packages/google-cloud-redis/samples/generated_samples/snippet_metadata_google.cloud.redis.v1.json b/packages/google-cloud-redis/samples/generated_samples/snippet_metadata_google.cloud.redis.v1.json index b39a9ed32274..78f872bc4aef 100644 --- a/packages/google-cloud-redis/samples/generated_samples/snippet_metadata_google.cloud.redis.v1.json +++ b/packages/google-cloud-redis/samples/generated_samples/snippet_metadata_google.cloud.redis.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-redis", - "version": "2.16.1" + "version": "0.1.0" }, "snippets": [ { @@ -55,7 +55,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -143,7 +143,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -224,7 +224,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -304,7 +304,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -389,7 +389,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -473,7 +473,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -558,7 +558,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -642,7 +642,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -723,7 +723,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_v1.types.InstanceAuthString", @@ -803,7 +803,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_v1.types.InstanceAuthString", @@ -884,7 +884,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_v1.types.Instance", @@ -964,7 +964,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_v1.types.Instance", @@ -1049,7 +1049,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -1133,7 +1133,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -1214,7 +1214,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_v1.services.cloud_redis.pagers.ListInstancesAsyncPager", @@ -1294,7 +1294,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_v1.services.cloud_redis.pagers.ListInstancesPager", @@ -1383,7 +1383,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -1471,7 +1471,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -1556,7 +1556,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -1640,7 +1640,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -1725,7 +1725,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -1809,7 +1809,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", diff --git a/packages/google-cloud-redis/samples/generated_samples/snippet_metadata_google.cloud.redis.v1beta1.json b/packages/google-cloud-redis/samples/generated_samples/snippet_metadata_google.cloud.redis.v1beta1.json index cbdefa7eddae..e1412dd446e5 100644 --- a/packages/google-cloud-redis/samples/generated_samples/snippet_metadata_google.cloud.redis.v1beta1.json +++ b/packages/google-cloud-redis/samples/generated_samples/snippet_metadata_google.cloud.redis.v1beta1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-redis", - "version": "2.16.1" + "version": "0.1.0" }, "snippets": [ { @@ -55,7 +55,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -143,7 +143,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -224,7 +224,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -304,7 +304,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -389,7 +389,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -473,7 +473,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -558,7 +558,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -642,7 +642,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -723,7 +723,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_v1beta1.types.InstanceAuthString", @@ -803,7 +803,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_v1beta1.types.InstanceAuthString", @@ -884,7 +884,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_v1beta1.types.Instance", @@ -964,7 +964,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_v1beta1.types.Instance", @@ -1049,7 +1049,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -1133,7 +1133,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -1214,7 +1214,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_v1beta1.services.cloud_redis.pagers.ListInstancesAsyncPager", @@ -1294,7 +1294,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.redis_v1beta1.services.cloud_redis.pagers.ListInstancesPager", @@ -1383,7 +1383,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -1471,7 +1471,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -1556,7 +1556,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -1640,7 +1640,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -1725,7 +1725,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -1809,7 +1809,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", diff --git a/packages/google-cloud-redis/tests/unit/gapic/redis_v1/test_cloud_redis.py b/packages/google-cloud-redis/tests/unit/gapic/redis_v1/test_cloud_redis.py index eaed0859bc68..a18ae66530de 100644 --- a/packages/google-cloud-redis/tests/unit/gapic/redis_v1/test_cloud_redis.py +++ b/packages/google-cloud-redis/tests/unit/gapic/redis_v1/test_cloud_redis.py @@ -5234,6 +5234,7 @@ def test_list_instances_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_instances(request) @@ -5287,6 +5288,7 @@ def test_list_instances_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_instances(**mock_args) @@ -5476,6 +5478,7 @@ def test_get_instance_rest_required_fields(request_type=cloud_redis.GetInstanceR response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_instance(request) @@ -5523,6 +5526,7 @@ def test_get_instance_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_instance(**mock_args) @@ -5658,6 +5662,7 @@ def test_get_instance_auth_string_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_instance_auth_string(request) @@ -5705,6 +5710,7 @@ def test_get_instance_auth_string_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_instance_auth_string(**mock_args) @@ -5847,6 +5853,7 @@ def test_create_instance_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_instance(request) @@ -5907,6 +5914,7 @@ def test_create_instance_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_instance(**mock_args) @@ -6038,6 +6046,7 @@ def test_update_instance_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_instance(request) @@ -6092,6 +6101,7 @@ def test_update_instance_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_instance(**mock_args) @@ -6232,6 +6242,7 @@ def test_upgrade_instance_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.upgrade_instance(request) @@ -6286,6 +6297,7 @@ def test_upgrade_instance_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.upgrade_instance(**mock_args) @@ -6420,6 +6432,7 @@ def test_import_instance_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.import_instance(request) @@ -6476,6 +6489,7 @@ def test_import_instance_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.import_instance(**mock_args) @@ -6612,6 +6626,7 @@ def test_export_instance_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.export_instance(request) @@ -6668,6 +6683,7 @@ def test_export_instance_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.export_instance(**mock_args) @@ -6806,6 +6822,7 @@ def test_failover_instance_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.failover_instance(request) @@ -6852,6 +6869,7 @@ def test_failover_instance_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.failover_instance(**mock_args) @@ -6985,6 +7003,7 @@ def test_delete_instance_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_instance(request) @@ -7030,6 +7049,7 @@ def test_delete_instance_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_instance(**mock_args) @@ -7167,6 +7187,7 @@ def test_reschedule_maintenance_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.reschedule_maintenance(request) @@ -7222,6 +7243,7 @@ def test_reschedule_maintenance_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.reschedule_maintenance(**mock_args) @@ -7952,6 +7974,7 @@ def test_list_instances_rest_bad_request(request_type=cloud_redis.ListInstancesR response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_instances(request) @@ -7988,6 +8011,7 @@ def test_list_instances_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_instances(request) # Establish that the response is the type that we expect. @@ -8029,6 +8053,7 @@ def test_list_instances_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = cloud_redis.ListInstancesResponse.to_json( cloud_redis.ListInstancesResponse() ) @@ -8073,6 +8098,7 @@ def test_get_instance_rest_bad_request(request_type=cloud_redis.GetInstanceReque response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_instance(request) @@ -8136,6 +8162,7 @@ def test_get_instance_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_instance(request) # Establish that the response is the type that we expect. @@ -8210,6 +8237,7 @@ def test_get_instance_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = cloud_redis.Instance.to_json(cloud_redis.Instance()) req.return_value.content = return_value @@ -8254,6 +8282,7 @@ def test_get_instance_auth_string_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_instance_auth_string(request) @@ -8289,6 +8318,7 @@ def test_get_instance_auth_string_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_instance_auth_string(request) # Establish that the response is the type that we expect. @@ -8329,6 +8359,7 @@ def test_get_instance_auth_string_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = cloud_redis.InstanceAuthString.to_json( cloud_redis.InstanceAuthString() ) @@ -8375,6 +8406,7 @@ def test_create_instance_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_instance(request) @@ -8546,6 +8578,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_instance(request) # Establish that the response is the type that we expect. @@ -8587,6 +8620,7 @@ def test_create_instance_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -8633,6 +8667,7 @@ def test_update_instance_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_instance(request) @@ -8806,6 +8841,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_instance(request) # Establish that the response is the type that we expect. @@ -8847,6 +8883,7 @@ def test_update_instance_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -8891,6 +8928,7 @@ def test_upgrade_instance_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.upgrade_instance(request) @@ -8921,6 +8959,7 @@ def test_upgrade_instance_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.upgrade_instance(request) # Establish that the response is the type that we expect. @@ -8962,6 +9001,7 @@ def test_upgrade_instance_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -9006,6 +9046,7 @@ def test_import_instance_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.import_instance(request) @@ -9036,6 +9077,7 @@ def test_import_instance_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.import_instance(request) # Establish that the response is the type that we expect. @@ -9077,6 +9119,7 @@ def test_import_instance_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -9121,6 +9164,7 @@ def test_export_instance_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.export_instance(request) @@ -9151,6 +9195,7 @@ def test_export_instance_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.export_instance(request) # Establish that the response is the type that we expect. @@ -9192,6 +9237,7 @@ def test_export_instance_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -9236,6 +9282,7 @@ def test_failover_instance_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.failover_instance(request) @@ -9266,6 +9313,7 @@ def test_failover_instance_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.failover_instance(request) # Establish that the response is the type that we expect. @@ -9307,6 +9355,7 @@ def test_failover_instance_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -9351,6 +9400,7 @@ def test_delete_instance_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_instance(request) @@ -9381,6 +9431,7 @@ def test_delete_instance_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_instance(request) # Establish that the response is the type that we expect. @@ -9422,6 +9473,7 @@ def test_delete_instance_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -9466,6 +9518,7 @@ def test_reschedule_maintenance_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.reschedule_maintenance(request) @@ -9496,6 +9549,7 @@ def test_reschedule_maintenance_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.reschedule_maintenance(request) # Establish that the response is the type that we expect. @@ -9537,6 +9591,7 @@ def test_reschedule_maintenance_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -9581,6 +9636,7 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_location(request) @@ -9611,6 +9667,7 @@ def test_get_location_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_location(request) @@ -9639,6 +9696,7 @@ def test_list_locations_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_locations(request) @@ -9669,6 +9727,7 @@ def test_list_locations_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_locations(request) @@ -9699,6 +9758,7 @@ def test_cancel_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.cancel_operation(request) @@ -9729,6 +9789,7 @@ def test_cancel_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.cancel_operation(request) @@ -9759,6 +9820,7 @@ def test_delete_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_operation(request) @@ -9789,6 +9851,7 @@ def test_delete_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_operation(request) @@ -9819,6 +9882,7 @@ def test_get_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_operation(request) @@ -9849,6 +9913,7 @@ def test_get_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_operation(request) @@ -9879,6 +9944,7 @@ def test_list_operations_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_operations(request) @@ -9909,6 +9975,7 @@ def test_list_operations_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_operations(request) diff --git a/packages/google-cloud-redis/tests/unit/gapic/redis_v1beta1/test_cloud_redis.py b/packages/google-cloud-redis/tests/unit/gapic/redis_v1beta1/test_cloud_redis.py index 003d0ea284a0..c40f00572e24 100644 --- a/packages/google-cloud-redis/tests/unit/gapic/redis_v1beta1/test_cloud_redis.py +++ b/packages/google-cloud-redis/tests/unit/gapic/redis_v1beta1/test_cloud_redis.py @@ -5206,6 +5206,7 @@ def test_list_instances_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_instances(request) @@ -5259,6 +5260,7 @@ def test_list_instances_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_instances(**mock_args) @@ -5449,6 +5451,7 @@ def test_get_instance_rest_required_fields(request_type=cloud_redis.GetInstanceR response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_instance(request) @@ -5496,6 +5499,7 @@ def test_get_instance_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_instance(**mock_args) @@ -5632,6 +5636,7 @@ def test_get_instance_auth_string_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_instance_auth_string(request) @@ -5679,6 +5684,7 @@ def test_get_instance_auth_string_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_instance_auth_string(**mock_args) @@ -5821,6 +5827,7 @@ def test_create_instance_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_instance(request) @@ -5881,6 +5888,7 @@ def test_create_instance_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_instance(**mock_args) @@ -6013,6 +6021,7 @@ def test_update_instance_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_instance(request) @@ -6067,6 +6076,7 @@ def test_update_instance_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_instance(**mock_args) @@ -6207,6 +6217,7 @@ def test_upgrade_instance_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.upgrade_instance(request) @@ -6261,6 +6272,7 @@ def test_upgrade_instance_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.upgrade_instance(**mock_args) @@ -6395,6 +6407,7 @@ def test_import_instance_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.import_instance(request) @@ -6451,6 +6464,7 @@ def test_import_instance_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.import_instance(**mock_args) @@ -6587,6 +6601,7 @@ def test_export_instance_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.export_instance(request) @@ -6643,6 +6658,7 @@ def test_export_instance_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.export_instance(**mock_args) @@ -6781,6 +6797,7 @@ def test_failover_instance_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.failover_instance(request) @@ -6827,6 +6844,7 @@ def test_failover_instance_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.failover_instance(**mock_args) @@ -6960,6 +6978,7 @@ def test_delete_instance_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_instance(request) @@ -7005,6 +7024,7 @@ def test_delete_instance_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_instance(**mock_args) @@ -7143,6 +7163,7 @@ def test_reschedule_maintenance_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.reschedule_maintenance(request) @@ -7198,6 +7219,7 @@ def test_reschedule_maintenance_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.reschedule_maintenance(**mock_args) @@ -7922,6 +7944,7 @@ def test_list_instances_rest_bad_request(request_type=cloud_redis.ListInstancesR response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_instances(request) @@ -7958,6 +7981,7 @@ def test_list_instances_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_instances(request) # Establish that the response is the type that we expect. @@ -7999,6 +8023,7 @@ def test_list_instances_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = cloud_redis.ListInstancesResponse.to_json( cloud_redis.ListInstancesResponse() ) @@ -8043,6 +8068,7 @@ def test_get_instance_rest_bad_request(request_type=cloud_redis.GetInstanceReque response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_instance(request) @@ -8100,6 +8126,7 @@ def test_get_instance_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_instance(request) # Establish that the response is the type that we expect. @@ -8166,6 +8193,7 @@ def test_get_instance_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = cloud_redis.Instance.to_json(cloud_redis.Instance()) req.return_value.content = return_value @@ -8210,6 +8238,7 @@ def test_get_instance_auth_string_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_instance_auth_string(request) @@ -8245,6 +8274,7 @@ def test_get_instance_auth_string_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_instance_auth_string(request) # Establish that the response is the type that we expect. @@ -8285,6 +8315,7 @@ def test_get_instance_auth_string_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = cloud_redis.InstanceAuthString.to_json( cloud_redis.InstanceAuthString() ) @@ -8331,6 +8362,7 @@ def test_create_instance_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_instance(request) @@ -8495,6 +8527,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_instance(request) # Establish that the response is the type that we expect. @@ -8536,6 +8569,7 @@ def test_create_instance_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -8582,6 +8616,7 @@ def test_update_instance_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_instance(request) @@ -8748,6 +8783,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_instance(request) # Establish that the response is the type that we expect. @@ -8789,6 +8825,7 @@ def test_update_instance_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -8833,6 +8870,7 @@ def test_upgrade_instance_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.upgrade_instance(request) @@ -8863,6 +8901,7 @@ def test_upgrade_instance_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.upgrade_instance(request) # Establish that the response is the type that we expect. @@ -8904,6 +8943,7 @@ def test_upgrade_instance_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -8948,6 +8988,7 @@ def test_import_instance_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.import_instance(request) @@ -8978,6 +9019,7 @@ def test_import_instance_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.import_instance(request) # Establish that the response is the type that we expect. @@ -9019,6 +9061,7 @@ def test_import_instance_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -9063,6 +9106,7 @@ def test_export_instance_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.export_instance(request) @@ -9093,6 +9137,7 @@ def test_export_instance_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.export_instance(request) # Establish that the response is the type that we expect. @@ -9134,6 +9179,7 @@ def test_export_instance_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -9178,6 +9224,7 @@ def test_failover_instance_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.failover_instance(request) @@ -9208,6 +9255,7 @@ def test_failover_instance_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.failover_instance(request) # Establish that the response is the type that we expect. @@ -9249,6 +9297,7 @@ def test_failover_instance_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -9293,6 +9342,7 @@ def test_delete_instance_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_instance(request) @@ -9323,6 +9373,7 @@ def test_delete_instance_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_instance(request) # Establish that the response is the type that we expect. @@ -9364,6 +9415,7 @@ def test_delete_instance_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -9408,6 +9460,7 @@ def test_reschedule_maintenance_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.reschedule_maintenance(request) @@ -9438,6 +9491,7 @@ def test_reschedule_maintenance_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.reschedule_maintenance(request) # Establish that the response is the type that we expect. @@ -9479,6 +9533,7 @@ def test_reschedule_maintenance_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager/gapic_version.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager/gapic_version.py index 0b9427f4e8a5..558c8aab67c5 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager/gapic_version.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.13.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/gapic_version.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/gapic_version.py index 0b9427f4e8a5..558c8aab67c5 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/gapic_version.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.13.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/async_client.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/async_client.py index b27e74377692..49d8554c6bf0 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/async_client.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -57,6 +58,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, FoldersTransport from .transports.grpc_asyncio import FoldersGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class FoldersAsyncClient: """Manages Cloud Platform folder resources. @@ -258,6 +268,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.resourcemanager_v3.FoldersAsyncClient`.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "credentialsType": None, + }, + ) + async def get_folder( self, request: Optional[Union[folders.GetFolderRequest, dict]] = None, @@ -265,7 +297,7 @@ async def get_folder( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> folders.Folder: r"""Retrieves a folder identified by the supplied resource name. Valid folder resource names have the format @@ -312,8 +344,10 @@ async def sample_get_folder(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.types.Folder: @@ -375,7 +409,7 @@ async def list_folders( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListFoldersAsyncPager: r"""Lists the folders that are direct descendants of supplied parent resource. ``list()`` provides a strongly consistent view of the @@ -434,8 +468,10 @@ async def sample_list_folders(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.services.folders.pagers.ListFoldersAsyncPager: @@ -504,7 +540,7 @@ async def search_folders( query: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.SearchFoldersAsyncPager: r"""Search for folders that match specific filter criteria. ``search()`` provides an eventually consistent view of the @@ -587,8 +623,10 @@ async def sample_search_folders(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.services.folders.pagers.SearchFoldersAsyncPager: @@ -657,7 +695,7 @@ async def create_folder( folder: Optional[folders.Folder] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Creates a folder in the resource hierarchy. Returns an ``Operation`` which can be used to track the progress of the @@ -737,8 +775,10 @@ async def sample_create_folder(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -804,7 +844,7 @@ async def update_folder( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Updates a folder, changing its ``display_name``. Changes to the folder ``display_name`` will be rejected if they violate either @@ -885,8 +925,10 @@ async def sample_update_folder(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -962,7 +1004,7 @@ async def move_folder( destination_parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Moves a folder under a new resource parent. Returns an ``Operation`` which can be used to track the progress of the @@ -1036,8 +1078,10 @@ async def sample_move_folder(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1110,7 +1154,7 @@ async def delete_folder( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Requests deletion of a folder. The folder is moved into the [DELETE_REQUESTED][google.cloud.resourcemanager.v3.Folder.State.DELETE_REQUESTED] @@ -1168,8 +1212,10 @@ async def sample_delete_folder(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1240,7 +1286,7 @@ async def undelete_folder( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Cancels the deletion request for a folder. This method may be called on a folder in any state. If the folder is in the @@ -1299,8 +1345,10 @@ async def sample_undelete_folder(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1371,7 +1419,7 @@ async def get_iam_policy( resource: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Gets the access control policy for a folder. The returned policy may be empty if no such policy or resource exists. The @@ -1422,8 +1470,10 @@ async def sample_get_iam_policy(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.policy_pb2.Policy: @@ -1509,7 +1559,7 @@ async def set_iam_policy( resource: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Sets the access control policy on a folder, replacing any existing policy. The ``resource`` field should be the folder's @@ -1559,8 +1609,10 @@ async def sample_set_iam_policy(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.policy_pb2.Policy: @@ -1647,7 +1699,7 @@ async def test_iam_permissions( permissions: Optional[MutableSequence[str]] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: r"""Returns permissions that a caller has on the specified folder. The ``resource`` field should be the folder's resource name, for @@ -1707,8 +1759,10 @@ async def sample_test_iam_permissions(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: @@ -1765,7 +1819,7 @@ async def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -1776,8 +1830,10 @@ async def get_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/client.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/client.py index b742c52dc8b8..38bccb239b15 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/client.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.iam.v1 import iam_policy_pb2 # type: ignore @@ -581,6 +591,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -643,6 +657,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.resourcemanager_v3.FoldersClient`.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "credentialsType": None, + }, + ) + def get_folder( self, request: Optional[Union[folders.GetFolderRequest, dict]] = None, @@ -650,7 +687,7 @@ def get_folder( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> folders.Folder: r"""Retrieves a folder identified by the supplied resource name. Valid folder resource names have the format @@ -697,8 +734,10 @@ def sample_get_folder(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.types.Folder: @@ -757,7 +796,7 @@ def list_folders( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListFoldersPager: r"""Lists the folders that are direct descendants of supplied parent resource. ``list()`` provides a strongly consistent view of the @@ -816,8 +855,10 @@ def sample_list_folders(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.services.folders.pagers.ListFoldersPager: @@ -883,7 +924,7 @@ def search_folders( query: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.SearchFoldersPager: r"""Search for folders that match specific filter criteria. ``search()`` provides an eventually consistent view of the @@ -966,8 +1007,10 @@ def sample_search_folders(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.services.folders.pagers.SearchFoldersPager: @@ -1033,7 +1076,7 @@ def create_folder( folder: Optional[folders.Folder] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Creates a folder in the resource hierarchy. Returns an ``Operation`` which can be used to track the progress of the @@ -1113,8 +1156,10 @@ def sample_create_folder(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1177,7 +1222,7 @@ def update_folder( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Updates a folder, changing its ``display_name``. Changes to the folder ``display_name`` will be rejected if they violate either @@ -1258,8 +1303,10 @@ def sample_update_folder(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1332,7 +1379,7 @@ def move_folder( destination_parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Moves a folder under a new resource parent. Returns an ``Operation`` which can be used to track the progress of the @@ -1406,8 +1453,10 @@ def sample_move_folder(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1477,7 +1526,7 @@ def delete_folder( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Requests deletion of a folder. The folder is moved into the [DELETE_REQUESTED][google.cloud.resourcemanager.v3.Folder.State.DELETE_REQUESTED] @@ -1535,8 +1584,10 @@ def sample_delete_folder(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1604,7 +1655,7 @@ def undelete_folder( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Cancels the deletion request for a folder. This method may be called on a folder in any state. If the folder is in the @@ -1663,8 +1714,10 @@ def sample_undelete_folder(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1732,7 +1785,7 @@ def get_iam_policy( resource: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Gets the access control policy for a folder. The returned policy may be empty if no such policy or resource exists. The @@ -1783,8 +1836,10 @@ def sample_get_iam_policy(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.policy_pb2.Policy: @@ -1871,7 +1926,7 @@ def set_iam_policy( resource: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Sets the access control policy on a folder, replacing any existing policy. The ``resource`` field should be the folder's @@ -1921,8 +1976,10 @@ def sample_set_iam_policy(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.policy_pb2.Policy: @@ -2010,7 +2067,7 @@ def test_iam_permissions( permissions: Optional[MutableSequence[str]] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: r"""Returns permissions that a caller has on the specified folder. The ``resource`` field should be the folder's resource name, for @@ -2070,8 +2127,10 @@ def sample_test_iam_permissions(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: @@ -2142,7 +2201,7 @@ def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -2153,8 +2212,10 @@ def get_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/pagers.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/pagers.py index 112332233e55..f19010b37c0f 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/pagers.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -81,8 +81,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = folders.ListFoldersRequest(request) @@ -141,7 +143,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -155,8 +157,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = folders.ListFoldersRequest(request) @@ -219,7 +223,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -233,8 +237,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = folders.SearchFoldersRequest(request) @@ -293,7 +299,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -307,8 +313,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = folders.SearchFoldersRequest(request) diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/transports/grpc.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/transports/grpc.py index 00645f337ac0..a09d63b4dc41 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/transports/grpc.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -23,12 +26,90 @@ from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.resourcemanager_v3.types import folders from .base import DEFAULT_CLIENT_INFO, FoldersTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class FoldersGrpcTransport(FoldersTransport): """gRPC backend transport for Folders. @@ -186,7 +267,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -250,7 +336,9 @@ def operations_client(self) -> operations_v1.OperationsClient: """ # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + self._operations_client = operations_v1.OperationsClient( + self._logged_channel + ) # Return the client from cache. return self._operations_client @@ -276,7 +364,7 @@ def get_folder(self) -> Callable[[folders.GetFolderRequest], folders.Folder]: # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_folder" not in self._stubs: - self._stubs["get_folder"] = self.grpc_channel.unary_unary( + self._stubs["get_folder"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Folders/GetFolder", request_serializer=folders.GetFolderRequest.serialize, response_deserializer=folders.Folder.deserialize, @@ -308,7 +396,7 @@ def list_folders( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_folders" not in self._stubs: - self._stubs["list_folders"] = self.grpc_channel.unary_unary( + self._stubs["list_folders"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Folders/ListFolders", request_serializer=folders.ListFoldersRequest.serialize, response_deserializer=folders.ListFoldersResponse.deserialize, @@ -340,7 +428,7 @@ def search_folders( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "search_folders" not in self._stubs: - self._stubs["search_folders"] = self.grpc_channel.unary_unary( + self._stubs["search_folders"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Folders/SearchFolders", request_serializer=folders.SearchFoldersRequest.serialize, response_deserializer=folders.SearchFoldersResponse.deserialize, @@ -394,7 +482,7 @@ def create_folder( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_folder" not in self._stubs: - self._stubs["create_folder"] = self.grpc_channel.unary_unary( + self._stubs["create_folder"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Folders/CreateFolder", request_serializer=folders.CreateFolderRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -437,7 +525,7 @@ def update_folder( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_folder" not in self._stubs: - self._stubs["update_folder"] = self.grpc_channel.unary_unary( + self._stubs["update_folder"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Folders/UpdateFolder", request_serializer=folders.UpdateFolderRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -480,7 +568,7 @@ def move_folder( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "move_folder" not in self._stubs: - self._stubs["move_folder"] = self.grpc_channel.unary_unary( + self._stubs["move_folder"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Folders/MoveFolder", request_serializer=folders.MoveFolderRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -517,7 +605,7 @@ def delete_folder( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_folder" not in self._stubs: - self._stubs["delete_folder"] = self.grpc_channel.unary_unary( + self._stubs["delete_folder"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Folders/DeleteFolder", request_serializer=folders.DeleteFolderRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -555,7 +643,7 @@ def undelete_folder( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "undelete_folder" not in self._stubs: - self._stubs["undelete_folder"] = self.grpc_channel.unary_unary( + self._stubs["undelete_folder"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Folders/UndeleteFolder", request_serializer=folders.UndeleteFolderRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -586,7 +674,7 @@ def get_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_iam_policy" not in self._stubs: - self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["get_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Folders/GetIamPolicy", request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -616,7 +704,7 @@ def set_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "set_iam_policy" not in self._stubs: - self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["set_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Folders/SetIamPolicy", request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -649,7 +737,7 @@ def test_iam_permissions( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "test_iam_permissions" not in self._stubs: - self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + self._stubs["test_iam_permissions"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Folders/TestIamPermissions", request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, @@ -657,7 +745,7 @@ def test_iam_permissions( return self._stubs["test_iam_permissions"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def get_operation( @@ -669,7 +757,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/transports/grpc_asyncio.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/transports/grpc_asyncio.py index 54d509dcd97a..70bf82f87271 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/transports/grpc_asyncio.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -25,14 +28,93 @@ from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.resourcemanager_v3.types import folders from .base import DEFAULT_CLIENT_INFO, FoldersTransport from .grpc import FoldersGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class FoldersGrpcAsyncIOTransport(FoldersTransport): """gRPC AsyncIO backend transport for Folders. @@ -233,10 +315,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -259,7 +344,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel + self._logged_channel ) # Return the client from cache. @@ -288,7 +373,7 @@ def get_folder( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_folder" not in self._stubs: - self._stubs["get_folder"] = self.grpc_channel.unary_unary( + self._stubs["get_folder"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Folders/GetFolder", request_serializer=folders.GetFolderRequest.serialize, response_deserializer=folders.Folder.deserialize, @@ -320,7 +405,7 @@ def list_folders( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_folders" not in self._stubs: - self._stubs["list_folders"] = self.grpc_channel.unary_unary( + self._stubs["list_folders"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Folders/ListFolders", request_serializer=folders.ListFoldersRequest.serialize, response_deserializer=folders.ListFoldersResponse.deserialize, @@ -354,7 +439,7 @@ def search_folders( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "search_folders" not in self._stubs: - self._stubs["search_folders"] = self.grpc_channel.unary_unary( + self._stubs["search_folders"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Folders/SearchFolders", request_serializer=folders.SearchFoldersRequest.serialize, response_deserializer=folders.SearchFoldersResponse.deserialize, @@ -408,7 +493,7 @@ def create_folder( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_folder" not in self._stubs: - self._stubs["create_folder"] = self.grpc_channel.unary_unary( + self._stubs["create_folder"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Folders/CreateFolder", request_serializer=folders.CreateFolderRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -451,7 +536,7 @@ def update_folder( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_folder" not in self._stubs: - self._stubs["update_folder"] = self.grpc_channel.unary_unary( + self._stubs["update_folder"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Folders/UpdateFolder", request_serializer=folders.UpdateFolderRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -494,7 +579,7 @@ def move_folder( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "move_folder" not in self._stubs: - self._stubs["move_folder"] = self.grpc_channel.unary_unary( + self._stubs["move_folder"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Folders/MoveFolder", request_serializer=folders.MoveFolderRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -531,7 +616,7 @@ def delete_folder( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_folder" not in self._stubs: - self._stubs["delete_folder"] = self.grpc_channel.unary_unary( + self._stubs["delete_folder"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Folders/DeleteFolder", request_serializer=folders.DeleteFolderRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -569,7 +654,7 @@ def undelete_folder( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "undelete_folder" not in self._stubs: - self._stubs["undelete_folder"] = self.grpc_channel.unary_unary( + self._stubs["undelete_folder"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Folders/UndeleteFolder", request_serializer=folders.UndeleteFolderRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -600,7 +685,7 @@ def get_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_iam_policy" not in self._stubs: - self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["get_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Folders/GetIamPolicy", request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -630,7 +715,7 @@ def set_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "set_iam_policy" not in self._stubs: - self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["set_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Folders/SetIamPolicy", request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -663,7 +748,7 @@ def test_iam_permissions( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "test_iam_permissions" not in self._stubs: - self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + self._stubs["test_iam_permissions"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Folders/TestIamPermissions", request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, @@ -768,7 +853,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: @@ -784,7 +869,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/transports/rest.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/transports/rest.py index bbf5ab0b9483..ea8b18e665ed 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/transports/rest.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/folders/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -40,6 +40,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -158,8 +166,10 @@ def post_update_folder(self, response): """ def pre_create_folder( - self, request: folders.CreateFolderRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[folders.CreateFolderRequest, Sequence[Tuple[str, str]]]: + self, + request: folders.CreateFolderRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[folders.CreateFolderRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for create_folder Override in a subclass to manipulate the request or metadata @@ -179,8 +189,10 @@ def post_create_folder( return response def pre_delete_folder( - self, request: folders.DeleteFolderRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[folders.DeleteFolderRequest, Sequence[Tuple[str, str]]]: + self, + request: folders.DeleteFolderRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[folders.DeleteFolderRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for delete_folder Override in a subclass to manipulate the request or metadata @@ -200,8 +212,10 @@ def post_delete_folder( return response def pre_get_folder( - self, request: folders.GetFolderRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[folders.GetFolderRequest, Sequence[Tuple[str, str]]]: + self, + request: folders.GetFolderRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[folders.GetFolderRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for get_folder Override in a subclass to manipulate the request or metadata @@ -221,8 +235,10 @@ def post_get_folder(self, response: folders.Folder) -> folders.Folder: def pre_get_iam_policy( self, request: iam_policy_pb2.GetIamPolicyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[iam_policy_pb2.GetIamPolicyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + iam_policy_pb2.GetIamPolicyRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_iam_policy Override in a subclass to manipulate the request or metadata @@ -240,8 +256,10 @@ def post_get_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: return response def pre_list_folders( - self, request: folders.ListFoldersRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[folders.ListFoldersRequest, Sequence[Tuple[str, str]]]: + self, + request: folders.ListFoldersRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[folders.ListFoldersRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for list_folders Override in a subclass to manipulate the request or metadata @@ -261,8 +279,10 @@ def post_list_folders( return response def pre_move_folder( - self, request: folders.MoveFolderRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[folders.MoveFolderRequest, Sequence[Tuple[str, str]]]: + self, + request: folders.MoveFolderRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[folders.MoveFolderRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for move_folder Override in a subclass to manipulate the request or metadata @@ -282,8 +302,10 @@ def post_move_folder( return response def pre_search_folders( - self, request: folders.SearchFoldersRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[folders.SearchFoldersRequest, Sequence[Tuple[str, str]]]: + self, + request: folders.SearchFoldersRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[folders.SearchFoldersRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for search_folders Override in a subclass to manipulate the request or metadata @@ -305,8 +327,10 @@ def post_search_folders( def pre_set_iam_policy( self, request: iam_policy_pb2.SetIamPolicyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[iam_policy_pb2.SetIamPolicyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + iam_policy_pb2.SetIamPolicyRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for set_iam_policy Override in a subclass to manipulate the request or metadata @@ -326,8 +350,11 @@ def post_set_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: def pre_test_iam_permissions( self, request: iam_policy_pb2.TestIamPermissionsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[iam_policy_pb2.TestIamPermissionsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + iam_policy_pb2.TestIamPermissionsRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for test_iam_permissions Override in a subclass to manipulate the request or metadata @@ -349,8 +376,8 @@ def post_test_iam_permissions( def pre_undelete_folder( self, request: folders.UndeleteFolderRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[folders.UndeleteFolderRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[folders.UndeleteFolderRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for undelete_folder Override in a subclass to manipulate the request or metadata @@ -370,8 +397,10 @@ def post_undelete_folder( return response def pre_update_folder( - self, request: folders.UpdateFolderRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[folders.UpdateFolderRequest, Sequence[Tuple[str, str]]]: + self, + request: folders.UpdateFolderRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[folders.UpdateFolderRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for update_folder Override in a subclass to manipulate the request or metadata @@ -393,8 +422,10 @@ def post_update_folder( def pre_get_operation( self, request: operations_pb2.GetOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.GetOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.GetOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_operation Override in a subclass to manipulate the request or metadata @@ -571,7 +602,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the create folder method over HTTP. @@ -581,8 +612,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -595,6 +628,7 @@ def __call__( http_options = ( _BaseFoldersRestTransport._BaseCreateFolder._get_http_options() ) + request, metadata = self._interceptor.pre_create_folder(request, metadata) transcoded_request = ( _BaseFoldersRestTransport._BaseCreateFolder._get_transcoded_request( @@ -613,6 +647,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.FoldersClient.CreateFolder", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "CreateFolder", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = FoldersRestTransport._CreateFolder._get_response( self._host, @@ -632,7 +693,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_folder(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.FoldersClient.create_folder", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "CreateFolder", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DeleteFolder(_BaseFoldersRestTransport._BaseDeleteFolder, FoldersRestStub): @@ -667,7 +750,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the delete folder method over HTTP. @@ -677,8 +760,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -691,6 +776,7 @@ def __call__( http_options = ( _BaseFoldersRestTransport._BaseDeleteFolder._get_http_options() ) + request, metadata = self._interceptor.pre_delete_folder(request, metadata) transcoded_request = ( _BaseFoldersRestTransport._BaseDeleteFolder._get_transcoded_request( @@ -705,6 +791,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.FoldersClient.DeleteFolder", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "DeleteFolder", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = FoldersRestTransport._DeleteFolder._get_response( self._host, @@ -723,7 +836,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_delete_folder(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.FoldersClient.delete_folder", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "DeleteFolder", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetFolder(_BaseFoldersRestTransport._BaseGetFolder, FoldersRestStub): @@ -758,7 +893,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> folders.Folder: r"""Call the get folder method over HTTP. @@ -768,8 +903,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.folders.Folder: @@ -780,6 +917,7 @@ def __call__( """ http_options = _BaseFoldersRestTransport._BaseGetFolder._get_http_options() + request, metadata = self._interceptor.pre_get_folder(request, metadata) transcoded_request = ( _BaseFoldersRestTransport._BaseGetFolder._get_transcoded_request( @@ -794,6 +932,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.FoldersClient.GetFolder", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "GetFolder", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = FoldersRestTransport._GetFolder._get_response( self._host, @@ -814,7 +979,29 @@ def __call__( pb_resp = folders.Folder.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_folder(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = folders.Folder.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.FoldersClient.get_folder", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "GetFolder", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetIamPolicy(_BaseFoldersRestTransport._BaseGetIamPolicy, FoldersRestStub): @@ -850,7 +1037,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Call the get iam policy method over HTTP. @@ -860,8 +1047,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.policy_pb2.Policy: @@ -946,6 +1135,7 @@ def __call__( http_options = ( _BaseFoldersRestTransport._BaseGetIamPolicy._get_http_options() ) + request, metadata = self._interceptor.pre_get_iam_policy(request, metadata) transcoded_request = ( _BaseFoldersRestTransport._BaseGetIamPolicy._get_transcoded_request( @@ -964,6 +1154,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.FoldersClient.GetIamPolicy", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "GetIamPolicy", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = FoldersRestTransport._GetIamPolicy._get_response( self._host, @@ -985,7 +1202,29 @@ def __call__( pb_resp = resp json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_iam_policy(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.FoldersClient.get_iam_policy", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "GetIamPolicy", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListFolders(_BaseFoldersRestTransport._BaseListFolders, FoldersRestStub): @@ -1020,7 +1259,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> folders.ListFoldersResponse: r"""Call the list folders method over HTTP. @@ -1030,8 +1269,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.folders.ListFoldersResponse: @@ -1041,6 +1282,7 @@ def __call__( http_options = ( _BaseFoldersRestTransport._BaseListFolders._get_http_options() ) + request, metadata = self._interceptor.pre_list_folders(request, metadata) transcoded_request = ( _BaseFoldersRestTransport._BaseListFolders._get_transcoded_request( @@ -1055,6 +1297,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.FoldersClient.ListFolders", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "ListFolders", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = FoldersRestTransport._ListFolders._get_response( self._host, @@ -1075,7 +1344,29 @@ def __call__( pb_resp = folders.ListFoldersResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_folders(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = folders.ListFoldersResponse.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.FoldersClient.list_folders", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "ListFolders", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _MoveFolder(_BaseFoldersRestTransport._BaseMoveFolder, FoldersRestStub): @@ -1111,7 +1402,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the move folder method over HTTP. @@ -1121,8 +1412,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1133,6 +1426,7 @@ def __call__( """ http_options = _BaseFoldersRestTransport._BaseMoveFolder._get_http_options() + request, metadata = self._interceptor.pre_move_folder(request, metadata) transcoded_request = ( _BaseFoldersRestTransport._BaseMoveFolder._get_transcoded_request( @@ -1151,6 +1445,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.FoldersClient.MoveFolder", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "MoveFolder", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = FoldersRestTransport._MoveFolder._get_response( self._host, @@ -1170,7 +1491,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_move_folder(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.FoldersClient.move_folder", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "MoveFolder", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _SearchFolders(_BaseFoldersRestTransport._BaseSearchFolders, FoldersRestStub): @@ -1205,7 +1548,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> folders.SearchFoldersResponse: r"""Call the search folders method over HTTP. @@ -1216,8 +1559,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.folders.SearchFoldersResponse: @@ -1229,6 +1574,7 @@ def __call__( http_options = ( _BaseFoldersRestTransport._BaseSearchFolders._get_http_options() ) + request, metadata = self._interceptor.pre_search_folders(request, metadata) transcoded_request = ( _BaseFoldersRestTransport._BaseSearchFolders._get_transcoded_request( @@ -1243,6 +1589,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.FoldersClient.SearchFolders", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "SearchFolders", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = FoldersRestTransport._SearchFolders._get_response( self._host, @@ -1263,7 +1636,29 @@ def __call__( pb_resp = folders.SearchFoldersResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_search_folders(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = folders.SearchFoldersResponse.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.FoldersClient.search_folders", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "SearchFolders", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _SetIamPolicy(_BaseFoldersRestTransport._BaseSetIamPolicy, FoldersRestStub): @@ -1299,7 +1694,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Call the set iam policy method over HTTP. @@ -1309,8 +1704,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.policy_pb2.Policy: @@ -1395,6 +1792,7 @@ def __call__( http_options = ( _BaseFoldersRestTransport._BaseSetIamPolicy._get_http_options() ) + request, metadata = self._interceptor.pre_set_iam_policy(request, metadata) transcoded_request = ( _BaseFoldersRestTransport._BaseSetIamPolicy._get_transcoded_request( @@ -1413,6 +1811,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.FoldersClient.SetIamPolicy", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "SetIamPolicy", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = FoldersRestTransport._SetIamPolicy._get_response( self._host, @@ -1434,7 +1859,29 @@ def __call__( pb_resp = resp json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_set_iam_policy(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.FoldersClient.set_iam_policy", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "SetIamPolicy", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _TestIamPermissions( @@ -1472,7 +1919,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: r"""Call the test iam permissions method over HTTP. @@ -1482,8 +1929,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.iam_policy_pb2.TestIamPermissionsResponse: @@ -1493,6 +1942,7 @@ def __call__( http_options = ( _BaseFoldersRestTransport._BaseTestIamPermissions._get_http_options() ) + request, metadata = self._interceptor.pre_test_iam_permissions( request, metadata ) @@ -1509,6 +1959,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.FoldersClient.TestIamPermissions", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "TestIamPermissions", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = FoldersRestTransport._TestIamPermissions._get_response( self._host, @@ -1530,7 +2007,29 @@ def __call__( pb_resp = resp json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_test_iam_permissions(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.FoldersClient.test_iam_permissions", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "TestIamPermissions", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UndeleteFolder( @@ -1568,7 +2067,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the undelete folder method over HTTP. @@ -1578,8 +2077,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1592,6 +2093,7 @@ def __call__( http_options = ( _BaseFoldersRestTransport._BaseUndeleteFolder._get_http_options() ) + request, metadata = self._interceptor.pre_undelete_folder(request, metadata) transcoded_request = ( _BaseFoldersRestTransport._BaseUndeleteFolder._get_transcoded_request( @@ -1610,6 +2112,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.FoldersClient.UndeleteFolder", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "UndeleteFolder", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = FoldersRestTransport._UndeleteFolder._get_response( self._host, @@ -1629,7 +2158,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_undelete_folder(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.FoldersClient.undelete_folder", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "UndeleteFolder", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateFolder(_BaseFoldersRestTransport._BaseUpdateFolder, FoldersRestStub): @@ -1665,7 +2216,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the update folder method over HTTP. @@ -1682,8 +2233,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1696,6 +2249,7 @@ def __call__( http_options = ( _BaseFoldersRestTransport._BaseUpdateFolder._get_http_options() ) + request, metadata = self._interceptor.pre_update_folder(request, metadata) transcoded_request = ( _BaseFoldersRestTransport._BaseUpdateFolder._get_transcoded_request( @@ -1714,6 +2268,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.FoldersClient.UpdateFolder", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "UpdateFolder", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = FoldersRestTransport._UpdateFolder._get_response( self._host, @@ -1733,7 +2314,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_folder(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.FoldersClient.update_folder", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "UpdateFolder", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property @@ -1861,7 +2464,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the get operation method over HTTP. @@ -1871,8 +2474,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: operations_pb2.Operation: Response from GetOperation method. @@ -1881,6 +2486,7 @@ def __call__( http_options = ( _BaseFoldersRestTransport._BaseGetOperation._get_http_options() ) + request, metadata = self._interceptor.pre_get_operation(request, metadata) transcoded_request = ( _BaseFoldersRestTransport._BaseGetOperation._get_transcoded_request( @@ -1895,6 +2501,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.FoldersClient.GetOperation", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "GetOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = FoldersRestTransport._GetOperation._get_response( self._host, @@ -1914,6 +2547,27 @@ def __call__( resp = operations_pb2.Operation() resp = json_format.Parse(content, resp) resp = self._interceptor.post_get_operation(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.FoldersAsyncClient.GetOperation", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Folders", + "rpcName": "GetOperation", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/async_client.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/async_client.py index f64be9dc0123..32441868bc37 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/async_client.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -54,6 +55,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, OrganizationsTransport from .transports.grpc_asyncio import OrganizationsGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class OrganizationsAsyncClient: """Allows users to manage their organization resources.""" @@ -259,6 +269,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.resourcemanager_v3.OrganizationsAsyncClient`.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Organizations", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.resourcemanager.v3.Organizations", + "credentialsType": None, + }, + ) + async def get_organization( self, request: Optional[Union[organizations.GetOrganizationRequest, dict]] = None, @@ -266,7 +298,7 @@ async def get_organization( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> organizations.Organization: r"""Fetches an organization resource identified by the specified resource name. @@ -314,8 +346,10 @@ async def sample_get_organization(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.types.Organization: @@ -378,7 +412,7 @@ async def search_organizations( query: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.SearchOrganizationsAsyncPager: r"""Searches organization resources that are visible to the user and satisfy the specified filter. This method returns organizations @@ -448,8 +482,10 @@ async def sample_search_organizations(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.services.organizations.pagers.SearchOrganizationsAsyncPager: @@ -518,7 +554,7 @@ async def get_iam_policy( resource: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Gets the access control policy for an organization resource. The policy may be empty if no such policy or resource exists. The @@ -571,8 +607,10 @@ async def sample_get_iam_policy(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.policy_pb2.Policy: @@ -658,7 +696,7 @@ async def set_iam_policy( resource: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Sets the access control policy on an organization resource. Replaces any existing policy. The ``resource`` field should be @@ -711,8 +749,10 @@ async def sample_set_iam_policy(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.policy_pb2.Policy: @@ -799,7 +839,7 @@ async def test_iam_permissions( permissions: Optional[MutableSequence[str]] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: r"""Returns the permissions that a caller has on the specified organization. The ``resource`` field should be the @@ -859,8 +899,10 @@ async def sample_test_iam_permissions(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: @@ -917,7 +959,7 @@ async def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -928,8 +970,10 @@ async def get_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/client.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/client.py index 8db4d927e4be..eec927ece34a 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/client.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -574,6 +584,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -639,6 +653,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.resourcemanager_v3.OrganizationsClient`.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Organizations", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.resourcemanager.v3.Organizations", + "credentialsType": None, + }, + ) + def get_organization( self, request: Optional[Union[organizations.GetOrganizationRequest, dict]] = None, @@ -646,7 +683,7 @@ def get_organization( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> organizations.Organization: r"""Fetches an organization resource identified by the specified resource name. @@ -694,8 +731,10 @@ def sample_get_organization(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.types.Organization: @@ -755,7 +794,7 @@ def search_organizations( query: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.SearchOrganizationsPager: r"""Searches organization resources that are visible to the user and satisfy the specified filter. This method returns organizations @@ -825,8 +864,10 @@ def sample_search_organizations(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.services.organizations.pagers.SearchOrganizationsPager: @@ -892,7 +933,7 @@ def get_iam_policy( resource: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Gets the access control policy for an organization resource. The policy may be empty if no such policy or resource exists. The @@ -945,8 +986,10 @@ def sample_get_iam_policy(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.policy_pb2.Policy: @@ -1033,7 +1076,7 @@ def set_iam_policy( resource: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Sets the access control policy on an organization resource. Replaces any existing policy. The ``resource`` field should be @@ -1086,8 +1129,10 @@ def sample_set_iam_policy(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.policy_pb2.Policy: @@ -1175,7 +1220,7 @@ def test_iam_permissions( permissions: Optional[MutableSequence[str]] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: r"""Returns the permissions that a caller has on the specified organization. The ``resource`` field should be the @@ -1235,8 +1280,10 @@ def sample_test_iam_permissions(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: @@ -1307,7 +1354,7 @@ def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -1318,8 +1365,10 @@ def get_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/pagers.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/pagers.py index 53419bd1ca3f..430b3e48b173 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/pagers.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -81,8 +81,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = organizations.SearchOrganizationsRequest(request) @@ -141,7 +143,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -155,8 +157,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = organizations.SearchOrganizationsRequest(request) diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/transports/grpc.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/transports/grpc.py index e57984f172e4..463d86620777 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/transports/grpc.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -23,12 +26,90 @@ from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.resourcemanager_v3.types import organizations from .base import DEFAULT_CLIENT_INFO, OrganizationsTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Organizations", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Organizations", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class OrganizationsGrpcTransport(OrganizationsTransport): """gRPC backend transport for Organizations. @@ -182,7 +263,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -257,7 +343,7 @@ def get_organization( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_organization" not in self._stubs: - self._stubs["get_organization"] = self.grpc_channel.unary_unary( + self._stubs["get_organization"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Organizations/GetOrganization", request_serializer=organizations.GetOrganizationRequest.serialize, response_deserializer=organizations.Organization.deserialize, @@ -293,7 +379,7 @@ def search_organizations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "search_organizations" not in self._stubs: - self._stubs["search_organizations"] = self.grpc_channel.unary_unary( + self._stubs["search_organizations"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Organizations/SearchOrganizations", request_serializer=organizations.SearchOrganizationsRequest.serialize, response_deserializer=organizations.SearchOrganizationsResponse.deserialize, @@ -326,7 +412,7 @@ def get_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_iam_policy" not in self._stubs: - self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["get_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Organizations/GetIamPolicy", request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -359,7 +445,7 @@ def set_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "set_iam_policy" not in self._stubs: - self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["set_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Organizations/SetIamPolicy", request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -392,7 +478,7 @@ def test_iam_permissions( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "test_iam_permissions" not in self._stubs: - self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + self._stubs["test_iam_permissions"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Organizations/TestIamPermissions", request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, @@ -400,7 +486,7 @@ def test_iam_permissions( return self._stubs["test_iam_permissions"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def get_operation( @@ -412,7 +498,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/transports/grpc_asyncio.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/transports/grpc_asyncio.py index 23a93093f608..04acd8560eef 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/transports/grpc_asyncio.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -25,14 +28,93 @@ from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.resourcemanager_v3.types import organizations from .base import DEFAULT_CLIENT_INFO, OrganizationsTransport from .grpc import OrganizationsGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Organizations", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Organizations", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class OrganizationsGrpcAsyncIOTransport(OrganizationsTransport): """gRPC AsyncIO backend transport for Organizations. @@ -229,10 +311,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -267,7 +352,7 @@ def get_organization( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_organization" not in self._stubs: - self._stubs["get_organization"] = self.grpc_channel.unary_unary( + self._stubs["get_organization"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Organizations/GetOrganization", request_serializer=organizations.GetOrganizationRequest.serialize, response_deserializer=organizations.Organization.deserialize, @@ -303,7 +388,7 @@ def search_organizations( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "search_organizations" not in self._stubs: - self._stubs["search_organizations"] = self.grpc_channel.unary_unary( + self._stubs["search_organizations"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Organizations/SearchOrganizations", request_serializer=organizations.SearchOrganizationsRequest.serialize, response_deserializer=organizations.SearchOrganizationsResponse.deserialize, @@ -336,7 +421,7 @@ def get_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_iam_policy" not in self._stubs: - self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["get_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Organizations/GetIamPolicy", request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -369,7 +454,7 @@ def set_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "set_iam_policy" not in self._stubs: - self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["set_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Organizations/SetIamPolicy", request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -402,7 +487,7 @@ def test_iam_permissions( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "test_iam_permissions" not in self._stubs: - self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + self._stubs["test_iam_permissions"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Organizations/TestIamPermissions", request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, @@ -468,7 +553,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: @@ -484,7 +569,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/transports/rest.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/transports/rest.py index bd0543b86776..338156e473b6 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/transports/rest.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/organizations/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -40,6 +40,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -112,8 +120,10 @@ def post_test_iam_permissions(self, response): def pre_get_iam_policy( self, request: iam_policy_pb2.GetIamPolicyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[iam_policy_pb2.GetIamPolicyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + iam_policy_pb2.GetIamPolicyRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_iam_policy Override in a subclass to manipulate the request or metadata @@ -133,8 +143,10 @@ def post_get_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: def pre_get_organization( self, request: organizations.GetOrganizationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[organizations.GetOrganizationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + organizations.GetOrganizationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_organization Override in a subclass to manipulate the request or metadata @@ -156,8 +168,11 @@ def post_get_organization( def pre_search_organizations( self, request: organizations.SearchOrganizationsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[organizations.SearchOrganizationsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + organizations.SearchOrganizationsRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for search_organizations Override in a subclass to manipulate the request or metadata @@ -179,8 +194,10 @@ def post_search_organizations( def pre_set_iam_policy( self, request: iam_policy_pb2.SetIamPolicyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[iam_policy_pb2.SetIamPolicyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + iam_policy_pb2.SetIamPolicyRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for set_iam_policy Override in a subclass to manipulate the request or metadata @@ -200,8 +217,11 @@ def post_set_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: def pre_test_iam_permissions( self, request: iam_policy_pb2.TestIamPermissionsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[iam_policy_pb2.TestIamPermissionsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + iam_policy_pb2.TestIamPermissionsRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for test_iam_permissions Override in a subclass to manipulate the request or metadata @@ -223,8 +243,10 @@ def post_test_iam_permissions( def pre_get_operation( self, request: operations_pb2.GetOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.GetOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.GetOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_operation Override in a subclass to manipulate the request or metadata @@ -365,7 +387,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Call the get iam policy method over HTTP. @@ -375,8 +397,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.policy_pb2.Policy: @@ -461,6 +485,7 @@ def __call__( http_options = ( _BaseOrganizationsRestTransport._BaseGetIamPolicy._get_http_options() ) + request, metadata = self._interceptor.pre_get_iam_policy(request, metadata) transcoded_request = _BaseOrganizationsRestTransport._BaseGetIamPolicy._get_transcoded_request( http_options, request @@ -475,6 +500,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.OrganizationsClient.GetIamPolicy", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Organizations", + "rpcName": "GetIamPolicy", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OrganizationsRestTransport._GetIamPolicy._get_response( self._host, @@ -496,7 +548,29 @@ def __call__( pb_resp = resp json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_iam_policy(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.OrganizationsClient.get_iam_policy", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Organizations", + "rpcName": "GetIamPolicy", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetOrganization( @@ -533,7 +607,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> organizations.Organization: r"""Call the get organization method over HTTP. @@ -545,8 +619,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.organizations.Organization: @@ -560,6 +636,7 @@ def __call__( http_options = ( _BaseOrganizationsRestTransport._BaseGetOrganization._get_http_options() ) + request, metadata = self._interceptor.pre_get_organization( request, metadata ) @@ -572,6 +649,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.OrganizationsClient.GetOrganization", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Organizations", + "rpcName": "GetOrganization", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OrganizationsRestTransport._GetOrganization._get_response( self._host, @@ -592,7 +696,29 @@ def __call__( pb_resp = organizations.Organization.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_organization(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = organizations.Organization.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.OrganizationsClient.get_organization", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Organizations", + "rpcName": "GetOrganization", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _SearchOrganizations( @@ -629,7 +755,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> organizations.SearchOrganizationsResponse: r"""Call the search organizations method over HTTP. @@ -639,8 +765,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.organizations.SearchOrganizationsResponse: @@ -652,6 +780,7 @@ def __call__( http_options = ( _BaseOrganizationsRestTransport._BaseSearchOrganizations._get_http_options() ) + request, metadata = self._interceptor.pre_search_organizations( request, metadata ) @@ -664,6 +793,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.OrganizationsClient.SearchOrganizations", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Organizations", + "rpcName": "SearchOrganizations", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OrganizationsRestTransport._SearchOrganizations._get_response( self._host, @@ -684,7 +840,31 @@ def __call__( pb_resp = organizations.SearchOrganizationsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_search_organizations(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + organizations.SearchOrganizationsResponse.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.OrganizationsClient.search_organizations", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Organizations", + "rpcName": "SearchOrganizations", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _SetIamPolicy( @@ -722,7 +902,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Call the set iam policy method over HTTP. @@ -732,8 +912,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.policy_pb2.Policy: @@ -818,6 +1000,7 @@ def __call__( http_options = ( _BaseOrganizationsRestTransport._BaseSetIamPolicy._get_http_options() ) + request, metadata = self._interceptor.pre_set_iam_policy(request, metadata) transcoded_request = _BaseOrganizationsRestTransport._BaseSetIamPolicy._get_transcoded_request( http_options, request @@ -832,6 +1015,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.OrganizationsClient.SetIamPolicy", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Organizations", + "rpcName": "SetIamPolicy", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OrganizationsRestTransport._SetIamPolicy._get_response( self._host, @@ -853,7 +1063,29 @@ def __call__( pb_resp = resp json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_set_iam_policy(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.OrganizationsClient.set_iam_policy", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Organizations", + "rpcName": "SetIamPolicy", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _TestIamPermissions( @@ -891,7 +1123,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: r"""Call the test iam permissions method over HTTP. @@ -901,8 +1133,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.iam_policy_pb2.TestIamPermissionsResponse: @@ -912,6 +1146,7 @@ def __call__( http_options = ( _BaseOrganizationsRestTransport._BaseTestIamPermissions._get_http_options() ) + request, metadata = self._interceptor.pre_test_iam_permissions( request, metadata ) @@ -928,6 +1163,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.OrganizationsClient.TestIamPermissions", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Organizations", + "rpcName": "TestIamPermissions", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OrganizationsRestTransport._TestIamPermissions._get_response( self._host, @@ -949,7 +1211,29 @@ def __call__( pb_resp = resp json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_test_iam_permissions(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.OrganizationsClient.test_iam_permissions", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Organizations", + "rpcName": "TestIamPermissions", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property @@ -1036,7 +1320,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the get operation method over HTTP. @@ -1046,8 +1330,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: operations_pb2.Operation: Response from GetOperation method. @@ -1056,6 +1342,7 @@ def __call__( http_options = ( _BaseOrganizationsRestTransport._BaseGetOperation._get_http_options() ) + request, metadata = self._interceptor.pre_get_operation(request, metadata) transcoded_request = _BaseOrganizationsRestTransport._BaseGetOperation._get_transcoded_request( http_options, request @@ -1066,6 +1353,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.OrganizationsClient.GetOperation", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Organizations", + "rpcName": "GetOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = OrganizationsRestTransport._GetOperation._get_response( self._host, @@ -1085,6 +1399,27 @@ def __call__( resp = operations_pb2.Operation() resp = json_format.Parse(content, resp) resp = self._interceptor.post_get_operation(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.OrganizationsAsyncClient.GetOperation", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Organizations", + "rpcName": "GetOperation", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/async_client.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/async_client.py index 258d67302211..fb7fc0cbdcb9 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/async_client.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -57,6 +58,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, ProjectsTransport from .transports.grpc_asyncio import ProjectsGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class ProjectsAsyncClient: """Manages Google Cloud Projects.""" @@ -254,6 +264,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.resourcemanager_v3.ProjectsAsyncClient`.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "credentialsType": None, + }, + ) + async def get_project( self, request: Optional[Union[projects.GetProjectRequest, dict]] = None, @@ -261,7 +293,7 @@ async def get_project( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> projects.Project: r"""Retrieves the project identified by the specified ``name`` (for example, ``projects/415104041262``). @@ -310,8 +342,10 @@ async def sample_get_project(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.types.Project: @@ -374,7 +408,7 @@ async def list_projects( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListProjectsAsyncPager: r"""Lists projects that are direct children of the specified folder or organization resource. ``list()`` provides a strongly @@ -431,8 +465,10 @@ async def sample_list_projects(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.services.projects.pagers.ListProjectsAsyncPager: @@ -509,7 +545,7 @@ async def search_projects( query: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.SearchProjectsAsyncPager: r"""Search for projects that the caller has both ``resourcemanager.projects.get`` permission on, and also satisfy @@ -607,8 +643,10 @@ async def sample_search_projects(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.services.projects.pagers.SearchProjectsAsyncPager: @@ -682,7 +720,7 @@ async def create_project( project: Optional[projects.Project] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Request that a new project be created. The result is an ``Operation`` which can be used to track the creation process. @@ -743,8 +781,10 @@ async def sample_create_project(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -811,7 +851,7 @@ async def update_project( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Updates the ``display_name`` and labels of the project identified by the specified ``name`` (for example, @@ -877,8 +917,10 @@ async def sample_update_project(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -955,7 +997,7 @@ async def move_project( destination_parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Move a project to another place in your resource hierarchy, under a new resource parent. @@ -1027,8 +1069,10 @@ async def sample_move_project(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1102,7 +1146,7 @@ async def delete_project( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Marks the project identified by the specified ``name`` (for example, ``projects/415104041262``) for deletion. @@ -1184,8 +1228,10 @@ async def sample_delete_project(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1257,7 +1303,7 @@ async def undelete_project( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Restores the project identified by the specified ``name`` (for example, ``projects/415104041262``). You can only use this @@ -1315,8 +1361,10 @@ async def sample_undelete_project(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -1388,7 +1436,7 @@ async def get_iam_policy( resource: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Returns the IAM access control policy for the specified project, in the format ``projects/{ProjectIdOrNumber}`` e.g. @@ -1437,8 +1485,10 @@ async def sample_get_iam_policy(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.policy_pb2.Policy: @@ -1524,7 +1574,7 @@ async def set_iam_policy( resource: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Sets the IAM access control policy for the specified project, in the format ``projects/{ProjectIdOrNumber}`` e.g. projects/123. @@ -1617,8 +1667,10 @@ async def sample_set_iam_policy(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.policy_pb2.Policy: @@ -1705,7 +1757,7 @@ async def test_iam_permissions( permissions: Optional[MutableSequence[str]] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: r"""Returns permissions that a caller has on the specified project, in the format ``projects/{ProjectIdOrNumber}`` e.g. @@ -1763,8 +1815,10 @@ async def sample_test_iam_permissions(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: @@ -1821,7 +1875,7 @@ async def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -1832,8 +1886,10 @@ async def get_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/client.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/client.py index d8fb12662a45..9f50334b832e 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/client.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.iam.v1 import iam_policy_pb2 # type: ignore @@ -577,6 +587,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -639,6 +653,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.resourcemanager_v3.ProjectsClient`.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "credentialsType": None, + }, + ) + def get_project( self, request: Optional[Union[projects.GetProjectRequest, dict]] = None, @@ -646,7 +683,7 @@ def get_project( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> projects.Project: r"""Retrieves the project identified by the specified ``name`` (for example, ``projects/415104041262``). @@ -695,8 +732,10 @@ def sample_get_project(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.types.Project: @@ -756,7 +795,7 @@ def list_projects( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListProjectsPager: r"""Lists projects that are direct children of the specified folder or organization resource. ``list()`` provides a strongly @@ -813,8 +852,10 @@ def sample_list_projects(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.services.projects.pagers.ListProjectsPager: @@ -888,7 +929,7 @@ def search_projects( query: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.SearchProjectsPager: r"""Search for projects that the caller has both ``resourcemanager.projects.get`` permission on, and also satisfy @@ -986,8 +1027,10 @@ def sample_search_projects(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.services.projects.pagers.SearchProjectsPager: @@ -1058,7 +1101,7 @@ def create_project( project: Optional[projects.Project] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Request that a new project be created. The result is an ``Operation`` which can be used to track the creation process. @@ -1119,8 +1162,10 @@ def sample_create_project(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1184,7 +1229,7 @@ def update_project( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Updates the ``display_name`` and labels of the project identified by the specified ``name`` (for example, @@ -1250,8 +1295,10 @@ def sample_update_project(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1325,7 +1372,7 @@ def move_project( destination_parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Move a project to another place in your resource hierarchy, under a new resource parent. @@ -1397,8 +1444,10 @@ def sample_move_project(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1469,7 +1518,7 @@ def delete_project( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Marks the project identified by the specified ``name`` (for example, ``projects/415104041262``) for deletion. @@ -1551,8 +1600,10 @@ def sample_delete_project(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1621,7 +1672,7 @@ def undelete_project( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Restores the project identified by the specified ``name`` (for example, ``projects/415104041262``). You can only use this @@ -1679,8 +1730,10 @@ def sample_undelete_project(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1749,7 +1802,7 @@ def get_iam_policy( resource: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Returns the IAM access control policy for the specified project, in the format ``projects/{ProjectIdOrNumber}`` e.g. @@ -1798,8 +1851,10 @@ def sample_get_iam_policy(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.policy_pb2.Policy: @@ -1886,7 +1941,7 @@ def set_iam_policy( resource: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Sets the IAM access control policy for the specified project, in the format ``projects/{ProjectIdOrNumber}`` e.g. projects/123. @@ -1979,8 +2034,10 @@ def sample_set_iam_policy(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.policy_pb2.Policy: @@ -2068,7 +2125,7 @@ def test_iam_permissions( permissions: Optional[MutableSequence[str]] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: r"""Returns permissions that a caller has on the specified project, in the format ``projects/{ProjectIdOrNumber}`` e.g. @@ -2126,8 +2183,10 @@ def sample_test_iam_permissions(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: @@ -2198,7 +2257,7 @@ def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -2209,8 +2268,10 @@ def get_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/pagers.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/pagers.py index fadb8e12e632..4bfbef1ce570 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/pagers.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -81,8 +81,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = projects.ListProjectsRequest(request) @@ -141,7 +143,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -155,8 +157,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = projects.ListProjectsRequest(request) @@ -219,7 +223,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -233,8 +237,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = projects.SearchProjectsRequest(request) @@ -293,7 +299,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -307,8 +313,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = projects.SearchProjectsRequest(request) diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/transports/grpc.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/transports/grpc.py index e467ddb9c888..7607da1cb262 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/transports/grpc.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -23,12 +26,90 @@ from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.resourcemanager_v3.types import projects from .base import DEFAULT_CLIENT_INFO, ProjectsTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class ProjectsGrpcTransport(ProjectsTransport): """gRPC backend transport for Projects. @@ -183,7 +264,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -247,7 +333,9 @@ def operations_client(self) -> operations_v1.OperationsClient: """ # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + self._operations_client = operations_v1.OperationsClient( + self._logged_channel + ) # Return the client from cache. return self._operations_client @@ -273,7 +361,7 @@ def get_project(self) -> Callable[[projects.GetProjectRequest], projects.Project # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_project" not in self._stubs: - self._stubs["get_project"] = self.grpc_channel.unary_unary( + self._stubs["get_project"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Projects/GetProject", request_serializer=projects.GetProjectRequest.serialize, response_deserializer=projects.Project.deserialize, @@ -305,7 +393,7 @@ def list_projects( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_projects" not in self._stubs: - self._stubs["list_projects"] = self.grpc_channel.unary_unary( + self._stubs["list_projects"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Projects/ListProjects", request_serializer=projects.ListProjectsRequest.serialize, response_deserializer=projects.ListProjectsResponse.deserialize, @@ -343,7 +431,7 @@ def search_projects( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "search_projects" not in self._stubs: - self._stubs["search_projects"] = self.grpc_channel.unary_unary( + self._stubs["search_projects"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Projects/SearchProjects", request_serializer=projects.SearchProjectsRequest.serialize, response_deserializer=projects.SearchProjectsResponse.deserialize, @@ -374,7 +462,7 @@ def create_project( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_project" not in self._stubs: - self._stubs["create_project"] = self.grpc_channel.unary_unary( + self._stubs["create_project"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Projects/CreateProject", request_serializer=projects.CreateProjectRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -406,7 +494,7 @@ def update_project( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_project" not in self._stubs: - self._stubs["update_project"] = self.grpc_channel.unary_unary( + self._stubs["update_project"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Projects/UpdateProject", request_serializer=projects.UpdateProjectRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -447,7 +535,7 @@ def move_project( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "move_project" not in self._stubs: - self._stubs["move_project"] = self.grpc_channel.unary_unary( + self._stubs["move_project"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Projects/MoveProject", request_serializer=projects.MoveProjectRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -507,7 +595,7 @@ def delete_project( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_project" not in self._stubs: - self._stubs["delete_project"] = self.grpc_channel.unary_unary( + self._stubs["delete_project"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Projects/DeleteProject", request_serializer=projects.DeleteProjectRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -540,7 +628,7 @@ def undelete_project( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "undelete_project" not in self._stubs: - self._stubs["undelete_project"] = self.grpc_channel.unary_unary( + self._stubs["undelete_project"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Projects/UndeleteProject", request_serializer=projects.UndeleteProjectRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -569,7 +657,7 @@ def get_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_iam_policy" not in self._stubs: - self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["get_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Projects/GetIamPolicy", request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -642,7 +730,7 @@ def set_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "set_iam_policy" not in self._stubs: - self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["set_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Projects/SetIamPolicy", request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -673,7 +761,7 @@ def test_iam_permissions( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "test_iam_permissions" not in self._stubs: - self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + self._stubs["test_iam_permissions"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Projects/TestIamPermissions", request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, @@ -681,7 +769,7 @@ def test_iam_permissions( return self._stubs["test_iam_permissions"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def get_operation( @@ -693,7 +781,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/transports/grpc_asyncio.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/transports/grpc_asyncio.py index db3bfa44e52c..190bbf2e465f 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/transports/grpc_asyncio.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -25,14 +28,93 @@ from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.resourcemanager_v3.types import projects from .base import DEFAULT_CLIENT_INFO, ProjectsTransport from .grpc import ProjectsGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class ProjectsGrpcAsyncIOTransport(ProjectsTransport): """gRPC AsyncIO backend transport for Projects. @@ -230,10 +312,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -256,7 +341,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel + self._logged_channel ) # Return the client from cache. @@ -285,7 +370,7 @@ def get_project( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_project" not in self._stubs: - self._stubs["get_project"] = self.grpc_channel.unary_unary( + self._stubs["get_project"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Projects/GetProject", request_serializer=projects.GetProjectRequest.serialize, response_deserializer=projects.Project.deserialize, @@ -319,7 +404,7 @@ def list_projects( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_projects" not in self._stubs: - self._stubs["list_projects"] = self.grpc_channel.unary_unary( + self._stubs["list_projects"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Projects/ListProjects", request_serializer=projects.ListProjectsRequest.serialize, response_deserializer=projects.ListProjectsResponse.deserialize, @@ -359,7 +444,7 @@ def search_projects( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "search_projects" not in self._stubs: - self._stubs["search_projects"] = self.grpc_channel.unary_unary( + self._stubs["search_projects"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Projects/SearchProjects", request_serializer=projects.SearchProjectsRequest.serialize, response_deserializer=projects.SearchProjectsResponse.deserialize, @@ -390,7 +475,7 @@ def create_project( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_project" not in self._stubs: - self._stubs["create_project"] = self.grpc_channel.unary_unary( + self._stubs["create_project"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Projects/CreateProject", request_serializer=projects.CreateProjectRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -422,7 +507,7 @@ def update_project( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_project" not in self._stubs: - self._stubs["update_project"] = self.grpc_channel.unary_unary( + self._stubs["update_project"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Projects/UpdateProject", request_serializer=projects.UpdateProjectRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -463,7 +548,7 @@ def move_project( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "move_project" not in self._stubs: - self._stubs["move_project"] = self.grpc_channel.unary_unary( + self._stubs["move_project"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Projects/MoveProject", request_serializer=projects.MoveProjectRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -523,7 +608,7 @@ def delete_project( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_project" not in self._stubs: - self._stubs["delete_project"] = self.grpc_channel.unary_unary( + self._stubs["delete_project"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Projects/DeleteProject", request_serializer=projects.DeleteProjectRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -558,7 +643,7 @@ def undelete_project( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "undelete_project" not in self._stubs: - self._stubs["undelete_project"] = self.grpc_channel.unary_unary( + self._stubs["undelete_project"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Projects/UndeleteProject", request_serializer=projects.UndeleteProjectRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -587,7 +672,7 @@ def get_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_iam_policy" not in self._stubs: - self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["get_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Projects/GetIamPolicy", request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -660,7 +745,7 @@ def set_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "set_iam_policy" not in self._stubs: - self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["set_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Projects/SetIamPolicy", request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -691,7 +776,7 @@ def test_iam_permissions( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "test_iam_permissions" not in self._stubs: - self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + self._stubs["test_iam_permissions"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.Projects/TestIamPermissions", request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, @@ -796,7 +881,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: @@ -812,7 +897,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/transports/rest.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/transports/rest.py index 25a24534849d..55312200c880 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/transports/rest.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/projects/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -40,6 +40,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -160,8 +168,8 @@ def post_update_project(self, response): def pre_create_project( self, request: projects.CreateProjectRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[projects.CreateProjectRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[projects.CreateProjectRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for create_project Override in a subclass to manipulate the request or metadata @@ -183,8 +191,8 @@ def post_create_project( def pre_delete_project( self, request: projects.DeleteProjectRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[projects.DeleteProjectRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[projects.DeleteProjectRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for delete_project Override in a subclass to manipulate the request or metadata @@ -206,8 +214,10 @@ def post_delete_project( def pre_get_iam_policy( self, request: iam_policy_pb2.GetIamPolicyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[iam_policy_pb2.GetIamPolicyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + iam_policy_pb2.GetIamPolicyRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_iam_policy Override in a subclass to manipulate the request or metadata @@ -225,8 +235,10 @@ def post_get_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: return response def pre_get_project( - self, request: projects.GetProjectRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[projects.GetProjectRequest, Sequence[Tuple[str, str]]]: + self, + request: projects.GetProjectRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[projects.GetProjectRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for get_project Override in a subclass to manipulate the request or metadata @@ -244,8 +256,10 @@ def post_get_project(self, response: projects.Project) -> projects.Project: return response def pre_list_projects( - self, request: projects.ListProjectsRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[projects.ListProjectsRequest, Sequence[Tuple[str, str]]]: + self, + request: projects.ListProjectsRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[projects.ListProjectsRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for list_projects Override in a subclass to manipulate the request or metadata @@ -265,8 +279,10 @@ def post_list_projects( return response def pre_move_project( - self, request: projects.MoveProjectRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[projects.MoveProjectRequest, Sequence[Tuple[str, str]]]: + self, + request: projects.MoveProjectRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[projects.MoveProjectRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for move_project Override in a subclass to manipulate the request or metadata @@ -288,8 +304,8 @@ def post_move_project( def pre_search_projects( self, request: projects.SearchProjectsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[projects.SearchProjectsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[projects.SearchProjectsRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for search_projects Override in a subclass to manipulate the request or metadata @@ -311,8 +327,10 @@ def post_search_projects( def pre_set_iam_policy( self, request: iam_policy_pb2.SetIamPolicyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[iam_policy_pb2.SetIamPolicyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + iam_policy_pb2.SetIamPolicyRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for set_iam_policy Override in a subclass to manipulate the request or metadata @@ -332,8 +350,11 @@ def post_set_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: def pre_test_iam_permissions( self, request: iam_policy_pb2.TestIamPermissionsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[iam_policy_pb2.TestIamPermissionsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + iam_policy_pb2.TestIamPermissionsRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for test_iam_permissions Override in a subclass to manipulate the request or metadata @@ -355,8 +376,10 @@ def post_test_iam_permissions( def pre_undelete_project( self, request: projects.UndeleteProjectRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[projects.UndeleteProjectRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + projects.UndeleteProjectRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for undelete_project Override in a subclass to manipulate the request or metadata @@ -378,8 +401,8 @@ def post_undelete_project( def pre_update_project( self, request: projects.UpdateProjectRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[projects.UpdateProjectRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[projects.UpdateProjectRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for update_project Override in a subclass to manipulate the request or metadata @@ -401,8 +424,10 @@ def post_update_project( def pre_get_operation( self, request: operations_pb2.GetOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.GetOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.GetOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_operation Override in a subclass to manipulate the request or metadata @@ -578,7 +603,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the create project method over HTTP. @@ -590,8 +615,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -604,6 +631,7 @@ def __call__( http_options = ( _BaseProjectsRestTransport._BaseCreateProject._get_http_options() ) + request, metadata = self._interceptor.pre_create_project(request, metadata) transcoded_request = ( _BaseProjectsRestTransport._BaseCreateProject._get_transcoded_request( @@ -622,6 +650,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.ProjectsClient.CreateProject", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "CreateProject", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ProjectsRestTransport._CreateProject._get_response( self._host, @@ -641,7 +696,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_project(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.ProjectsClient.create_project", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "CreateProject", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DeleteProject( @@ -678,7 +755,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the delete project method over HTTP. @@ -689,8 +766,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -703,6 +782,7 @@ def __call__( http_options = ( _BaseProjectsRestTransport._BaseDeleteProject._get_http_options() ) + request, metadata = self._interceptor.pre_delete_project(request, metadata) transcoded_request = ( _BaseProjectsRestTransport._BaseDeleteProject._get_transcoded_request( @@ -717,6 +797,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.ProjectsClient.DeleteProject", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "DeleteProject", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ProjectsRestTransport._DeleteProject._get_response( self._host, @@ -735,7 +842,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_delete_project(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.ProjectsClient.delete_project", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "DeleteProject", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetIamPolicy(_BaseProjectsRestTransport._BaseGetIamPolicy, ProjectsRestStub): @@ -771,7 +900,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Call the get iam policy method over HTTP. @@ -781,8 +910,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.policy_pb2.Policy: @@ -867,6 +998,7 @@ def __call__( http_options = ( _BaseProjectsRestTransport._BaseGetIamPolicy._get_http_options() ) + request, metadata = self._interceptor.pre_get_iam_policy(request, metadata) transcoded_request = ( _BaseProjectsRestTransport._BaseGetIamPolicy._get_transcoded_request( @@ -885,6 +1017,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.ProjectsClient.GetIamPolicy", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "GetIamPolicy", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ProjectsRestTransport._GetIamPolicy._get_response( self._host, @@ -906,7 +1065,29 @@ def __call__( pb_resp = resp json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_iam_policy(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.ProjectsClient.get_iam_policy", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "GetIamPolicy", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetProject(_BaseProjectsRestTransport._BaseGetProject, ProjectsRestStub): @@ -941,7 +1122,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> projects.Project: r"""Call the get project method over HTTP. @@ -953,8 +1134,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.projects.Project: @@ -968,6 +1151,7 @@ def __call__( http_options = ( _BaseProjectsRestTransport._BaseGetProject._get_http_options() ) + request, metadata = self._interceptor.pre_get_project(request, metadata) transcoded_request = ( _BaseProjectsRestTransport._BaseGetProject._get_transcoded_request( @@ -982,6 +1166,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.ProjectsClient.GetProject", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "GetProject", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ProjectsRestTransport._GetProject._get_response( self._host, @@ -1002,7 +1213,29 @@ def __call__( pb_resp = projects.Project.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_project(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = projects.Project.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.ProjectsClient.get_project", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "GetProject", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListProjects(_BaseProjectsRestTransport._BaseListProjects, ProjectsRestStub): @@ -1037,7 +1270,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> projects.ListProjectsResponse: r"""Call the list projects method over HTTP. @@ -1049,8 +1282,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.projects.ListProjectsResponse: @@ -1071,6 +1306,7 @@ def __call__( http_options = ( _BaseProjectsRestTransport._BaseListProjects._get_http_options() ) + request, metadata = self._interceptor.pre_list_projects(request, metadata) transcoded_request = ( _BaseProjectsRestTransport._BaseListProjects._get_transcoded_request( @@ -1085,6 +1321,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.ProjectsClient.ListProjects", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "ListProjects", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ProjectsRestTransport._ListProjects._get_response( self._host, @@ -1105,7 +1368,29 @@ def __call__( pb_resp = projects.ListProjectsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_projects(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = projects.ListProjectsResponse.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.ProjectsClient.list_projects", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "ListProjects", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _MoveProject(_BaseProjectsRestTransport._BaseMoveProject, ProjectsRestStub): @@ -1141,7 +1426,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the move project method over HTTP. @@ -1153,8 +1438,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1167,6 +1454,7 @@ def __call__( http_options = ( _BaseProjectsRestTransport._BaseMoveProject._get_http_options() ) + request, metadata = self._interceptor.pre_move_project(request, metadata) transcoded_request = ( _BaseProjectsRestTransport._BaseMoveProject._get_transcoded_request( @@ -1185,6 +1473,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.ProjectsClient.MoveProject", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "MoveProject", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ProjectsRestTransport._MoveProject._get_response( self._host, @@ -1204,7 +1519,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_move_project(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.ProjectsClient.move_project", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "MoveProject", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _SearchProjects( @@ -1241,7 +1578,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> projects.SearchProjectsResponse: r"""Call the search projects method over HTTP. @@ -1253,8 +1590,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.projects.SearchProjectsResponse: @@ -1271,6 +1610,7 @@ def __call__( http_options = ( _BaseProjectsRestTransport._BaseSearchProjects._get_http_options() ) + request, metadata = self._interceptor.pre_search_projects(request, metadata) transcoded_request = ( _BaseProjectsRestTransport._BaseSearchProjects._get_transcoded_request( @@ -1285,6 +1625,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.ProjectsClient.SearchProjects", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "SearchProjects", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ProjectsRestTransport._SearchProjects._get_response( self._host, @@ -1305,7 +1672,29 @@ def __call__( pb_resp = projects.SearchProjectsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_search_projects(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = projects.SearchProjectsResponse.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.ProjectsClient.search_projects", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "SearchProjects", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _SetIamPolicy(_BaseProjectsRestTransport._BaseSetIamPolicy, ProjectsRestStub): @@ -1341,7 +1730,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Call the set iam policy method over HTTP. @@ -1351,8 +1740,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.policy_pb2.Policy: @@ -1437,6 +1828,7 @@ def __call__( http_options = ( _BaseProjectsRestTransport._BaseSetIamPolicy._get_http_options() ) + request, metadata = self._interceptor.pre_set_iam_policy(request, metadata) transcoded_request = ( _BaseProjectsRestTransport._BaseSetIamPolicy._get_transcoded_request( @@ -1455,6 +1847,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.ProjectsClient.SetIamPolicy", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "SetIamPolicy", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ProjectsRestTransport._SetIamPolicy._get_response( self._host, @@ -1476,7 +1895,29 @@ def __call__( pb_resp = resp json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_set_iam_policy(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.ProjectsClient.set_iam_policy", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "SetIamPolicy", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _TestIamPermissions( @@ -1514,7 +1955,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: r"""Call the test iam permissions method over HTTP. @@ -1524,8 +1965,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.iam_policy_pb2.TestIamPermissionsResponse: @@ -1535,6 +1978,7 @@ def __call__( http_options = ( _BaseProjectsRestTransport._BaseTestIamPermissions._get_http_options() ) + request, metadata = self._interceptor.pre_test_iam_permissions( request, metadata ) @@ -1551,6 +1995,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.ProjectsClient.TestIamPermissions", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "TestIamPermissions", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ProjectsRestTransport._TestIamPermissions._get_response( self._host, @@ -1572,7 +2043,29 @@ def __call__( pb_resp = resp json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_test_iam_permissions(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.ProjectsClient.test_iam_permissions", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "TestIamPermissions", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UndeleteProject( @@ -1610,7 +2103,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the undelete project method over HTTP. @@ -1622,8 +2115,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1636,6 +2131,7 @@ def __call__( http_options = ( _BaseProjectsRestTransport._BaseUndeleteProject._get_http_options() ) + request, metadata = self._interceptor.pre_undelete_project( request, metadata ) @@ -1658,6 +2154,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.ProjectsClient.UndeleteProject", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "UndeleteProject", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ProjectsRestTransport._UndeleteProject._get_response( self._host, @@ -1677,7 +2200,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_undelete_project(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.ProjectsClient.undelete_project", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "UndeleteProject", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateProject( @@ -1715,7 +2260,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the update project method over HTTP. @@ -1732,8 +2277,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1746,6 +2293,7 @@ def __call__( http_options = ( _BaseProjectsRestTransport._BaseUpdateProject._get_http_options() ) + request, metadata = self._interceptor.pre_update_project(request, metadata) transcoded_request = ( _BaseProjectsRestTransport._BaseUpdateProject._get_transcoded_request( @@ -1764,6 +2312,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.ProjectsClient.UpdateProject", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "UpdateProject", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ProjectsRestTransport._UpdateProject._get_response( self._host, @@ -1783,7 +2358,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_project(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.ProjectsClient.update_project", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "UpdateProject", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property @@ -1911,7 +2508,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the get operation method over HTTP. @@ -1921,8 +2518,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: operations_pb2.Operation: Response from GetOperation method. @@ -1931,6 +2530,7 @@ def __call__( http_options = ( _BaseProjectsRestTransport._BaseGetOperation._get_http_options() ) + request, metadata = self._interceptor.pre_get_operation(request, metadata) transcoded_request = ( _BaseProjectsRestTransport._BaseGetOperation._get_transcoded_request( @@ -1945,6 +2545,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.ProjectsClient.GetOperation", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "GetOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ProjectsRestTransport._GetOperation._get_response( self._host, @@ -1964,6 +2591,27 @@ def __call__( resp = operations_pb2.Operation() resp = json_format.Parse(content, resp) resp = self._interceptor.post_get_operation(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.ProjectsAsyncClient.GetOperation", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.Projects", + "rpcName": "GetOperation", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/async_client.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/async_client.py index 129b38e5c2a4..e86e6d5dd972 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/async_client.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -54,6 +55,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, TagBindingsTransport from .transports.grpc_asyncio import TagBindingsGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class TagBindingsAsyncClient: """Allow users to create and manage TagBindings between @@ -262,6 +272,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.resourcemanager_v3.TagBindingsAsyncClient`.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagBindings", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.resourcemanager.v3.TagBindings", + "credentialsType": None, + }, + ) + async def list_tag_bindings( self, request: Optional[Union[tag_bindings.ListTagBindingsRequest, dict]] = None, @@ -269,7 +301,7 @@ async def list_tag_bindings( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListTagBindingsAsyncPager: r"""Lists the TagBindings for the given Google Cloud resource, as specified with ``parent``. @@ -321,8 +353,10 @@ async def sample_list_tag_bindings(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.services.tag_bindings.pagers.ListTagBindingsAsyncPager: @@ -391,7 +425,7 @@ async def create_tag_binding( tag_binding: Optional[tag_bindings.TagBinding] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Creates a TagBinding between a TagValue and a Google Cloud resource. @@ -439,8 +473,10 @@ async def sample_create_tag_binding(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -507,7 +543,7 @@ async def delete_tag_binding( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a TagBinding. @@ -556,8 +592,10 @@ async def sample_delete_tag_binding(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -636,7 +674,7 @@ async def list_effective_tags( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListEffectiveTagsAsyncPager: r"""Return a list of effective tags for the given Google Cloud resource, as specified in ``parent``. @@ -684,8 +722,10 @@ async def sample_list_effective_tags(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.services.tag_bindings.pagers.ListEffectiveTagsAsyncPager: @@ -753,7 +793,7 @@ async def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -764,8 +804,10 @@ async def get_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/client.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/client.py index c59d4dbd9939..72886ad92428 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/client.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -607,6 +617,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -669,6 +683,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.resourcemanager_v3.TagBindingsClient`.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagBindings", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.resourcemanager.v3.TagBindings", + "credentialsType": None, + }, + ) + def list_tag_bindings( self, request: Optional[Union[tag_bindings.ListTagBindingsRequest, dict]] = None, @@ -676,7 +713,7 @@ def list_tag_bindings( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListTagBindingsPager: r"""Lists the TagBindings for the given Google Cloud resource, as specified with ``parent``. @@ -728,8 +765,10 @@ def sample_list_tag_bindings(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.services.tag_bindings.pagers.ListTagBindingsPager: @@ -795,7 +834,7 @@ def create_tag_binding( tag_binding: Optional[tag_bindings.TagBinding] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Creates a TagBinding between a TagValue and a Google Cloud resource. @@ -843,8 +882,10 @@ def sample_create_tag_binding(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -908,7 +949,7 @@ def delete_tag_binding( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Deletes a TagBinding. @@ -957,8 +998,10 @@ def sample_delete_tag_binding(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1034,7 +1077,7 @@ def list_effective_tags( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListEffectiveTagsPager: r"""Return a list of effective tags for the given Google Cloud resource, as specified in ``parent``. @@ -1082,8 +1125,10 @@ def sample_list_effective_tags(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.services.tag_bindings.pagers.ListEffectiveTagsPager: @@ -1161,7 +1206,7 @@ def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -1172,8 +1217,10 @@ def get_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/pagers.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/pagers.py index e2e3cb451a8f..8334736ae46f 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/pagers.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -81,8 +81,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = tag_bindings.ListTagBindingsRequest(request) @@ -141,7 +143,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -155,8 +157,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = tag_bindings.ListTagBindingsRequest(request) @@ -219,7 +223,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -233,8 +237,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = tag_bindings.ListEffectiveTagsRequest(request) @@ -293,7 +299,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -307,8 +313,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = tag_bindings.ListEffectiveTagsRequest(request) diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/transports/grpc.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/transports/grpc.py index e1f716ab3cb7..ed8c5ced0413 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/transports/grpc.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -21,12 +24,90 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.resourcemanager_v3.types import tag_bindings from .base import DEFAULT_CLIENT_INFO, TagBindingsTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagBindings", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagBindings", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class TagBindingsGrpcTransport(TagBindingsTransport): """gRPC backend transport for TagBindings. @@ -183,7 +264,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -247,7 +333,9 @@ def operations_client(self) -> operations_v1.OperationsClient: """ # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + self._operations_client = operations_v1.OperationsClient( + self._logged_channel + ) # Return the client from cache. return self._operations_client @@ -278,7 +366,7 @@ def list_tag_bindings( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_tag_bindings" not in self._stubs: - self._stubs["list_tag_bindings"] = self.grpc_channel.unary_unary( + self._stubs["list_tag_bindings"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagBindings/ListTagBindings", request_serializer=tag_bindings.ListTagBindingsRequest.serialize, response_deserializer=tag_bindings.ListTagBindingsResponse.deserialize, @@ -305,7 +393,7 @@ def create_tag_binding( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_tag_binding" not in self._stubs: - self._stubs["create_tag_binding"] = self.grpc_channel.unary_unary( + self._stubs["create_tag_binding"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagBindings/CreateTagBinding", request_serializer=tag_bindings.CreateTagBindingRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -331,7 +419,7 @@ def delete_tag_binding( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_tag_binding" not in self._stubs: - self._stubs["delete_tag_binding"] = self.grpc_channel.unary_unary( + self._stubs["delete_tag_binding"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagBindings/DeleteTagBinding", request_serializer=tag_bindings.DeleteTagBindingRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -360,7 +448,7 @@ def list_effective_tags( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_effective_tags" not in self._stubs: - self._stubs["list_effective_tags"] = self.grpc_channel.unary_unary( + self._stubs["list_effective_tags"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagBindings/ListEffectiveTags", request_serializer=tag_bindings.ListEffectiveTagsRequest.serialize, response_deserializer=tag_bindings.ListEffectiveTagsResponse.deserialize, @@ -368,7 +456,7 @@ def list_effective_tags( return self._stubs["list_effective_tags"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def get_operation( @@ -380,7 +468,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/transports/grpc_asyncio.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/transports/grpc_asyncio.py index 1736e074e55c..7d1ac6aa0c0d 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/transports/grpc_asyncio.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -23,14 +26,93 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.resourcemanager_v3.types import tag_bindings from .base import DEFAULT_CLIENT_INFO, TagBindingsTransport from .grpc import TagBindingsGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagBindings", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagBindings", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class TagBindingsGrpcAsyncIOTransport(TagBindingsTransport): """gRPC AsyncIO backend transport for TagBindings. @@ -230,10 +312,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -256,7 +341,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel + self._logged_channel ) # Return the client from cache. @@ -289,7 +374,7 @@ def list_tag_bindings( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_tag_bindings" not in self._stubs: - self._stubs["list_tag_bindings"] = self.grpc_channel.unary_unary( + self._stubs["list_tag_bindings"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagBindings/ListTagBindings", request_serializer=tag_bindings.ListTagBindingsRequest.serialize, response_deserializer=tag_bindings.ListTagBindingsResponse.deserialize, @@ -318,7 +403,7 @@ def create_tag_binding( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_tag_binding" not in self._stubs: - self._stubs["create_tag_binding"] = self.grpc_channel.unary_unary( + self._stubs["create_tag_binding"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagBindings/CreateTagBinding", request_serializer=tag_bindings.CreateTagBindingRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -346,7 +431,7 @@ def delete_tag_binding( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_tag_binding" not in self._stubs: - self._stubs["delete_tag_binding"] = self.grpc_channel.unary_unary( + self._stubs["delete_tag_binding"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagBindings/DeleteTagBinding", request_serializer=tag_bindings.DeleteTagBindingRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -376,7 +461,7 @@ def list_effective_tags( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_effective_tags" not in self._stubs: - self._stubs["list_effective_tags"] = self.grpc_channel.unary_unary( + self._stubs["list_effective_tags"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagBindings/ListEffectiveTags", request_serializer=tag_bindings.ListEffectiveTagsRequest.serialize, response_deserializer=tag_bindings.ListEffectiveTagsResponse.deserialize, @@ -428,7 +513,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: @@ -444,7 +529,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/transports/rest.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/transports/rest.py index 67d83171cc9f..da6ad505f359 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/transports/rest.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_bindings/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -38,6 +38,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -102,8 +110,10 @@ def post_list_tag_bindings(self, response): def pre_create_tag_binding( self, request: tag_bindings.CreateTagBindingRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[tag_bindings.CreateTagBindingRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + tag_bindings.CreateTagBindingRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for create_tag_binding Override in a subclass to manipulate the request or metadata @@ -125,8 +135,10 @@ def post_create_tag_binding( def pre_delete_tag_binding( self, request: tag_bindings.DeleteTagBindingRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[tag_bindings.DeleteTagBindingRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + tag_bindings.DeleteTagBindingRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for delete_tag_binding Override in a subclass to manipulate the request or metadata @@ -148,8 +160,10 @@ def post_delete_tag_binding( def pre_list_effective_tags( self, request: tag_bindings.ListEffectiveTagsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[tag_bindings.ListEffectiveTagsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + tag_bindings.ListEffectiveTagsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_effective_tags Override in a subclass to manipulate the request or metadata @@ -171,8 +185,10 @@ def post_list_effective_tags( def pre_list_tag_bindings( self, request: tag_bindings.ListTagBindingsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[tag_bindings.ListTagBindingsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + tag_bindings.ListTagBindingsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_tag_bindings Override in a subclass to manipulate the request or metadata @@ -194,8 +210,10 @@ def post_list_tag_bindings( def pre_get_operation( self, request: operations_pb2.GetOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.GetOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.GetOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_operation Override in a subclass to manipulate the request or metadata @@ -373,7 +391,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the create tag binding method over HTTP. @@ -384,8 +402,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -398,6 +418,7 @@ def __call__( http_options = ( _BaseTagBindingsRestTransport._BaseCreateTagBinding._get_http_options() ) + request, metadata = self._interceptor.pre_create_tag_binding( request, metadata ) @@ -414,6 +435,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagBindingsClient.CreateTagBinding", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagBindings", + "rpcName": "CreateTagBinding", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagBindingsRestTransport._CreateTagBinding._get_response( self._host, @@ -433,7 +481,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_tag_binding(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagBindingsClient.create_tag_binding", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagBindings", + "rpcName": "CreateTagBinding", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DeleteTagBinding( @@ -470,7 +540,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the delete tag binding method over HTTP. @@ -481,8 +551,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -495,6 +567,7 @@ def __call__( http_options = ( _BaseTagBindingsRestTransport._BaseDeleteTagBinding._get_http_options() ) + request, metadata = self._interceptor.pre_delete_tag_binding( request, metadata ) @@ -507,6 +580,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagBindingsClient.DeleteTagBinding", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagBindings", + "rpcName": "DeleteTagBinding", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagBindingsRestTransport._DeleteTagBinding._get_response( self._host, @@ -525,7 +625,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_delete_tag_binding(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagBindingsClient.delete_tag_binding", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagBindings", + "rpcName": "DeleteTagBinding", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListEffectiveTags( @@ -562,7 +684,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> tag_bindings.ListEffectiveTagsResponse: r"""Call the list effective tags method over HTTP. @@ -573,8 +695,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.tag_bindings.ListEffectiveTagsResponse: @@ -584,6 +708,7 @@ def __call__( http_options = ( _BaseTagBindingsRestTransport._BaseListEffectiveTags._get_http_options() ) + request, metadata = self._interceptor.pre_list_effective_tags( request, metadata ) @@ -596,6 +721,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagBindingsClient.ListEffectiveTags", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagBindings", + "rpcName": "ListEffectiveTags", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagBindingsRestTransport._ListEffectiveTags._get_response( self._host, @@ -616,7 +768,31 @@ def __call__( pb_resp = tag_bindings.ListEffectiveTagsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_effective_tags(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = tag_bindings.ListEffectiveTagsResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagBindingsClient.list_effective_tags", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagBindings", + "rpcName": "ListEffectiveTags", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListTagBindings( @@ -653,7 +829,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> tag_bindings.ListTagBindingsResponse: r"""Call the list tag bindings method over HTTP. @@ -664,8 +840,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.tag_bindings.ListTagBindingsResponse: @@ -675,6 +853,7 @@ def __call__( http_options = ( _BaseTagBindingsRestTransport._BaseListTagBindings._get_http_options() ) + request, metadata = self._interceptor.pre_list_tag_bindings( request, metadata ) @@ -687,6 +866,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagBindingsClient.ListTagBindings", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagBindings", + "rpcName": "ListTagBindings", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagBindingsRestTransport._ListTagBindings._get_response( self._host, @@ -707,7 +913,31 @@ def __call__( pb_resp = tag_bindings.ListTagBindingsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_tag_bindings(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = tag_bindings.ListTagBindingsResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagBindingsClient.list_tag_bindings", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagBindings", + "rpcName": "ListTagBindings", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property @@ -784,7 +1014,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the get operation method over HTTP. @@ -794,8 +1024,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: operations_pb2.Operation: Response from GetOperation method. @@ -804,6 +1036,7 @@ def __call__( http_options = ( _BaseTagBindingsRestTransport._BaseGetOperation._get_http_options() ) + request, metadata = self._interceptor.pre_get_operation(request, metadata) transcoded_request = ( _BaseTagBindingsRestTransport._BaseGetOperation._get_transcoded_request( @@ -818,6 +1051,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagBindingsClient.GetOperation", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagBindings", + "rpcName": "GetOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagBindingsRestTransport._GetOperation._get_response( self._host, @@ -837,6 +1097,27 @@ def __call__( resp = operations_pb2.Operation() resp = json_format.Parse(content, resp) resp = self._interceptor.post_get_operation(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagBindingsAsyncClient.GetOperation", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagBindings", + "rpcName": "GetOperation", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/async_client.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/async_client.py index ddb2a1c02940..374370569ffa 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/async_client.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -54,6 +55,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, TagHoldsTransport from .transports.grpc_asyncio import TagHoldsGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class TagHoldsAsyncClient: """Allow users to create and manage TagHolds for TagValues. @@ -257,6 +267,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.resourcemanager_v3.TagHoldsAsyncClient`.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagHolds", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.resourcemanager.v3.TagHolds", + "credentialsType": None, + }, + ) + async def create_tag_hold( self, request: Optional[Union[tag_holds.CreateTagHoldRequest, dict]] = None, @@ -265,7 +297,7 @@ async def create_tag_hold( tag_hold: Optional[tag_holds.TagHold] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Creates a TagHold. Returns ALREADY_EXISTS if a TagHold with the same resource and origin exists under the same TagValue. @@ -324,8 +356,10 @@ async def sample_create_tag_hold(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -400,7 +434,7 @@ async def delete_tag_hold( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a TagHold. @@ -449,8 +483,10 @@ async def sample_delete_tag_hold(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -529,7 +565,7 @@ async def list_tag_holds( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListTagHoldsAsyncPager: r"""Lists TagHolds under a TagValue. @@ -574,8 +610,10 @@ async def sample_list_tag_holds(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.services.tag_holds.pagers.ListTagHoldsAsyncPager: @@ -649,7 +687,7 @@ async def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -660,8 +698,10 @@ async def get_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/client.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/client.py index 6b52e231be0f..1b12b6948881 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/client.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -582,6 +592,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -644,6 +658,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.resourcemanager_v3.TagHoldsClient`.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagHolds", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.resourcemanager.v3.TagHolds", + "credentialsType": None, + }, + ) + def create_tag_hold( self, request: Optional[Union[tag_holds.CreateTagHoldRequest, dict]] = None, @@ -652,7 +689,7 @@ def create_tag_hold( tag_hold: Optional[tag_holds.TagHold] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Creates a TagHold. Returns ALREADY_EXISTS if a TagHold with the same resource and origin exists under the same TagValue. @@ -711,8 +748,10 @@ def sample_create_tag_hold(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -784,7 +823,7 @@ def delete_tag_hold( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Deletes a TagHold. @@ -833,8 +872,10 @@ def sample_delete_tag_hold(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -910,7 +951,7 @@ def list_tag_holds( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListTagHoldsPager: r"""Lists TagHolds under a TagValue. @@ -955,8 +996,10 @@ def sample_list_tag_holds(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.services.tag_holds.pagers.ListTagHoldsPager: @@ -1040,7 +1083,7 @@ def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -1051,8 +1094,10 @@ def get_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/pagers.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/pagers.py index 69eaf61b1e05..3a4cbb01bb15 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/pagers.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -81,8 +81,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = tag_holds.ListTagHoldsRequest(request) @@ -141,7 +143,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -155,8 +157,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = tag_holds.ListTagHoldsRequest(request) diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/transports/grpc.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/transports/grpc.py index 74eabf02c23b..d039d464e746 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/transports/grpc.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -21,12 +24,90 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.resourcemanager_v3.types import tag_holds from .base import DEFAULT_CLIENT_INFO, TagHoldsTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagHolds", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagHolds", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class TagHoldsGrpcTransport(TagHoldsTransport): """gRPC backend transport for TagHolds. @@ -186,7 +267,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -250,7 +336,9 @@ def operations_client(self) -> operations_v1.OperationsClient: """ # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + self._operations_client = operations_v1.OperationsClient( + self._logged_channel + ) # Return the client from cache. return self._operations_client @@ -275,7 +363,7 @@ def create_tag_hold( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_tag_hold" not in self._stubs: - self._stubs["create_tag_hold"] = self.grpc_channel.unary_unary( + self._stubs["create_tag_hold"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagHolds/CreateTagHold", request_serializer=tag_holds.CreateTagHoldRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -301,7 +389,7 @@ def delete_tag_hold( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_tag_hold" not in self._stubs: - self._stubs["delete_tag_hold"] = self.grpc_channel.unary_unary( + self._stubs["delete_tag_hold"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagHolds/DeleteTagHold", request_serializer=tag_holds.DeleteTagHoldRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -327,7 +415,7 @@ def list_tag_holds( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_tag_holds" not in self._stubs: - self._stubs["list_tag_holds"] = self.grpc_channel.unary_unary( + self._stubs["list_tag_holds"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagHolds/ListTagHolds", request_serializer=tag_holds.ListTagHoldsRequest.serialize, response_deserializer=tag_holds.ListTagHoldsResponse.deserialize, @@ -335,7 +423,7 @@ def list_tag_holds( return self._stubs["list_tag_holds"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def get_operation( @@ -347,7 +435,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/transports/grpc_asyncio.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/transports/grpc_asyncio.py index 2e441f976475..fbe4072486ac 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/transports/grpc_asyncio.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -23,14 +26,93 @@ from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.resourcemanager_v3.types import tag_holds from .base import DEFAULT_CLIENT_INFO, TagHoldsTransport from .grpc import TagHoldsGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagHolds", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagHolds", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class TagHoldsGrpcAsyncIOTransport(TagHoldsTransport): """gRPC AsyncIO backend transport for TagHolds. @@ -233,10 +315,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -259,7 +344,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel + self._logged_channel ) # Return the client from cache. @@ -287,7 +372,7 @@ def create_tag_hold( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_tag_hold" not in self._stubs: - self._stubs["create_tag_hold"] = self.grpc_channel.unary_unary( + self._stubs["create_tag_hold"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagHolds/CreateTagHold", request_serializer=tag_holds.CreateTagHoldRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -315,7 +400,7 @@ def delete_tag_hold( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_tag_hold" not in self._stubs: - self._stubs["delete_tag_hold"] = self.grpc_channel.unary_unary( + self._stubs["delete_tag_hold"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagHolds/DeleteTagHold", request_serializer=tag_holds.DeleteTagHoldRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -343,7 +428,7 @@ def list_tag_holds( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_tag_holds" not in self._stubs: - self._stubs["list_tag_holds"] = self.grpc_channel.unary_unary( + self._stubs["list_tag_holds"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagHolds/ListTagHolds", request_serializer=tag_holds.ListTagHoldsRequest.serialize, response_deserializer=tag_holds.ListTagHoldsResponse.deserialize, @@ -381,7 +466,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: @@ -397,7 +482,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/transports/rest.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/transports/rest.py index dd468ff985f1..483d926d7b84 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/transports/rest.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_holds/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -38,6 +38,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -94,8 +102,8 @@ def post_list_tag_holds(self, response): def pre_create_tag_hold( self, request: tag_holds.CreateTagHoldRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[tag_holds.CreateTagHoldRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[tag_holds.CreateTagHoldRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for create_tag_hold Override in a subclass to manipulate the request or metadata @@ -117,8 +125,8 @@ def post_create_tag_hold( def pre_delete_tag_hold( self, request: tag_holds.DeleteTagHoldRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[tag_holds.DeleteTagHoldRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[tag_holds.DeleteTagHoldRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for delete_tag_hold Override in a subclass to manipulate the request or metadata @@ -140,8 +148,8 @@ def post_delete_tag_hold( def pre_list_tag_holds( self, request: tag_holds.ListTagHoldsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[tag_holds.ListTagHoldsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[tag_holds.ListTagHoldsRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for list_tag_holds Override in a subclass to manipulate the request or metadata @@ -163,8 +171,10 @@ def post_list_tag_holds( def pre_get_operation( self, request: operations_pb2.GetOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.GetOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.GetOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_operation Override in a subclass to manipulate the request or metadata @@ -345,7 +355,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the create tag hold method over HTTP. @@ -356,8 +366,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -370,6 +382,7 @@ def __call__( http_options = ( _BaseTagHoldsRestTransport._BaseCreateTagHold._get_http_options() ) + request, metadata = self._interceptor.pre_create_tag_hold(request, metadata) transcoded_request = ( _BaseTagHoldsRestTransport._BaseCreateTagHold._get_transcoded_request( @@ -388,6 +401,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagHoldsClient.CreateTagHold", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagHolds", + "rpcName": "CreateTagHold", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagHoldsRestTransport._CreateTagHold._get_response( self._host, @@ -407,7 +447,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_tag_hold(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagHoldsClient.create_tag_hold", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagHolds", + "rpcName": "CreateTagHold", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DeleteTagHold( @@ -444,7 +506,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the delete tag hold method over HTTP. @@ -455,8 +517,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -469,6 +533,7 @@ def __call__( http_options = ( _BaseTagHoldsRestTransport._BaseDeleteTagHold._get_http_options() ) + request, metadata = self._interceptor.pre_delete_tag_hold(request, metadata) transcoded_request = ( _BaseTagHoldsRestTransport._BaseDeleteTagHold._get_transcoded_request( @@ -483,6 +548,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagHoldsClient.DeleteTagHold", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagHolds", + "rpcName": "DeleteTagHold", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagHoldsRestTransport._DeleteTagHold._get_response( self._host, @@ -501,7 +593,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_delete_tag_hold(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagHoldsClient.delete_tag_hold", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagHolds", + "rpcName": "DeleteTagHold", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListTagHolds(_BaseTagHoldsRestTransport._BaseListTagHolds, TagHoldsRestStub): @@ -536,7 +650,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> tag_holds.ListTagHoldsResponse: r"""Call the list tag holds method over HTTP. @@ -547,8 +661,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.tag_holds.ListTagHoldsResponse: @@ -558,6 +674,7 @@ def __call__( http_options = ( _BaseTagHoldsRestTransport._BaseListTagHolds._get_http_options() ) + request, metadata = self._interceptor.pre_list_tag_holds(request, metadata) transcoded_request = ( _BaseTagHoldsRestTransport._BaseListTagHolds._get_transcoded_request( @@ -572,6 +689,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagHoldsClient.ListTagHolds", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagHolds", + "rpcName": "ListTagHolds", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagHoldsRestTransport._ListTagHolds._get_response( self._host, @@ -592,7 +736,29 @@ def __call__( pb_resp = tag_holds.ListTagHoldsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_tag_holds(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = tag_holds.ListTagHoldsResponse.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagHoldsClient.list_tag_holds", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagHolds", + "rpcName": "ListTagHolds", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property @@ -655,7 +821,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the get operation method over HTTP. @@ -665,8 +831,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: operations_pb2.Operation: Response from GetOperation method. @@ -675,6 +843,7 @@ def __call__( http_options = ( _BaseTagHoldsRestTransport._BaseGetOperation._get_http_options() ) + request, metadata = self._interceptor.pre_get_operation(request, metadata) transcoded_request = ( _BaseTagHoldsRestTransport._BaseGetOperation._get_transcoded_request( @@ -689,6 +858,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagHoldsClient.GetOperation", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagHolds", + "rpcName": "GetOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagHoldsRestTransport._GetOperation._get_response( self._host, @@ -708,6 +904,27 @@ def __call__( resp = operations_pb2.Operation() resp = json_format.Parse(content, resp) resp = self._interceptor.post_get_operation(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagHoldsAsyncClient.GetOperation", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagHolds", + "rpcName": "GetOperation", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/async_client.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/async_client.py index 1da8f0c88af8..1a675d69572f 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/async_client.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -57,6 +58,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, TagKeysTransport from .transports.grpc_asyncio import TagKeysGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class TagKeysAsyncClient: """Allow users to create and manage tag keys.""" @@ -254,6 +264,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.resourcemanager_v3.TagKeysAsyncClient`.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "credentialsType": None, + }, + ) + async def list_tag_keys( self, request: Optional[Union[tag_keys.ListTagKeysRequest, dict]] = None, @@ -261,7 +293,7 @@ async def list_tag_keys( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListTagKeysAsyncPager: r"""Lists all TagKeys for a parent resource. @@ -308,8 +340,10 @@ async def sample_list_tag_keys(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.services.tag_keys.pagers.ListTagKeysAsyncPager: @@ -378,7 +412,7 @@ async def get_tag_key( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> tag_keys.TagKey: r"""Retrieves a TagKey. This method will return ``PERMISSION_DENIED`` if the key does not exist or the user does @@ -424,8 +458,10 @@ async def sample_get_tag_key(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.types.TagKey: @@ -486,7 +522,7 @@ async def get_namespaced_tag_key( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> tag_keys.TagKey: r"""Retrieves a TagKey by its namespaced name. This method will return ``PERMISSION_DENIED`` if the key does not exist or the @@ -535,8 +571,10 @@ async def sample_get_namespaced_tag_key(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.types.TagKey: @@ -591,7 +629,7 @@ async def create_tag_key( tag_key: Optional[tag_keys.TagKey] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Creates a new TagKey. If another request with the same parameters is sent while the original request is in @@ -647,8 +685,10 @@ async def sample_create_tag_key(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -715,7 +755,7 @@ async def update_tag_key( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Updates the attributes of the TagKey resource. @@ -778,8 +818,10 @@ async def sample_update_tag_key(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -855,7 +897,7 @@ async def delete_tag_key( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a TagKey. The TagKey cannot be deleted if it has any child TagValues. @@ -906,8 +948,10 @@ async def sample_delete_tag_key(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -979,7 +1023,7 @@ async def get_iam_policy( resource: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Gets the access control policy for a TagKey. The returned policy may be empty if no such policy or resource exists. The @@ -1030,8 +1074,10 @@ async def sample_get_iam_policy(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.policy_pb2.Policy: @@ -1117,7 +1163,7 @@ async def set_iam_policy( resource: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Sets the access control policy on a TagKey, replacing any existing policy. The ``resource`` field should be the TagKey's @@ -1167,8 +1213,10 @@ async def sample_set_iam_policy(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.policy_pb2.Policy: @@ -1255,7 +1303,7 @@ async def test_iam_permissions( permissions: Optional[MutableSequence[str]] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: r"""Returns permissions that a caller has on the specified TagKey. The ``resource`` field should be the TagKey's resource name. For @@ -1315,8 +1363,10 @@ async def sample_test_iam_permissions(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: @@ -1373,7 +1423,7 @@ async def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -1384,8 +1434,10 @@ async def get_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/client.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/client.py index 5db9b3313e51..0a5bcb8828d7 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/client.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.iam.v1 import iam_policy_pb2 # type: ignore @@ -577,6 +587,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -639,6 +653,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.resourcemanager_v3.TagKeysClient`.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "credentialsType": None, + }, + ) + def list_tag_keys( self, request: Optional[Union[tag_keys.ListTagKeysRequest, dict]] = None, @@ -646,7 +683,7 @@ def list_tag_keys( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListTagKeysPager: r"""Lists all TagKeys for a parent resource. @@ -693,8 +730,10 @@ def sample_list_tag_keys(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.services.tag_keys.pagers.ListTagKeysPager: @@ -760,7 +799,7 @@ def get_tag_key( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> tag_keys.TagKey: r"""Retrieves a TagKey. This method will return ``PERMISSION_DENIED`` if the key does not exist or the user does @@ -806,8 +845,10 @@ def sample_get_tag_key(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.types.TagKey: @@ -865,7 +906,7 @@ def get_namespaced_tag_key( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> tag_keys.TagKey: r"""Retrieves a TagKey by its namespaced name. This method will return ``PERMISSION_DENIED`` if the key does not exist or the @@ -914,8 +955,10 @@ def sample_get_namespaced_tag_key(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.types.TagKey: @@ -967,7 +1010,7 @@ def create_tag_key( tag_key: Optional[tag_keys.TagKey] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Creates a new TagKey. If another request with the same parameters is sent while the original request is in @@ -1023,8 +1066,10 @@ def sample_create_tag_key(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1088,7 +1133,7 @@ def update_tag_key( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Updates the attributes of the TagKey resource. @@ -1151,8 +1196,10 @@ def sample_update_tag_key(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1225,7 +1272,7 @@ def delete_tag_key( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Deletes a TagKey. The TagKey cannot be deleted if it has any child TagValues. @@ -1276,8 +1323,10 @@ def sample_delete_tag_key(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1346,7 +1395,7 @@ def get_iam_policy( resource: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Gets the access control policy for a TagKey. The returned policy may be empty if no such policy or resource exists. The @@ -1397,8 +1446,10 @@ def sample_get_iam_policy(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.policy_pb2.Policy: @@ -1485,7 +1536,7 @@ def set_iam_policy( resource: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Sets the access control policy on a TagKey, replacing any existing policy. The ``resource`` field should be the TagKey's @@ -1535,8 +1586,10 @@ def sample_set_iam_policy(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.policy_pb2.Policy: @@ -1624,7 +1677,7 @@ def test_iam_permissions( permissions: Optional[MutableSequence[str]] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: r"""Returns permissions that a caller has on the specified TagKey. The ``resource`` field should be the TagKey's resource name. For @@ -1684,8 +1737,10 @@ def sample_test_iam_permissions(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: @@ -1756,7 +1811,7 @@ def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -1767,8 +1822,10 @@ def get_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/pagers.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/pagers.py index 15bf354cca28..326ac1dd650c 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/pagers.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -81,8 +81,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = tag_keys.ListTagKeysRequest(request) @@ -141,7 +143,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -155,8 +157,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = tag_keys.ListTagKeysRequest(request) diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/transports/grpc.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/transports/grpc.py index be4a3b5b99b9..a37a98f0f888 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/transports/grpc.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -23,12 +26,90 @@ from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.resourcemanager_v3.types import tag_keys from .base import DEFAULT_CLIENT_INFO, TagKeysTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class TagKeysGrpcTransport(TagKeysTransport): """gRPC backend transport for TagKeys. @@ -183,7 +264,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -247,7 +333,9 @@ def operations_client(self) -> operations_v1.OperationsClient: """ # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + self._operations_client = operations_v1.OperationsClient( + self._logged_channel + ) # Return the client from cache. return self._operations_client @@ -271,7 +359,7 @@ def list_tag_keys( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_tag_keys" not in self._stubs: - self._stubs["list_tag_keys"] = self.grpc_channel.unary_unary( + self._stubs["list_tag_keys"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagKeys/ListTagKeys", request_serializer=tag_keys.ListTagKeysRequest.serialize, response_deserializer=tag_keys.ListTagKeysResponse.deserialize, @@ -297,7 +385,7 @@ def get_tag_key(self) -> Callable[[tag_keys.GetTagKeyRequest], tag_keys.TagKey]: # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_tag_key" not in self._stubs: - self._stubs["get_tag_key"] = self.grpc_channel.unary_unary( + self._stubs["get_tag_key"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagKeys/GetTagKey", request_serializer=tag_keys.GetTagKeyRequest.serialize, response_deserializer=tag_keys.TagKey.deserialize, @@ -325,7 +413,7 @@ def get_namespaced_tag_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_namespaced_tag_key" not in self._stubs: - self._stubs["get_namespaced_tag_key"] = self.grpc_channel.unary_unary( + self._stubs["get_namespaced_tag_key"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagKeys/GetNamespacedTagKey", request_serializer=tag_keys.GetNamespacedTagKeyRequest.serialize, response_deserializer=tag_keys.TagKey.deserialize, @@ -355,7 +443,7 @@ def create_tag_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_tag_key" not in self._stubs: - self._stubs["create_tag_key"] = self.grpc_channel.unary_unary( + self._stubs["create_tag_key"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagKeys/CreateTagKey", request_serializer=tag_keys.CreateTagKeyRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -381,7 +469,7 @@ def update_tag_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_tag_key" not in self._stubs: - self._stubs["update_tag_key"] = self.grpc_channel.unary_unary( + self._stubs["update_tag_key"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagKeys/UpdateTagKey", request_serializer=tag_keys.UpdateTagKeyRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -408,7 +496,7 @@ def delete_tag_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_tag_key" not in self._stubs: - self._stubs["delete_tag_key"] = self.grpc_channel.unary_unary( + self._stubs["delete_tag_key"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagKeys/DeleteTagKey", request_serializer=tag_keys.DeleteTagKeyRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -439,7 +527,7 @@ def get_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_iam_policy" not in self._stubs: - self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["get_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagKeys/GetIamPolicy", request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -469,7 +557,7 @@ def set_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "set_iam_policy" not in self._stubs: - self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["set_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagKeys/SetIamPolicy", request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -502,7 +590,7 @@ def test_iam_permissions( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "test_iam_permissions" not in self._stubs: - self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + self._stubs["test_iam_permissions"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagKeys/TestIamPermissions", request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, @@ -510,7 +598,7 @@ def test_iam_permissions( return self._stubs["test_iam_permissions"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def get_operation( @@ -522,7 +610,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/transports/grpc_asyncio.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/transports/grpc_asyncio.py index 86b19103dbb0..bd4e001c3f74 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/transports/grpc_asyncio.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -25,14 +28,93 @@ from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.resourcemanager_v3.types import tag_keys from .base import DEFAULT_CLIENT_INFO, TagKeysTransport from .grpc import TagKeysGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class TagKeysGrpcAsyncIOTransport(TagKeysTransport): """gRPC AsyncIO backend transport for TagKeys. @@ -230,10 +312,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -256,7 +341,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel + self._logged_channel ) # Return the client from cache. @@ -283,7 +368,7 @@ def list_tag_keys( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_tag_keys" not in self._stubs: - self._stubs["list_tag_keys"] = self.grpc_channel.unary_unary( + self._stubs["list_tag_keys"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagKeys/ListTagKeys", request_serializer=tag_keys.ListTagKeysRequest.serialize, response_deserializer=tag_keys.ListTagKeysResponse.deserialize, @@ -311,7 +396,7 @@ def get_tag_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_tag_key" not in self._stubs: - self._stubs["get_tag_key"] = self.grpc_channel.unary_unary( + self._stubs["get_tag_key"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagKeys/GetTagKey", request_serializer=tag_keys.GetTagKeyRequest.serialize, response_deserializer=tag_keys.TagKey.deserialize, @@ -339,7 +424,7 @@ def get_namespaced_tag_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_namespaced_tag_key" not in self._stubs: - self._stubs["get_namespaced_tag_key"] = self.grpc_channel.unary_unary( + self._stubs["get_namespaced_tag_key"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagKeys/GetNamespacedTagKey", request_serializer=tag_keys.GetNamespacedTagKeyRequest.serialize, response_deserializer=tag_keys.TagKey.deserialize, @@ -369,7 +454,7 @@ def create_tag_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_tag_key" not in self._stubs: - self._stubs["create_tag_key"] = self.grpc_channel.unary_unary( + self._stubs["create_tag_key"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagKeys/CreateTagKey", request_serializer=tag_keys.CreateTagKeyRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -395,7 +480,7 @@ def update_tag_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_tag_key" not in self._stubs: - self._stubs["update_tag_key"] = self.grpc_channel.unary_unary( + self._stubs["update_tag_key"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagKeys/UpdateTagKey", request_serializer=tag_keys.UpdateTagKeyRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -422,7 +507,7 @@ def delete_tag_key( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_tag_key" not in self._stubs: - self._stubs["delete_tag_key"] = self.grpc_channel.unary_unary( + self._stubs["delete_tag_key"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagKeys/DeleteTagKey", request_serializer=tag_keys.DeleteTagKeyRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -453,7 +538,7 @@ def get_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_iam_policy" not in self._stubs: - self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["get_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagKeys/GetIamPolicy", request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -483,7 +568,7 @@ def set_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "set_iam_policy" not in self._stubs: - self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["set_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagKeys/SetIamPolicy", request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -516,7 +601,7 @@ def test_iam_permissions( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "test_iam_permissions" not in self._stubs: - self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + self._stubs["test_iam_permissions"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagKeys/TestIamPermissions", request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, @@ -611,7 +696,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: @@ -627,7 +712,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/transports/rest.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/transports/rest.py index 71f15619d2c5..33d03a329e50 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/transports/rest.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_keys/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -40,6 +40,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -142,8 +150,10 @@ def post_update_tag_key(self, response): """ def pre_create_tag_key( - self, request: tag_keys.CreateTagKeyRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[tag_keys.CreateTagKeyRequest, Sequence[Tuple[str, str]]]: + self, + request: tag_keys.CreateTagKeyRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[tag_keys.CreateTagKeyRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for create_tag_key Override in a subclass to manipulate the request or metadata @@ -163,8 +173,10 @@ def post_create_tag_key( return response def pre_delete_tag_key( - self, request: tag_keys.DeleteTagKeyRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[tag_keys.DeleteTagKeyRequest, Sequence[Tuple[str, str]]]: + self, + request: tag_keys.DeleteTagKeyRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[tag_keys.DeleteTagKeyRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for delete_tag_key Override in a subclass to manipulate the request or metadata @@ -186,8 +198,10 @@ def post_delete_tag_key( def pre_get_iam_policy( self, request: iam_policy_pb2.GetIamPolicyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[iam_policy_pb2.GetIamPolicyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + iam_policy_pb2.GetIamPolicyRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_iam_policy Override in a subclass to manipulate the request or metadata @@ -207,8 +221,10 @@ def post_get_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: def pre_get_namespaced_tag_key( self, request: tag_keys.GetNamespacedTagKeyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[tag_keys.GetNamespacedTagKeyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + tag_keys.GetNamespacedTagKeyRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_namespaced_tag_key Override in a subclass to manipulate the request or metadata @@ -226,8 +242,10 @@ def post_get_namespaced_tag_key(self, response: tag_keys.TagKey) -> tag_keys.Tag return response def pre_get_tag_key( - self, request: tag_keys.GetTagKeyRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[tag_keys.GetTagKeyRequest, Sequence[Tuple[str, str]]]: + self, + request: tag_keys.GetTagKeyRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[tag_keys.GetTagKeyRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for get_tag_key Override in a subclass to manipulate the request or metadata @@ -245,8 +263,10 @@ def post_get_tag_key(self, response: tag_keys.TagKey) -> tag_keys.TagKey: return response def pre_list_tag_keys( - self, request: tag_keys.ListTagKeysRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[tag_keys.ListTagKeysRequest, Sequence[Tuple[str, str]]]: + self, + request: tag_keys.ListTagKeysRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[tag_keys.ListTagKeysRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for list_tag_keys Override in a subclass to manipulate the request or metadata @@ -268,8 +288,10 @@ def post_list_tag_keys( def pre_set_iam_policy( self, request: iam_policy_pb2.SetIamPolicyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[iam_policy_pb2.SetIamPolicyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + iam_policy_pb2.SetIamPolicyRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for set_iam_policy Override in a subclass to manipulate the request or metadata @@ -289,8 +311,11 @@ def post_set_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: def pre_test_iam_permissions( self, request: iam_policy_pb2.TestIamPermissionsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[iam_policy_pb2.TestIamPermissionsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + iam_policy_pb2.TestIamPermissionsRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for test_iam_permissions Override in a subclass to manipulate the request or metadata @@ -310,8 +335,10 @@ def post_test_iam_permissions( return response def pre_update_tag_key( - self, request: tag_keys.UpdateTagKeyRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[tag_keys.UpdateTagKeyRequest, Sequence[Tuple[str, str]]]: + self, + request: tag_keys.UpdateTagKeyRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[tag_keys.UpdateTagKeyRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for update_tag_key Override in a subclass to manipulate the request or metadata @@ -333,8 +360,10 @@ def post_update_tag_key( def pre_get_operation( self, request: operations_pb2.GetOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.GetOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.GetOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_operation Override in a subclass to manipulate the request or metadata @@ -508,7 +537,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the create tag key method over HTTP. @@ -519,8 +548,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -533,6 +564,7 @@ def __call__( http_options = ( _BaseTagKeysRestTransport._BaseCreateTagKey._get_http_options() ) + request, metadata = self._interceptor.pre_create_tag_key(request, metadata) transcoded_request = ( _BaseTagKeysRestTransport._BaseCreateTagKey._get_transcoded_request( @@ -551,6 +583,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagKeysClient.CreateTagKey", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": "CreateTagKey", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagKeysRestTransport._CreateTagKey._get_response( self._host, @@ -570,7 +629,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_tag_key(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagKeysClient.create_tag_key", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": "CreateTagKey", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DeleteTagKey(_BaseTagKeysRestTransport._BaseDeleteTagKey, TagKeysRestStub): @@ -605,7 +686,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the delete tag key method over HTTP. @@ -616,8 +697,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -630,6 +713,7 @@ def __call__( http_options = ( _BaseTagKeysRestTransport._BaseDeleteTagKey._get_http_options() ) + request, metadata = self._interceptor.pre_delete_tag_key(request, metadata) transcoded_request = ( _BaseTagKeysRestTransport._BaseDeleteTagKey._get_transcoded_request( @@ -644,6 +728,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagKeysClient.DeleteTagKey", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": "DeleteTagKey", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagKeysRestTransport._DeleteTagKey._get_response( self._host, @@ -662,7 +773,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_delete_tag_key(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagKeysClient.delete_tag_key", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": "DeleteTagKey", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetIamPolicy(_BaseTagKeysRestTransport._BaseGetIamPolicy, TagKeysRestStub): @@ -698,7 +831,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Call the get iam policy method over HTTP. @@ -708,8 +841,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.policy_pb2.Policy: @@ -794,6 +929,7 @@ def __call__( http_options = ( _BaseTagKeysRestTransport._BaseGetIamPolicy._get_http_options() ) + request, metadata = self._interceptor.pre_get_iam_policy(request, metadata) transcoded_request = ( _BaseTagKeysRestTransport._BaseGetIamPolicy._get_transcoded_request( @@ -812,6 +948,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagKeysClient.GetIamPolicy", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": "GetIamPolicy", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagKeysRestTransport._GetIamPolicy._get_response( self._host, @@ -833,7 +996,29 @@ def __call__( pb_resp = resp json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_iam_policy(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagKeysClient.get_iam_policy", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": "GetIamPolicy", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetNamespacedTagKey( @@ -870,7 +1055,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> tag_keys.TagKey: r"""Call the get namespaced tag key method over HTTP. @@ -881,8 +1066,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.tag_keys.TagKey: @@ -894,6 +1081,7 @@ def __call__( http_options = ( _BaseTagKeysRestTransport._BaseGetNamespacedTagKey._get_http_options() ) + request, metadata = self._interceptor.pre_get_namespaced_tag_key( request, metadata ) @@ -906,6 +1094,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagKeysClient.GetNamespacedTagKey", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": "GetNamespacedTagKey", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagKeysRestTransport._GetNamespacedTagKey._get_response( self._host, @@ -926,7 +1141,29 @@ def __call__( pb_resp = tag_keys.TagKey.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_namespaced_tag_key(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = tag_keys.TagKey.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagKeysClient.get_namespaced_tag_key", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": "GetNamespacedTagKey", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetTagKey(_BaseTagKeysRestTransport._BaseGetTagKey, TagKeysRestStub): @@ -961,7 +1198,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> tag_keys.TagKey: r"""Call the get tag key method over HTTP. @@ -972,8 +1209,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.tag_keys.TagKey: @@ -983,6 +1222,7 @@ def __call__( """ http_options = _BaseTagKeysRestTransport._BaseGetTagKey._get_http_options() + request, metadata = self._interceptor.pre_get_tag_key(request, metadata) transcoded_request = ( _BaseTagKeysRestTransport._BaseGetTagKey._get_transcoded_request( @@ -997,6 +1237,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagKeysClient.GetTagKey", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": "GetTagKey", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagKeysRestTransport._GetTagKey._get_response( self._host, @@ -1017,7 +1284,29 @@ def __call__( pb_resp = tag_keys.TagKey.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_tag_key(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = tag_keys.TagKey.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagKeysClient.get_tag_key", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": "GetTagKey", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListTagKeys(_BaseTagKeysRestTransport._BaseListTagKeys, TagKeysRestStub): @@ -1052,7 +1341,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> tag_keys.ListTagKeysResponse: r"""Call the list tag keys method over HTTP. @@ -1063,8 +1352,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.tag_keys.ListTagKeysResponse: @@ -1074,6 +1365,7 @@ def __call__( http_options = ( _BaseTagKeysRestTransport._BaseListTagKeys._get_http_options() ) + request, metadata = self._interceptor.pre_list_tag_keys(request, metadata) transcoded_request = ( _BaseTagKeysRestTransport._BaseListTagKeys._get_transcoded_request( @@ -1088,6 +1380,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagKeysClient.ListTagKeys", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": "ListTagKeys", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagKeysRestTransport._ListTagKeys._get_response( self._host, @@ -1108,7 +1427,29 @@ def __call__( pb_resp = tag_keys.ListTagKeysResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_tag_keys(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = tag_keys.ListTagKeysResponse.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagKeysClient.list_tag_keys", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": "ListTagKeys", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _SetIamPolicy(_BaseTagKeysRestTransport._BaseSetIamPolicy, TagKeysRestStub): @@ -1144,7 +1485,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Call the set iam policy method over HTTP. @@ -1154,8 +1495,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.policy_pb2.Policy: @@ -1240,6 +1583,7 @@ def __call__( http_options = ( _BaseTagKeysRestTransport._BaseSetIamPolicy._get_http_options() ) + request, metadata = self._interceptor.pre_set_iam_policy(request, metadata) transcoded_request = ( _BaseTagKeysRestTransport._BaseSetIamPolicy._get_transcoded_request( @@ -1258,6 +1602,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagKeysClient.SetIamPolicy", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": "SetIamPolicy", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagKeysRestTransport._SetIamPolicy._get_response( self._host, @@ -1279,7 +1650,29 @@ def __call__( pb_resp = resp json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_set_iam_policy(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagKeysClient.set_iam_policy", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": "SetIamPolicy", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _TestIamPermissions( @@ -1317,7 +1710,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: r"""Call the test iam permissions method over HTTP. @@ -1327,8 +1720,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.iam_policy_pb2.TestIamPermissionsResponse: @@ -1338,6 +1733,7 @@ def __call__( http_options = ( _BaseTagKeysRestTransport._BaseTestIamPermissions._get_http_options() ) + request, metadata = self._interceptor.pre_test_iam_permissions( request, metadata ) @@ -1354,6 +1750,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagKeysClient.TestIamPermissions", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": "TestIamPermissions", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagKeysRestTransport._TestIamPermissions._get_response( self._host, @@ -1375,7 +1798,29 @@ def __call__( pb_resp = resp json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_test_iam_permissions(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagKeysClient.test_iam_permissions", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": "TestIamPermissions", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateTagKey(_BaseTagKeysRestTransport._BaseUpdateTagKey, TagKeysRestStub): @@ -1411,7 +1856,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the update tag key method over HTTP. @@ -1422,8 +1867,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1436,6 +1883,7 @@ def __call__( http_options = ( _BaseTagKeysRestTransport._BaseUpdateTagKey._get_http_options() ) + request, metadata = self._interceptor.pre_update_tag_key(request, metadata) transcoded_request = ( _BaseTagKeysRestTransport._BaseUpdateTagKey._get_transcoded_request( @@ -1454,6 +1902,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagKeysClient.UpdateTagKey", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": "UpdateTagKey", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagKeysRestTransport._UpdateTagKey._get_response( self._host, @@ -1473,7 +1948,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_tag_key(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagKeysClient.update_tag_key", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": "UpdateTagKey", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property @@ -1585,7 +2082,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the get operation method over HTTP. @@ -1595,8 +2092,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: operations_pb2.Operation: Response from GetOperation method. @@ -1605,6 +2104,7 @@ def __call__( http_options = ( _BaseTagKeysRestTransport._BaseGetOperation._get_http_options() ) + request, metadata = self._interceptor.pre_get_operation(request, metadata) transcoded_request = ( _BaseTagKeysRestTransport._BaseGetOperation._get_transcoded_request( @@ -1619,6 +2119,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagKeysClient.GetOperation", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": "GetOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagKeysRestTransport._GetOperation._get_response( self._host, @@ -1638,6 +2165,27 @@ def __call__( resp = operations_pb2.Operation() resp = json_format.Parse(content, resp) resp = self._interceptor.post_get_operation(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagKeysAsyncClient.GetOperation", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagKeys", + "rpcName": "GetOperation", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/async_client.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/async_client.py index a281aee5c2a0..3d5c6486a4c3 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/async_client.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -57,6 +58,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, TagValuesTransport from .transports.grpc_asyncio import TagValuesGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class TagValuesAsyncClient: """Allow users to create and manage tag values.""" @@ -256,6 +266,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.resourcemanager_v3.TagValuesAsyncClient`.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "credentialsType": None, + }, + ) + async def list_tag_values( self, request: Optional[Union[tag_values.ListTagValuesRequest, dict]] = None, @@ -263,7 +295,7 @@ async def list_tag_values( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListTagValuesAsyncPager: r"""Lists all TagValues for a specific TagKey. @@ -308,8 +340,10 @@ async def sample_list_tag_values(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.services.tag_values.pagers.ListTagValuesAsyncPager: @@ -378,7 +412,7 @@ async def get_tag_value( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> tag_values.TagValue: r"""Retrieves a TagValue. This method will return ``PERMISSION_DENIED`` if the value does not exist or the user @@ -424,8 +458,10 @@ async def sample_get_tag_value(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.types.TagValue: @@ -488,7 +524,7 @@ async def get_namespaced_tag_value( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> tag_values.TagValue: r"""Retrieves a TagValue by its namespaced name. This method will return ``PERMISSION_DENIED`` if the value does not exist or the @@ -545,8 +581,10 @@ async def sample_get_namespaced_tag_value(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.types.TagValue: @@ -603,7 +641,7 @@ async def create_tag_value( tag_value: Optional[tag_values.TagValue] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Creates a TagValue as a child of the specified TagKey. If a another request with the same parameters is @@ -659,8 +697,10 @@ async def sample_create_tag_value(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -727,7 +767,7 @@ async def update_tag_value( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Updates the attributes of the TagValue resource. @@ -787,8 +827,10 @@ async def sample_update_tag_value(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -864,7 +906,7 @@ async def delete_tag_value( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a TagValue. The TagValue cannot have any bindings when it is deleted. @@ -914,8 +956,10 @@ async def sample_delete_tag_value(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation_async.AsyncOperation: @@ -987,7 +1031,7 @@ async def get_iam_policy( resource: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Gets the access control policy for a TagValue. The returned policy may be empty if no such policy or resource exists. The @@ -1039,8 +1083,10 @@ async def sample_get_iam_policy(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.policy_pb2.Policy: @@ -1126,7 +1172,7 @@ async def set_iam_policy( resource: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Sets the access control policy on a TagValue, replacing any existing policy. The ``resource`` field should be the TagValue's @@ -1176,8 +1222,10 @@ async def sample_set_iam_policy(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.policy_pb2.Policy: @@ -1264,7 +1312,7 @@ async def test_iam_permissions( permissions: Optional[MutableSequence[str]] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: r"""Returns permissions that a caller has on the specified TagValue. The ``resource`` field should be the TagValue's resource name. @@ -1324,8 +1372,10 @@ async def sample_test_iam_permissions(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: @@ -1382,7 +1432,7 @@ async def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -1393,8 +1443,10 @@ async def get_operation( retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/client.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/client.py index 6110fc9e8f2a..fd081c6cd176 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/client.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.iam.v1 import iam_policy_pb2 # type: ignore @@ -577,6 +587,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -639,6 +653,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.resourcemanager_v3.TagValuesClient`.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "credentialsType": None, + }, + ) + def list_tag_values( self, request: Optional[Union[tag_values.ListTagValuesRequest, dict]] = None, @@ -646,7 +683,7 @@ def list_tag_values( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListTagValuesPager: r"""Lists all TagValues for a specific TagKey. @@ -691,8 +728,10 @@ def sample_list_tag_values(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.services.tag_values.pagers.ListTagValuesPager: @@ -758,7 +797,7 @@ def get_tag_value( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> tag_values.TagValue: r"""Retrieves a TagValue. This method will return ``PERMISSION_DENIED`` if the value does not exist or the user @@ -804,8 +843,10 @@ def sample_get_tag_value(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.types.TagValue: @@ -865,7 +906,7 @@ def get_namespaced_tag_value( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> tag_values.TagValue: r"""Retrieves a TagValue by its namespaced name. This method will return ``PERMISSION_DENIED`` if the value does not exist or the @@ -922,8 +963,10 @@ def sample_get_namespaced_tag_value(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcemanager_v3.types.TagValue: @@ -977,7 +1020,7 @@ def create_tag_value( tag_value: Optional[tag_values.TagValue] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Creates a TagValue as a child of the specified TagKey. If a another request with the same parameters is @@ -1033,8 +1076,10 @@ def sample_create_tag_value(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1098,7 +1143,7 @@ def update_tag_value( update_mask: Optional[field_mask_pb2.FieldMask] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Updates the attributes of the TagValue resource. @@ -1158,8 +1203,10 @@ def sample_update_tag_value(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1232,7 +1279,7 @@ def delete_tag_value( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operation.Operation: r"""Deletes a TagValue. The TagValue cannot have any bindings when it is deleted. @@ -1282,8 +1329,10 @@ def sample_delete_tag_value(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.api_core.operation.Operation: @@ -1352,7 +1401,7 @@ def get_iam_policy( resource: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Gets the access control policy for a TagValue. The returned policy may be empty if no such policy or resource exists. The @@ -1404,8 +1453,10 @@ def sample_get_iam_policy(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.policy_pb2.Policy: @@ -1492,7 +1543,7 @@ def set_iam_policy( resource: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Sets the access control policy on a TagValue, replacing any existing policy. The ``resource`` field should be the TagValue's @@ -1542,8 +1593,10 @@ def sample_set_iam_policy(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.policy_pb2.Policy: @@ -1631,7 +1684,7 @@ def test_iam_permissions( permissions: Optional[MutableSequence[str]] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: r"""Returns permissions that a caller has on the specified TagValue. The ``resource`` field should be the TagValue's resource name. @@ -1691,8 +1744,10 @@ def sample_test_iam_permissions(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: @@ -1763,7 +1818,7 @@ def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -1774,8 +1829,10 @@ def get_operation( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: An ``Operation`` object. diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/pagers.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/pagers.py index 0952df8d17d4..e0e5fec82f1b 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/pagers.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -81,8 +81,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = tag_values.ListTagValuesRequest(request) @@ -141,7 +143,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -155,8 +157,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = tag_values.ListTagValuesRequest(request) diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/transports/grpc.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/transports/grpc.py index 917b4f073736..acf988ad41c1 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/transports/grpc.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -23,12 +26,90 @@ from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.resourcemanager_v3.types import tag_values from .base import DEFAULT_CLIENT_INFO, TagValuesTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class TagValuesGrpcTransport(TagValuesTransport): """gRPC backend transport for TagValues. @@ -183,7 +264,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -247,7 +333,9 @@ def operations_client(self) -> operations_v1.OperationsClient: """ # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + self._operations_client = operations_v1.OperationsClient( + self._logged_channel + ) # Return the client from cache. return self._operations_client @@ -271,7 +359,7 @@ def list_tag_values( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_tag_values" not in self._stubs: - self._stubs["list_tag_values"] = self.grpc_channel.unary_unary( + self._stubs["list_tag_values"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagValues/ListTagValues", request_serializer=tag_values.ListTagValuesRequest.serialize, response_deserializer=tag_values.ListTagValuesResponse.deserialize, @@ -299,7 +387,7 @@ def get_tag_value( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_tag_value" not in self._stubs: - self._stubs["get_tag_value"] = self.grpc_channel.unary_unary( + self._stubs["get_tag_value"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagValues/GetTagValue", request_serializer=tag_values.GetTagValueRequest.serialize, response_deserializer=tag_values.TagValue.deserialize, @@ -327,7 +415,7 @@ def get_namespaced_tag_value( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_namespaced_tag_value" not in self._stubs: - self._stubs["get_namespaced_tag_value"] = self.grpc_channel.unary_unary( + self._stubs["get_namespaced_tag_value"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagValues/GetNamespacedTagValue", request_serializer=tag_values.GetNamespacedTagValueRequest.serialize, response_deserializer=tag_values.TagValue.deserialize, @@ -357,7 +445,7 @@ def create_tag_value( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_tag_value" not in self._stubs: - self._stubs["create_tag_value"] = self.grpc_channel.unary_unary( + self._stubs["create_tag_value"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagValues/CreateTagValue", request_serializer=tag_values.CreateTagValueRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -383,7 +471,7 @@ def update_tag_value( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_tag_value" not in self._stubs: - self._stubs["update_tag_value"] = self.grpc_channel.unary_unary( + self._stubs["update_tag_value"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagValues/UpdateTagValue", request_serializer=tag_values.UpdateTagValueRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -410,7 +498,7 @@ def delete_tag_value( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_tag_value" not in self._stubs: - self._stubs["delete_tag_value"] = self.grpc_channel.unary_unary( + self._stubs["delete_tag_value"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagValues/DeleteTagValue", request_serializer=tag_values.DeleteTagValueRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -442,7 +530,7 @@ def get_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_iam_policy" not in self._stubs: - self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["get_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagValues/GetIamPolicy", request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -472,7 +560,7 @@ def set_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "set_iam_policy" not in self._stubs: - self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["set_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagValues/SetIamPolicy", request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -505,7 +593,7 @@ def test_iam_permissions( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "test_iam_permissions" not in self._stubs: - self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + self._stubs["test_iam_permissions"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagValues/TestIamPermissions", request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, @@ -513,7 +601,7 @@ def test_iam_permissions( return self._stubs["test_iam_permissions"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def get_operation( @@ -525,7 +613,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/transports/grpc_asyncio.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/transports/grpc_asyncio.py index 77154bab434a..cebc687dacbf 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/transports/grpc_asyncio.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -25,14 +28,93 @@ from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.resourcemanager_v3.types import tag_values from .base import DEFAULT_CLIENT_INFO, TagValuesTransport from .grpc import TagValuesGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class TagValuesGrpcAsyncIOTransport(TagValuesTransport): """gRPC AsyncIO backend transport for TagValues. @@ -230,10 +312,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -256,7 +341,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel + self._logged_channel ) # Return the client from cache. @@ -283,7 +368,7 @@ def list_tag_values( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_tag_values" not in self._stubs: - self._stubs["list_tag_values"] = self.grpc_channel.unary_unary( + self._stubs["list_tag_values"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagValues/ListTagValues", request_serializer=tag_values.ListTagValuesRequest.serialize, response_deserializer=tag_values.ListTagValuesResponse.deserialize, @@ -311,7 +396,7 @@ def get_tag_value( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_tag_value" not in self._stubs: - self._stubs["get_tag_value"] = self.grpc_channel.unary_unary( + self._stubs["get_tag_value"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagValues/GetTagValue", request_serializer=tag_values.GetTagValueRequest.serialize, response_deserializer=tag_values.TagValue.deserialize, @@ -341,7 +426,7 @@ def get_namespaced_tag_value( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_namespaced_tag_value" not in self._stubs: - self._stubs["get_namespaced_tag_value"] = self.grpc_channel.unary_unary( + self._stubs["get_namespaced_tag_value"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagValues/GetNamespacedTagValue", request_serializer=tag_values.GetNamespacedTagValueRequest.serialize, response_deserializer=tag_values.TagValue.deserialize, @@ -373,7 +458,7 @@ def create_tag_value( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "create_tag_value" not in self._stubs: - self._stubs["create_tag_value"] = self.grpc_channel.unary_unary( + self._stubs["create_tag_value"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagValues/CreateTagValue", request_serializer=tag_values.CreateTagValueRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -401,7 +486,7 @@ def update_tag_value( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_tag_value" not in self._stubs: - self._stubs["update_tag_value"] = self.grpc_channel.unary_unary( + self._stubs["update_tag_value"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagValues/UpdateTagValue", request_serializer=tag_values.UpdateTagValueRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -430,7 +515,7 @@ def delete_tag_value( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "delete_tag_value" not in self._stubs: - self._stubs["delete_tag_value"] = self.grpc_channel.unary_unary( + self._stubs["delete_tag_value"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagValues/DeleteTagValue", request_serializer=tag_values.DeleteTagValueRequest.serialize, response_deserializer=operations_pb2.Operation.FromString, @@ -462,7 +547,7 @@ def get_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_iam_policy" not in self._stubs: - self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["get_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagValues/GetIamPolicy", request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -492,7 +577,7 @@ def set_iam_policy( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "set_iam_policy" not in self._stubs: - self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + self._stubs["set_iam_policy"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagValues/SetIamPolicy", request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, response_deserializer=policy_pb2.Policy.FromString, @@ -525,7 +610,7 @@ def test_iam_permissions( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "test_iam_permissions" not in self._stubs: - self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + self._stubs["test_iam_permissions"] = self._logged_channel.unary_unary( "/google.cloud.resourcemanager.v3.TagValues/TestIamPermissions", request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, @@ -620,7 +705,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: @@ -636,7 +721,7 @@ def get_operation( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( + self._stubs["get_operation"] = self._logged_channel.unary_unary( "/google.longrunning.Operations/GetOperation", request_serializer=operations_pb2.GetOperationRequest.SerializeToString, response_deserializer=operations_pb2.Operation.FromString, diff --git a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/transports/rest.py b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/transports/rest.py index 543d523f73e4..bad4838b1c73 100644 --- a/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/transports/rest.py +++ b/packages/google-cloud-resource-manager/google/cloud/resourcemanager_v3/services/tag_values/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -40,6 +40,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -144,8 +152,10 @@ def post_update_tag_value(self, response): def pre_create_tag_value( self, request: tag_values.CreateTagValueRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[tag_values.CreateTagValueRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + tag_values.CreateTagValueRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for create_tag_value Override in a subclass to manipulate the request or metadata @@ -167,8 +177,10 @@ def post_create_tag_value( def pre_delete_tag_value( self, request: tag_values.DeleteTagValueRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[tag_values.DeleteTagValueRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + tag_values.DeleteTagValueRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for delete_tag_value Override in a subclass to manipulate the request or metadata @@ -190,8 +202,10 @@ def post_delete_tag_value( def pre_get_iam_policy( self, request: iam_policy_pb2.GetIamPolicyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[iam_policy_pb2.GetIamPolicyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + iam_policy_pb2.GetIamPolicyRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_iam_policy Override in a subclass to manipulate the request or metadata @@ -211,8 +225,10 @@ def post_get_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: def pre_get_namespaced_tag_value( self, request: tag_values.GetNamespacedTagValueRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[tag_values.GetNamespacedTagValueRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + tag_values.GetNamespacedTagValueRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_namespaced_tag_value Override in a subclass to manipulate the request or metadata @@ -234,8 +250,8 @@ def post_get_namespaced_tag_value( def pre_get_tag_value( self, request: tag_values.GetTagValueRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[tag_values.GetTagValueRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[tag_values.GetTagValueRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for get_tag_value Override in a subclass to manipulate the request or metadata @@ -255,8 +271,10 @@ def post_get_tag_value(self, response: tag_values.TagValue) -> tag_values.TagVal def pre_list_tag_values( self, request: tag_values.ListTagValuesRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[tag_values.ListTagValuesRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + tag_values.ListTagValuesRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_tag_values Override in a subclass to manipulate the request or metadata @@ -278,8 +296,10 @@ def post_list_tag_values( def pre_set_iam_policy( self, request: iam_policy_pb2.SetIamPolicyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[iam_policy_pb2.SetIamPolicyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + iam_policy_pb2.SetIamPolicyRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for set_iam_policy Override in a subclass to manipulate the request or metadata @@ -299,8 +319,11 @@ def post_set_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: def pre_test_iam_permissions( self, request: iam_policy_pb2.TestIamPermissionsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[iam_policy_pb2.TestIamPermissionsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + iam_policy_pb2.TestIamPermissionsRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for test_iam_permissions Override in a subclass to manipulate the request or metadata @@ -322,8 +345,10 @@ def post_test_iam_permissions( def pre_update_tag_value( self, request: tag_values.UpdateTagValueRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[tag_values.UpdateTagValueRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + tag_values.UpdateTagValueRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for update_tag_value Override in a subclass to manipulate the request or metadata @@ -345,8 +370,10 @@ def post_update_tag_value( def pre_get_operation( self, request: operations_pb2.GetOperationRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[operations_pb2.GetOperationRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.GetOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_operation Override in a subclass to manipulate the request or metadata @@ -522,7 +549,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the create tag value method over HTTP. @@ -533,8 +560,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -547,6 +576,7 @@ def __call__( http_options = ( _BaseTagValuesRestTransport._BaseCreateTagValue._get_http_options() ) + request, metadata = self._interceptor.pre_create_tag_value( request, metadata ) @@ -569,6 +599,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagValuesClient.CreateTagValue", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": "CreateTagValue", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagValuesRestTransport._CreateTagValue._get_response( self._host, @@ -588,7 +645,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_tag_value(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagValuesClient.create_tag_value", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": "CreateTagValue", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _DeleteTagValue( @@ -625,7 +704,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the delete tag value method over HTTP. @@ -636,8 +715,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -650,6 +731,7 @@ def __call__( http_options = ( _BaseTagValuesRestTransport._BaseDeleteTagValue._get_http_options() ) + request, metadata = self._interceptor.pre_delete_tag_value( request, metadata ) @@ -666,6 +748,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagValuesClient.DeleteTagValue", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": "DeleteTagValue", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagValuesRestTransport._DeleteTagValue._get_response( self._host, @@ -684,7 +793,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_delete_tag_value(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagValuesClient.delete_tag_value", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": "DeleteTagValue", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetIamPolicy( @@ -722,7 +853,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Call the get iam policy method over HTTP. @@ -732,8 +863,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.policy_pb2.Policy: @@ -818,6 +951,7 @@ def __call__( http_options = ( _BaseTagValuesRestTransport._BaseGetIamPolicy._get_http_options() ) + request, metadata = self._interceptor.pre_get_iam_policy(request, metadata) transcoded_request = ( _BaseTagValuesRestTransport._BaseGetIamPolicy._get_transcoded_request( @@ -836,6 +970,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagValuesClient.GetIamPolicy", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": "GetIamPolicy", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagValuesRestTransport._GetIamPolicy._get_response( self._host, @@ -857,7 +1018,29 @@ def __call__( pb_resp = resp json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_iam_policy(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagValuesClient.get_iam_policy", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": "GetIamPolicy", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetNamespacedTagValue( @@ -894,7 +1077,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> tag_values.TagValue: r"""Call the get namespaced tag value method over HTTP. @@ -905,8 +1088,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.tag_values.TagValue: @@ -920,6 +1105,7 @@ def __call__( http_options = ( _BaseTagValuesRestTransport._BaseGetNamespacedTagValue._get_http_options() ) + request, metadata = self._interceptor.pre_get_namespaced_tag_value( request, metadata ) @@ -932,6 +1118,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagValuesClient.GetNamespacedTagValue", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": "GetNamespacedTagValue", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagValuesRestTransport._GetNamespacedTagValue._get_response( self._host, @@ -952,7 +1165,29 @@ def __call__( pb_resp = tag_values.TagValue.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_namespaced_tag_value(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = tag_values.TagValue.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagValuesClient.get_namespaced_tag_value", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": "GetNamespacedTagValue", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _GetTagValue(_BaseTagValuesRestTransport._BaseGetTagValue, TagValuesRestStub): @@ -987,7 +1222,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> tag_values.TagValue: r"""Call the get tag value method over HTTP. @@ -998,8 +1233,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.tag_values.TagValue: @@ -1013,6 +1250,7 @@ def __call__( http_options = ( _BaseTagValuesRestTransport._BaseGetTagValue._get_http_options() ) + request, metadata = self._interceptor.pre_get_tag_value(request, metadata) transcoded_request = ( _BaseTagValuesRestTransport._BaseGetTagValue._get_transcoded_request( @@ -1027,6 +1265,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagValuesClient.GetTagValue", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": "GetTagValue", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagValuesRestTransport._GetTagValue._get_response( self._host, @@ -1047,7 +1312,29 @@ def __call__( pb_resp = tag_values.TagValue.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_tag_value(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = tag_values.TagValue.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagValuesClient.get_tag_value", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": "GetTagValue", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListTagValues( @@ -1084,7 +1371,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> tag_values.ListTagValuesResponse: r"""Call the list tag values method over HTTP. @@ -1097,8 +1384,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.tag_values.ListTagValuesResponse: @@ -1108,6 +1397,7 @@ def __call__( http_options = ( _BaseTagValuesRestTransport._BaseListTagValues._get_http_options() ) + request, metadata = self._interceptor.pre_list_tag_values(request, metadata) transcoded_request = ( _BaseTagValuesRestTransport._BaseListTagValues._get_transcoded_request( @@ -1122,6 +1412,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagValuesClient.ListTagValues", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": "ListTagValues", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagValuesRestTransport._ListTagValues._get_response( self._host, @@ -1142,7 +1459,31 @@ def __call__( pb_resp = tag_values.ListTagValuesResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_tag_values(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = tag_values.ListTagValuesResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagValuesClient.list_tag_values", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": "ListTagValues", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _SetIamPolicy( @@ -1180,7 +1521,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> policy_pb2.Policy: r"""Call the set iam policy method over HTTP. @@ -1190,8 +1531,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.policy_pb2.Policy: @@ -1276,6 +1619,7 @@ def __call__( http_options = ( _BaseTagValuesRestTransport._BaseSetIamPolicy._get_http_options() ) + request, metadata = self._interceptor.pre_set_iam_policy(request, metadata) transcoded_request = ( _BaseTagValuesRestTransport._BaseSetIamPolicy._get_transcoded_request( @@ -1294,6 +1638,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagValuesClient.SetIamPolicy", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": "SetIamPolicy", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagValuesRestTransport._SetIamPolicy._get_response( self._host, @@ -1315,7 +1686,29 @@ def __call__( pb_resp = resp json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_set_iam_policy(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagValuesClient.set_iam_policy", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": "SetIamPolicy", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _TestIamPermissions( @@ -1353,7 +1746,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: r"""Call the test iam permissions method over HTTP. @@ -1363,8 +1756,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.iam_policy_pb2.TestIamPermissionsResponse: @@ -1374,6 +1769,7 @@ def __call__( http_options = ( _BaseTagValuesRestTransport._BaseTestIamPermissions._get_http_options() ) + request, metadata = self._interceptor.pre_test_iam_permissions( request, metadata ) @@ -1390,6 +1786,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagValuesClient.TestIamPermissions", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": "TestIamPermissions", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagValuesRestTransport._TestIamPermissions._get_response( self._host, @@ -1411,7 +1834,29 @@ def __call__( pb_resp = resp json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_test_iam_permissions(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagValuesClient.test_iam_permissions", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": "TestIamPermissions", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateTagValue( @@ -1449,7 +1894,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the update tag value method over HTTP. @@ -1460,8 +1905,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.operations_pb2.Operation: @@ -1474,6 +1921,7 @@ def __call__( http_options = ( _BaseTagValuesRestTransport._BaseUpdateTagValue._get_http_options() ) + request, metadata = self._interceptor.pre_update_tag_value( request, metadata ) @@ -1496,6 +1944,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagValuesClient.UpdateTagValue", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": "UpdateTagValue", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagValuesRestTransport._UpdateTagValue._get_response( self._host, @@ -1515,7 +1990,29 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_tag_value(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagValuesClient.update_tag_value", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": "UpdateTagValue", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property @@ -1631,7 +2128,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> operations_pb2.Operation: r"""Call the get operation method over HTTP. @@ -1641,8 +2138,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: operations_pb2.Operation: Response from GetOperation method. @@ -1651,6 +2150,7 @@ def __call__( http_options = ( _BaseTagValuesRestTransport._BaseGetOperation._get_http_options() ) + request, metadata = self._interceptor.pre_get_operation(request, metadata) transcoded_request = ( _BaseTagValuesRestTransport._BaseGetOperation._get_transcoded_request( @@ -1665,6 +2165,33 @@ def __call__( ) ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcemanager_v3.TagValuesClient.GetOperation", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": "GetOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = TagValuesRestTransport._GetOperation._get_response( self._host, @@ -1684,6 +2211,27 @@ def __call__( resp = operations_pb2.Operation() resp = json_format.Parse(content, resp) resp = self._interceptor.post_get_operation(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcemanager_v3.TagValuesAsyncClient.GetOperation", + extra={ + "serviceName": "google.cloud.resourcemanager.v3.TagValues", + "rpcName": "GetOperation", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) return resp @property diff --git a/packages/google-cloud-resource-manager/samples/generated_samples/snippet_metadata_google.cloud.resourcemanager.v3.json b/packages/google-cloud-resource-manager/samples/generated_samples/snippet_metadata_google.cloud.resourcemanager.v3.json index 2516b2643b20..18bac0c91496 100644 --- a/packages/google-cloud-resource-manager/samples/generated_samples/snippet_metadata_google.cloud.resourcemanager.v3.json +++ b/packages/google-cloud-resource-manager/samples/generated_samples/snippet_metadata_google.cloud.resourcemanager.v3.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-resource-manager", - "version": "1.13.1" + "version": "0.1.0" }, "snippets": [ { @@ -47,7 +47,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -127,7 +127,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -208,7 +208,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -288,7 +288,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -369,7 +369,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.types.Folder", @@ -449,7 +449,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.types.Folder", @@ -530,7 +530,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.policy_pb2.Policy", @@ -610,7 +610,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.policy_pb2.Policy", @@ -691,7 +691,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.services.folders.pagers.ListFoldersAsyncPager", @@ -771,7 +771,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.services.folders.pagers.ListFoldersPager", @@ -856,7 +856,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -940,7 +940,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -1021,7 +1021,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.services.folders.pagers.SearchFoldersAsyncPager", @@ -1101,7 +1101,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.services.folders.pagers.SearchFoldersPager", @@ -1182,7 +1182,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.policy_pb2.Policy", @@ -1262,7 +1262,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.policy_pb2.Policy", @@ -1347,7 +1347,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse", @@ -1431,7 +1431,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse", @@ -1512,7 +1512,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -1592,7 +1592,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -1677,7 +1677,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -1761,7 +1761,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -1842,7 +1842,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.policy_pb2.Policy", @@ -1922,7 +1922,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.policy_pb2.Policy", @@ -2003,7 +2003,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.types.Organization", @@ -2083,7 +2083,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.types.Organization", @@ -2164,7 +2164,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.services.organizations.pagers.SearchOrganizationsAsyncPager", @@ -2244,7 +2244,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.services.organizations.pagers.SearchOrganizationsPager", @@ -2325,7 +2325,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.policy_pb2.Policy", @@ -2405,7 +2405,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.policy_pb2.Policy", @@ -2490,7 +2490,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse", @@ -2574,7 +2574,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse", @@ -2655,7 +2655,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -2735,7 +2735,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -2816,7 +2816,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -2896,7 +2896,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -2977,7 +2977,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.policy_pb2.Policy", @@ -3057,7 +3057,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.policy_pb2.Policy", @@ -3138,7 +3138,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.types.Project", @@ -3218,7 +3218,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.types.Project", @@ -3299,7 +3299,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.services.projects.pagers.ListProjectsAsyncPager", @@ -3379,7 +3379,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.services.projects.pagers.ListProjectsPager", @@ -3464,7 +3464,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -3548,7 +3548,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -3629,7 +3629,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.services.projects.pagers.SearchProjectsAsyncPager", @@ -3709,7 +3709,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.services.projects.pagers.SearchProjectsPager", @@ -3790,7 +3790,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.policy_pb2.Policy", @@ -3870,7 +3870,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.policy_pb2.Policy", @@ -3955,7 +3955,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse", @@ -4039,7 +4039,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse", @@ -4120,7 +4120,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -4200,7 +4200,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -4285,7 +4285,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -4369,7 +4369,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -4450,7 +4450,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -4530,7 +4530,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -4611,7 +4611,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -4691,7 +4691,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -4772,7 +4772,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.services.tag_bindings.pagers.ListEffectiveTagsAsyncPager", @@ -4852,7 +4852,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.services.tag_bindings.pagers.ListEffectiveTagsPager", @@ -4933,7 +4933,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.services.tag_bindings.pagers.ListTagBindingsAsyncPager", @@ -5013,7 +5013,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.services.tag_bindings.pagers.ListTagBindingsPager", @@ -5098,7 +5098,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -5182,7 +5182,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -5263,7 +5263,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -5343,7 +5343,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -5424,7 +5424,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.services.tag_holds.pagers.ListTagHoldsAsyncPager", @@ -5504,7 +5504,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.services.tag_holds.pagers.ListTagHoldsPager", @@ -5585,7 +5585,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -5665,7 +5665,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -5746,7 +5746,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -5826,7 +5826,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -5907,7 +5907,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.policy_pb2.Policy", @@ -5987,7 +5987,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.policy_pb2.Policy", @@ -6068,7 +6068,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.types.TagKey", @@ -6148,7 +6148,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.types.TagKey", @@ -6229,7 +6229,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.types.TagKey", @@ -6309,7 +6309,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.types.TagKey", @@ -6390,7 +6390,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.services.tag_keys.pagers.ListTagKeysAsyncPager", @@ -6470,7 +6470,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.services.tag_keys.pagers.ListTagKeysPager", @@ -6551,7 +6551,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.policy_pb2.Policy", @@ -6631,7 +6631,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.policy_pb2.Policy", @@ -6716,7 +6716,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse", @@ -6800,7 +6800,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse", @@ -6885,7 +6885,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -6969,7 +6969,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -7050,7 +7050,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -7130,7 +7130,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -7211,7 +7211,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -7291,7 +7291,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", @@ -7372,7 +7372,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.policy_pb2.Policy", @@ -7452,7 +7452,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.policy_pb2.Policy", @@ -7533,7 +7533,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.types.TagValue", @@ -7613,7 +7613,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.types.TagValue", @@ -7694,7 +7694,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.types.TagValue", @@ -7774,7 +7774,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.types.TagValue", @@ -7855,7 +7855,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.services.tag_values.pagers.ListTagValuesAsyncPager", @@ -7935,7 +7935,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcemanager_v3.services.tag_values.pagers.ListTagValuesPager", @@ -8016,7 +8016,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.policy_pb2.Policy", @@ -8096,7 +8096,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.policy_pb2.Policy", @@ -8181,7 +8181,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse", @@ -8265,7 +8265,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse", @@ -8350,7 +8350,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation_async.AsyncOperation", @@ -8434,7 +8434,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.api_core.operation.Operation", diff --git a/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_folders.py b/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_folders.py index 5561ddb777e7..5142b5a5fa6c 100644 --- a/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_folders.py +++ b/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_folders.py @@ -4995,6 +4995,7 @@ def test_get_folder_rest_required_fields(request_type=folders.GetFolderRequest): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_folder(request) @@ -5040,6 +5041,7 @@ def test_get_folder_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_folder(**mock_args) @@ -5179,6 +5181,7 @@ def test_list_folders_rest_required_fields(request_type=folders.ListFoldersReque response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_folders(request) @@ -5240,6 +5243,7 @@ def test_list_folders_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_folders(**mock_args) @@ -5390,6 +5394,7 @@ def test_search_folders_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.search_folders(**mock_args) @@ -5575,6 +5580,7 @@ def test_create_folder_rest_required_fields(request_type=folders.CreateFolderReq response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_folder(request) @@ -5618,6 +5624,7 @@ def test_create_folder_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_folder(**mock_args) @@ -5742,6 +5749,7 @@ def test_update_folder_rest_required_fields(request_type=folders.UpdateFolderReq response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_folder(request) @@ -5794,6 +5802,7 @@ def test_update_folder_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_folder(**mock_args) @@ -5928,6 +5937,7 @@ def test_move_folder_rest_required_fields(request_type=folders.MoveFolderRequest response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.move_folder(request) @@ -5980,6 +5990,7 @@ def test_move_folder_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.move_folder(**mock_args) @@ -6109,6 +6120,7 @@ def test_delete_folder_rest_required_fields(request_type=folders.DeleteFolderReq response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_folder(request) @@ -6152,6 +6164,7 @@ def test_delete_folder_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_folder(**mock_args) @@ -6283,6 +6296,7 @@ def test_undelete_folder_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.undelete_folder(request) @@ -6326,6 +6340,7 @@ def test_undelete_folder_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.undelete_folder(**mock_args) @@ -6454,6 +6469,7 @@ def test_get_iam_policy_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_iam_policy(request) @@ -6497,6 +6513,7 @@ def test_get_iam_policy_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_iam_policy(**mock_args) @@ -6625,6 +6642,7 @@ def test_set_iam_policy_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.set_iam_policy(request) @@ -6676,6 +6694,7 @@ def test_set_iam_policy_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.set_iam_policy(**mock_args) @@ -6812,6 +6831,7 @@ def test_test_iam_permissions_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.test_iam_permissions(request) @@ -6864,6 +6884,7 @@ def test_test_iam_permissions_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.test_iam_permissions(**mock_args) @@ -7567,6 +7588,7 @@ def test_get_folder_rest_bad_request(request_type=folders.GetFolderRequest): response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_folder(request) @@ -7606,6 +7628,7 @@ def test_get_folder_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_folder(request) # Establish that the response is the type that we expect. @@ -7646,6 +7669,7 @@ def test_get_folder_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = folders.Folder.to_json(folders.Folder()) req.return_value.content = return_value @@ -7688,6 +7712,7 @@ def test_list_folders_rest_bad_request(request_type=folders.ListFoldersRequest): response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_folders(request) @@ -7723,6 +7748,7 @@ def test_list_folders_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_folders(request) # Establish that the response is the type that we expect. @@ -7759,6 +7785,7 @@ def test_list_folders_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = folders.ListFoldersResponse.to_json( folders.ListFoldersResponse() ) @@ -7803,6 +7830,7 @@ def test_search_folders_rest_bad_request(request_type=folders.SearchFoldersReque response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.search_folders(request) @@ -7838,6 +7866,7 @@ def test_search_folders_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.search_folders(request) # Establish that the response is the type that we expect. @@ -7874,6 +7903,7 @@ def test_search_folders_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = folders.SearchFoldersResponse.to_json( folders.SearchFoldersResponse() ) @@ -7918,6 +7948,7 @@ def test_create_folder_rest_bad_request(request_type=folders.CreateFolderRequest response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_folder(request) @@ -8025,6 +8056,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_folder(request) # Establish that the response is the type that we expect. @@ -8062,6 +8094,7 @@ def test_create_folder_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -8104,6 +8137,7 @@ def test_update_folder_rest_bad_request(request_type=folders.UpdateFolderRequest response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_folder(request) @@ -8211,6 +8245,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_folder(request) # Establish that the response is the type that we expect. @@ -8248,6 +8283,7 @@ def test_update_folder_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -8290,6 +8326,7 @@ def test_move_folder_rest_bad_request(request_type=folders.MoveFolderRequest): response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.move_folder(request) @@ -8320,6 +8357,7 @@ def test_move_folder_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.move_folder(request) # Establish that the response is the type that we expect. @@ -8357,6 +8395,7 @@ def test_move_folder_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -8399,6 +8438,7 @@ def test_delete_folder_rest_bad_request(request_type=folders.DeleteFolderRequest response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_folder(request) @@ -8429,6 +8469,7 @@ def test_delete_folder_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_folder(request) # Establish that the response is the type that we expect. @@ -8466,6 +8507,7 @@ def test_delete_folder_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -8508,6 +8550,7 @@ def test_undelete_folder_rest_bad_request(request_type=folders.UndeleteFolderReq response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.undelete_folder(request) @@ -8538,6 +8581,7 @@ def test_undelete_folder_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.undelete_folder(request) # Establish that the response is the type that we expect. @@ -8575,6 +8619,7 @@ def test_undelete_folder_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -8619,6 +8664,7 @@ def test_get_iam_policy_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_iam_policy(request) @@ -8652,6 +8698,7 @@ def test_get_iam_policy_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_iam_policy(request) # Establish that the response is the type that we expect. @@ -8689,6 +8736,7 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(policy_pb2.Policy()) req.return_value.content = return_value @@ -8733,6 +8781,7 @@ def test_set_iam_policy_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.set_iam_policy(request) @@ -8766,6 +8815,7 @@ def test_set_iam_policy_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.set_iam_policy(request) # Establish that the response is the type that we expect. @@ -8803,6 +8853,7 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(policy_pb2.Policy()) req.return_value.content = return_value @@ -8847,6 +8898,7 @@ def test_test_iam_permissions_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.test_iam_permissions(request) @@ -8879,6 +8931,7 @@ def test_test_iam_permissions_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.test_iam_permissions(request) # Establish that the response is the type that we expect. @@ -8915,6 +8968,7 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson( iam_policy_pb2.TestIamPermissionsResponse() ) @@ -8961,6 +9015,7 @@ def test_get_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_operation(request) @@ -8991,6 +9046,7 @@ def test_get_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_operation(request) diff --git a/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_organizations.py b/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_organizations.py index e4f013a13d5c..18afea0f64d2 100644 --- a/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_organizations.py +++ b/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_organizations.py @@ -3038,6 +3038,7 @@ def test_get_organization_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_organization(request) @@ -3083,6 +3084,7 @@ def test_get_organization_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_organization(**mock_args) @@ -3178,6 +3180,7 @@ def test_search_organizations_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.search_organizations(**mock_args) @@ -3369,6 +3372,7 @@ def test_get_iam_policy_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_iam_policy(request) @@ -3412,6 +3416,7 @@ def test_get_iam_policy_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_iam_policy(**mock_args) @@ -3541,6 +3546,7 @@ def test_set_iam_policy_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.set_iam_policy(request) @@ -3592,6 +3598,7 @@ def test_set_iam_policy_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.set_iam_policy(**mock_args) @@ -3729,6 +3736,7 @@ def test_test_iam_permissions_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.test_iam_permissions(request) @@ -3781,6 +3789,7 @@ def test_test_iam_permissions_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.test_iam_permissions(**mock_args) @@ -4212,6 +4221,7 @@ def test_get_organization_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_organization(request) @@ -4251,6 +4261,7 @@ def test_get_organization_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_organization(request) # Establish that the response is the type that we expect. @@ -4294,6 +4305,7 @@ def test_get_organization_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = organizations.Organization.to_json(organizations.Organization()) req.return_value.content = return_value @@ -4338,6 +4350,7 @@ def test_search_organizations_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.search_organizations(request) @@ -4373,6 +4386,7 @@ def test_search_organizations_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.search_organizations(request) # Establish that the response is the type that we expect. @@ -4413,6 +4427,7 @@ def test_search_organizations_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = organizations.SearchOrganizationsResponse.to_json( organizations.SearchOrganizationsResponse() ) @@ -4459,6 +4474,7 @@ def test_get_iam_policy_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_iam_policy(request) @@ -4492,6 +4508,7 @@ def test_get_iam_policy_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_iam_policy(request) # Establish that the response is the type that we expect. @@ -4531,6 +4548,7 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(policy_pb2.Policy()) req.return_value.content = return_value @@ -4575,6 +4593,7 @@ def test_set_iam_policy_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.set_iam_policy(request) @@ -4608,6 +4627,7 @@ def test_set_iam_policy_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.set_iam_policy(request) # Establish that the response is the type that we expect. @@ -4647,6 +4667,7 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(policy_pb2.Policy()) req.return_value.content = return_value @@ -4691,6 +4712,7 @@ def test_test_iam_permissions_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.test_iam_permissions(request) @@ -4723,6 +4745,7 @@ def test_test_iam_permissions_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.test_iam_permissions(request) # Establish that the response is the type that we expect. @@ -4761,6 +4784,7 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson( iam_policy_pb2.TestIamPermissionsResponse() ) @@ -4807,6 +4831,7 @@ def test_get_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_operation(request) @@ -4837,6 +4862,7 @@ def test_get_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_operation(request) diff --git a/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_projects.py b/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_projects.py index dd9b17dda71a..ce0a5344f899 100644 --- a/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_projects.py +++ b/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_projects.py @@ -5014,6 +5014,7 @@ def test_get_project_rest_required_fields(request_type=projects.GetProjectReques response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_project(request) @@ -5059,6 +5060,7 @@ def test_get_project_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_project(**mock_args) @@ -5198,6 +5200,7 @@ def test_list_projects_rest_required_fields(request_type=projects.ListProjectsRe response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_projects(request) @@ -5259,6 +5262,7 @@ def test_list_projects_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_projects(**mock_args) @@ -5411,6 +5415,7 @@ def test_search_projects_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.search_projects(**mock_args) @@ -5598,6 +5603,7 @@ def test_create_project_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_project(request) @@ -5641,6 +5647,7 @@ def test_create_project_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_project(**mock_args) @@ -5769,6 +5776,7 @@ def test_update_project_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_project(request) @@ -5813,6 +5821,7 @@ def test_update_project_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_project(**mock_args) @@ -5947,6 +5956,7 @@ def test_move_project_rest_required_fields(request_type=projects.MoveProjectRequ response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.move_project(request) @@ -5999,6 +6009,7 @@ def test_move_project_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.move_project(**mock_args) @@ -6130,6 +6141,7 @@ def test_delete_project_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_project(request) @@ -6173,6 +6185,7 @@ def test_delete_project_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_project(**mock_args) @@ -6306,6 +6319,7 @@ def test_undelete_project_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.undelete_project(request) @@ -6349,6 +6363,7 @@ def test_undelete_project_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.undelete_project(**mock_args) @@ -6477,6 +6492,7 @@ def test_get_iam_policy_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_iam_policy(request) @@ -6520,6 +6536,7 @@ def test_get_iam_policy_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_iam_policy(**mock_args) @@ -6648,6 +6665,7 @@ def test_set_iam_policy_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.set_iam_policy(request) @@ -6699,6 +6717,7 @@ def test_set_iam_policy_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.set_iam_policy(**mock_args) @@ -6835,6 +6854,7 @@ def test_test_iam_permissions_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.test_iam_permissions(request) @@ -6887,6 +6907,7 @@ def test_test_iam_permissions_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.test_iam_permissions(**mock_args) @@ -7591,6 +7612,7 @@ def test_get_project_rest_bad_request(request_type=projects.GetProjectRequest): response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_project(request) @@ -7631,6 +7653,7 @@ def test_get_project_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_project(request) # Establish that the response is the type that we expect. @@ -7672,6 +7695,7 @@ def test_get_project_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = projects.Project.to_json(projects.Project()) req.return_value.content = return_value @@ -7714,6 +7738,7 @@ def test_list_projects_rest_bad_request(request_type=projects.ListProjectsReques response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_projects(request) @@ -7749,6 +7774,7 @@ def test_list_projects_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_projects(request) # Establish that the response is the type that we expect. @@ -7785,6 +7811,7 @@ def test_list_projects_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = projects.ListProjectsResponse.to_json( projects.ListProjectsResponse() ) @@ -7829,6 +7856,7 @@ def test_search_projects_rest_bad_request(request_type=projects.SearchProjectsRe response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.search_projects(request) @@ -7864,6 +7892,7 @@ def test_search_projects_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.search_projects(request) # Establish that the response is the type that we expect. @@ -7900,6 +7929,7 @@ def test_search_projects_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = projects.SearchProjectsResponse.to_json( projects.SearchProjectsResponse() ) @@ -7944,6 +7974,7 @@ def test_create_project_rest_bad_request(request_type=projects.CreateProjectRequ response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_project(request) @@ -8053,6 +8084,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_project(request) # Establish that the response is the type that we expect. @@ -8090,6 +8122,7 @@ def test_create_project_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -8132,6 +8165,7 @@ def test_update_project_rest_bad_request(request_type=projects.UpdateProjectRequ response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_project(request) @@ -8241,6 +8275,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_project(request) # Establish that the response is the type that we expect. @@ -8278,6 +8313,7 @@ def test_update_project_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -8320,6 +8356,7 @@ def test_move_project_rest_bad_request(request_type=projects.MoveProjectRequest) response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.move_project(request) @@ -8350,6 +8387,7 @@ def test_move_project_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.move_project(request) # Establish that the response is the type that we expect. @@ -8387,6 +8425,7 @@ def test_move_project_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -8429,6 +8468,7 @@ def test_delete_project_rest_bad_request(request_type=projects.DeleteProjectRequ response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_project(request) @@ -8459,6 +8499,7 @@ def test_delete_project_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_project(request) # Establish that the response is the type that we expect. @@ -8496,6 +8537,7 @@ def test_delete_project_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -8540,6 +8582,7 @@ def test_undelete_project_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.undelete_project(request) @@ -8570,6 +8613,7 @@ def test_undelete_project_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.undelete_project(request) # Establish that the response is the type that we expect. @@ -8609,6 +8653,7 @@ def test_undelete_project_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -8653,6 +8698,7 @@ def test_get_iam_policy_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_iam_policy(request) @@ -8686,6 +8732,7 @@ def test_get_iam_policy_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_iam_policy(request) # Establish that the response is the type that we expect. @@ -8723,6 +8770,7 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(policy_pb2.Policy()) req.return_value.content = return_value @@ -8767,6 +8815,7 @@ def test_set_iam_policy_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.set_iam_policy(request) @@ -8800,6 +8849,7 @@ def test_set_iam_policy_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.set_iam_policy(request) # Establish that the response is the type that we expect. @@ -8837,6 +8887,7 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(policy_pb2.Policy()) req.return_value.content = return_value @@ -8881,6 +8932,7 @@ def test_test_iam_permissions_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.test_iam_permissions(request) @@ -8913,6 +8965,7 @@ def test_test_iam_permissions_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.test_iam_permissions(request) # Establish that the response is the type that we expect. @@ -8949,6 +9002,7 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson( iam_policy_pb2.TestIamPermissionsResponse() ) @@ -8995,6 +9049,7 @@ def test_get_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_operation(request) @@ -9025,6 +9080,7 @@ def test_get_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_operation(request) diff --git a/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_tag_bindings.py b/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_tag_bindings.py index 567ccae5563b..ebdb04a2be99 100644 --- a/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_tag_bindings.py +++ b/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_tag_bindings.py @@ -2725,6 +2725,7 @@ def test_list_tag_bindings_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_tag_bindings(request) @@ -2785,6 +2786,7 @@ def test_list_tag_bindings_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_tag_bindings(**mock_args) @@ -2980,6 +2982,7 @@ def test_create_tag_binding_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_tag_binding(request) @@ -3023,6 +3026,7 @@ def test_create_tag_binding_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_tag_binding(**mock_args) @@ -3157,6 +3161,7 @@ def test_delete_tag_binding_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_tag_binding(request) @@ -3200,6 +3205,7 @@ def test_delete_tag_binding_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_tag_binding(**mock_args) @@ -3344,6 +3350,7 @@ def test_list_effective_tags_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_effective_tags(request) @@ -3404,6 +3411,7 @@ def test_list_effective_tags_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_effective_tags(**mock_args) @@ -3846,6 +3854,7 @@ def test_list_tag_bindings_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_tag_bindings(request) @@ -3881,6 +3890,7 @@ def test_list_tag_bindings_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_tag_bindings(request) # Establish that the response is the type that we expect. @@ -3921,6 +3931,7 @@ def test_list_tag_bindings_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = tag_bindings.ListTagBindingsResponse.to_json( tag_bindings.ListTagBindingsResponse() ) @@ -3967,6 +3978,7 @@ def test_create_tag_binding_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_tag_binding(request) @@ -4070,6 +4082,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_tag_binding(request) # Establish that the response is the type that we expect. @@ -4111,6 +4124,7 @@ def test_create_tag_binding_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -4155,6 +4169,7 @@ def test_delete_tag_binding_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_tag_binding(request) @@ -4185,6 +4200,7 @@ def test_delete_tag_binding_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_tag_binding(request) # Establish that the response is the type that we expect. @@ -4226,6 +4242,7 @@ def test_delete_tag_binding_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -4270,6 +4287,7 @@ def test_list_effective_tags_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_effective_tags(request) @@ -4305,6 +4323,7 @@ def test_list_effective_tags_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_effective_tags(request) # Establish that the response is the type that we expect. @@ -4345,6 +4364,7 @@ def test_list_effective_tags_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = tag_bindings.ListEffectiveTagsResponse.to_json( tag_bindings.ListEffectiveTagsResponse() ) @@ -4391,6 +4411,7 @@ def test_get_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_operation(request) @@ -4421,6 +4442,7 @@ def test_get_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_operation(request) diff --git a/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_tag_holds.py b/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_tag_holds.py index 2456c0e8e62e..fb079f4babac 100644 --- a/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_tag_holds.py +++ b/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_tag_holds.py @@ -2310,6 +2310,7 @@ def test_create_tag_hold_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_tag_hold(request) @@ -2362,6 +2363,7 @@ def test_create_tag_hold_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_tag_hold(**mock_args) @@ -2495,6 +2497,7 @@ def test_delete_tag_hold_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_tag_hold(request) @@ -2538,6 +2541,7 @@ def test_delete_tag_hold_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_tag_hold(**mock_args) @@ -2675,6 +2679,7 @@ def test_list_tag_holds_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_tag_holds(request) @@ -2729,6 +2734,7 @@ def test_list_tag_holds_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_tag_holds(**mock_args) @@ -3103,6 +3109,7 @@ def test_create_tag_hold_rest_bad_request(request_type=tag_holds.CreateTagHoldRe response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_tag_hold(request) @@ -3207,6 +3214,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_tag_hold(request) # Establish that the response is the type that we expect. @@ -3244,6 +3252,7 @@ def test_create_tag_hold_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -3286,6 +3295,7 @@ def test_delete_tag_hold_rest_bad_request(request_type=tag_holds.DeleteTagHoldRe response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_tag_hold(request) @@ -3316,6 +3326,7 @@ def test_delete_tag_hold_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_tag_hold(request) # Establish that the response is the type that we expect. @@ -3353,6 +3364,7 @@ def test_delete_tag_hold_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -3395,6 +3407,7 @@ def test_list_tag_holds_rest_bad_request(request_type=tag_holds.ListTagHoldsRequ response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_tag_holds(request) @@ -3430,6 +3443,7 @@ def test_list_tag_holds_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_tag_holds(request) # Establish that the response is the type that we expect. @@ -3466,6 +3480,7 @@ def test_list_tag_holds_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = tag_holds.ListTagHoldsResponse.to_json( tag_holds.ListTagHoldsResponse() ) @@ -3512,6 +3527,7 @@ def test_get_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_operation(request) @@ -3542,6 +3558,7 @@ def test_get_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_operation(request) diff --git a/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_tag_keys.py b/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_tag_keys.py index ca914a37d2f7..a80ef3dd50af 100644 --- a/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_tag_keys.py +++ b/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_tag_keys.py @@ -4198,6 +4198,7 @@ def test_list_tag_keys_rest_required_fields(request_type=tag_keys.ListTagKeysReq response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_tag_keys(request) @@ -4258,6 +4259,7 @@ def test_list_tag_keys_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_tag_keys(**mock_args) @@ -4444,6 +4446,7 @@ def test_get_tag_key_rest_required_fields(request_type=tag_keys.GetTagKeyRequest response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_tag_key(request) @@ -4489,6 +4492,7 @@ def test_get_tag_key_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_tag_key(**mock_args) @@ -4628,6 +4632,7 @@ def test_get_namespaced_tag_key_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_namespaced_tag_key(request) @@ -4679,6 +4684,7 @@ def test_get_namespaced_tag_key_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_namespaced_tag_key(**mock_args) @@ -4805,6 +4811,7 @@ def test_create_tag_key_rest_required_fields(request_type=tag_keys.CreateTagKeyR response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_tag_key(request) @@ -4848,6 +4855,7 @@ def test_create_tag_key_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_tag_key(**mock_args) @@ -4977,6 +4985,7 @@ def test_update_tag_key_rest_required_fields(request_type=tag_keys.UpdateTagKeyR response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_tag_key(request) @@ -5029,6 +5038,7 @@ def test_update_tag_key_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_tag_key(**mock_args) @@ -5165,6 +5175,7 @@ def test_delete_tag_key_rest_required_fields(request_type=tag_keys.DeleteTagKeyR response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_tag_key(request) @@ -5216,6 +5227,7 @@ def test_delete_tag_key_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_tag_key(**mock_args) @@ -5344,6 +5356,7 @@ def test_get_iam_policy_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_iam_policy(request) @@ -5387,6 +5400,7 @@ def test_get_iam_policy_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_iam_policy(**mock_args) @@ -5515,6 +5529,7 @@ def test_set_iam_policy_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.set_iam_policy(request) @@ -5566,6 +5581,7 @@ def test_set_iam_policy_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.set_iam_policy(**mock_args) @@ -5702,6 +5718,7 @@ def test_test_iam_permissions_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.test_iam_permissions(request) @@ -5754,6 +5771,7 @@ def test_test_iam_permissions_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.test_iam_permissions(**mock_args) @@ -6377,6 +6395,7 @@ def test_list_tag_keys_rest_bad_request(request_type=tag_keys.ListTagKeysRequest response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_tag_keys(request) @@ -6412,6 +6431,7 @@ def test_list_tag_keys_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_tag_keys(request) # Establish that the response is the type that we expect. @@ -6448,6 +6468,7 @@ def test_list_tag_keys_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = tag_keys.ListTagKeysResponse.to_json( tag_keys.ListTagKeysResponse() ) @@ -6492,6 +6513,7 @@ def test_get_tag_key_rest_bad_request(request_type=tag_keys.GetTagKeyRequest): response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_tag_key(request) @@ -6533,6 +6555,7 @@ def test_get_tag_key_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_tag_key(request) # Establish that the response is the type that we expect. @@ -6575,6 +6598,7 @@ def test_get_tag_key_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = tag_keys.TagKey.to_json(tag_keys.TagKey()) req.return_value.content = return_value @@ -6619,6 +6643,7 @@ def test_get_namespaced_tag_key_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_namespaced_tag_key(request) @@ -6660,6 +6685,7 @@ def test_get_namespaced_tag_key_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_namespaced_tag_key(request) # Establish that the response is the type that we expect. @@ -6704,6 +6730,7 @@ def test_get_namespaced_tag_key_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = tag_keys.TagKey.to_json(tag_keys.TagKey()) req.return_value.content = return_value @@ -6746,6 +6773,7 @@ def test_create_tag_key_rest_bad_request(request_type=tag_keys.CreateTagKeyReque response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_tag_key(request) @@ -6855,6 +6883,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_tag_key(request) # Establish that the response is the type that we expect. @@ -6892,6 +6921,7 @@ def test_create_tag_key_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -6934,6 +6964,7 @@ def test_update_tag_key_rest_bad_request(request_type=tag_keys.UpdateTagKeyReque response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_tag_key(request) @@ -7043,6 +7074,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_tag_key(request) # Establish that the response is the type that we expect. @@ -7080,6 +7112,7 @@ def test_update_tag_key_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -7122,6 +7155,7 @@ def test_delete_tag_key_rest_bad_request(request_type=tag_keys.DeleteTagKeyReque response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_tag_key(request) @@ -7152,6 +7186,7 @@ def test_delete_tag_key_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_tag_key(request) # Establish that the response is the type that we expect. @@ -7189,6 +7224,7 @@ def test_delete_tag_key_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -7233,6 +7269,7 @@ def test_get_iam_policy_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_iam_policy(request) @@ -7266,6 +7303,7 @@ def test_get_iam_policy_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_iam_policy(request) # Establish that the response is the type that we expect. @@ -7303,6 +7341,7 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(policy_pb2.Policy()) req.return_value.content = return_value @@ -7347,6 +7386,7 @@ def test_set_iam_policy_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.set_iam_policy(request) @@ -7380,6 +7420,7 @@ def test_set_iam_policy_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.set_iam_policy(request) # Establish that the response is the type that we expect. @@ -7417,6 +7458,7 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(policy_pb2.Policy()) req.return_value.content = return_value @@ -7461,6 +7503,7 @@ def test_test_iam_permissions_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.test_iam_permissions(request) @@ -7493,6 +7536,7 @@ def test_test_iam_permissions_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.test_iam_permissions(request) # Establish that the response is the type that we expect. @@ -7529,6 +7573,7 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson( iam_policy_pb2.TestIamPermissionsResponse() ) @@ -7575,6 +7620,7 @@ def test_get_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_operation(request) @@ -7605,6 +7651,7 @@ def test_get_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_operation(request) diff --git a/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_tag_values.py b/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_tag_values.py index 25f14069de0b..bc47dde37a98 100644 --- a/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_tag_values.py +++ b/packages/google-cloud-resource-manager/tests/unit/gapic/resourcemanager_v3/test_tag_values.py @@ -4221,6 +4221,7 @@ def test_list_tag_values_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_tag_values(request) @@ -4281,6 +4282,7 @@ def test_list_tag_values_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_tag_values(**mock_args) @@ -4469,6 +4471,7 @@ def test_get_tag_value_rest_required_fields(request_type=tag_values.GetTagValueR response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_tag_value(request) @@ -4514,6 +4517,7 @@ def test_get_tag_value_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_tag_value(**mock_args) @@ -4653,6 +4657,7 @@ def test_get_namespaced_tag_value_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_namespaced_tag_value(request) @@ -4704,6 +4709,7 @@ def test_get_namespaced_tag_value_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_namespaced_tag_value(**mock_args) @@ -4834,6 +4840,7 @@ def test_create_tag_value_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_tag_value(request) @@ -4877,6 +4884,7 @@ def test_create_tag_value_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_tag_value(**mock_args) @@ -5012,6 +5020,7 @@ def test_update_tag_value_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_tag_value(request) @@ -5064,6 +5073,7 @@ def test_update_tag_value_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_tag_value(**mock_args) @@ -5204,6 +5214,7 @@ def test_delete_tag_value_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_tag_value(request) @@ -5255,6 +5266,7 @@ def test_delete_tag_value_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_tag_value(**mock_args) @@ -5383,6 +5395,7 @@ def test_get_iam_policy_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_iam_policy(request) @@ -5426,6 +5439,7 @@ def test_get_iam_policy_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_iam_policy(**mock_args) @@ -5555,6 +5569,7 @@ def test_set_iam_policy_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.set_iam_policy(request) @@ -5606,6 +5621,7 @@ def test_set_iam_policy_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.set_iam_policy(**mock_args) @@ -5743,6 +5759,7 @@ def test_test_iam_permissions_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.test_iam_permissions(request) @@ -5795,6 +5812,7 @@ def test_test_iam_permissions_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.test_iam_permissions(**mock_args) @@ -6416,6 +6434,7 @@ def test_list_tag_values_rest_bad_request(request_type=tag_values.ListTagValuesR response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_tag_values(request) @@ -6451,6 +6470,7 @@ def test_list_tag_values_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_tag_values(request) # Establish that the response is the type that we expect. @@ -6489,6 +6509,7 @@ def test_list_tag_values_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = tag_values.ListTagValuesResponse.to_json( tag_values.ListTagValuesResponse() ) @@ -6533,6 +6554,7 @@ def test_get_tag_value_rest_bad_request(request_type=tag_values.GetTagValueReque response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_tag_value(request) @@ -6573,6 +6595,7 @@ def test_get_tag_value_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_tag_value(request) # Establish that the response is the type that we expect. @@ -6614,6 +6637,7 @@ def test_get_tag_value_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = tag_values.TagValue.to_json(tag_values.TagValue()) req.return_value.content = return_value @@ -6658,6 +6682,7 @@ def test_get_namespaced_tag_value_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_namespaced_tag_value(request) @@ -6698,6 +6723,7 @@ def test_get_namespaced_tag_value_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_namespaced_tag_value(request) # Establish that the response is the type that we expect. @@ -6741,6 +6767,7 @@ def test_get_namespaced_tag_value_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = tag_values.TagValue.to_json(tag_values.TagValue()) req.return_value.content = return_value @@ -6785,6 +6812,7 @@ def test_create_tag_value_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.create_tag_value(request) @@ -6892,6 +6920,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.create_tag_value(request) # Establish that the response is the type that we expect. @@ -6931,6 +6960,7 @@ def test_create_tag_value_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -6975,6 +7005,7 @@ def test_update_tag_value_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_tag_value(request) @@ -7082,6 +7113,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_tag_value(request) # Establish that the response is the type that we expect. @@ -7121,6 +7153,7 @@ def test_update_tag_value_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -7165,6 +7198,7 @@ def test_delete_tag_value_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.delete_tag_value(request) @@ -7195,6 +7229,7 @@ def test_delete_tag_value_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_tag_value(request) # Establish that the response is the type that we expect. @@ -7234,6 +7269,7 @@ def test_delete_tag_value_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(operations_pb2.Operation()) req.return_value.content = return_value @@ -7278,6 +7314,7 @@ def test_get_iam_policy_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_iam_policy(request) @@ -7311,6 +7348,7 @@ def test_get_iam_policy_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_iam_policy(request) # Establish that the response is the type that we expect. @@ -7348,6 +7386,7 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(policy_pb2.Policy()) req.return_value.content = return_value @@ -7392,6 +7431,7 @@ def test_set_iam_policy_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.set_iam_policy(request) @@ -7425,6 +7465,7 @@ def test_set_iam_policy_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.set_iam_policy(request) # Establish that the response is the type that we expect. @@ -7462,6 +7503,7 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson(policy_pb2.Policy()) req.return_value.content = return_value @@ -7506,6 +7548,7 @@ def test_test_iam_permissions_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.test_iam_permissions(request) @@ -7538,6 +7581,7 @@ def test_test_iam_permissions_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.test_iam_permissions(request) # Establish that the response is the type that we expect. @@ -7574,6 +7618,7 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = json_format.MessageToJson( iam_policy_pb2.TestIamPermissionsResponse() ) @@ -7620,6 +7665,7 @@ def test_get_operation_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_operation(request) @@ -7650,6 +7696,7 @@ def test_get_operation_rest(request_type): response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_operation(request) diff --git a/packages/google-cloud-resource-settings/google/cloud/resourcesettings/gapic_version.py b/packages/google-cloud-resource-settings/google/cloud/resourcesettings/gapic_version.py index f1d827b5c728..558c8aab67c5 100644 --- a/packages/google-cloud-resource-settings/google/cloud/resourcesettings/gapic_version.py +++ b/packages/google-cloud-resource-settings/google/cloud/resourcesettings/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.10.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/gapic_version.py b/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/gapic_version.py index f1d827b5c728..558c8aab67c5 100644 --- a/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/gapic_version.py +++ b/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.10.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/async_client.py b/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/async_client.py index 9d55d4cf1b46..5f2680c48a8e 100644 --- a/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/async_client.py +++ b/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/async_client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import re from typing import ( Callable, @@ -49,6 +50,15 @@ from .transports.base import DEFAULT_CLIENT_INFO, ResourceSettingsServiceTransport from .transports.grpc_asyncio import ResourceSettingsServiceGrpcAsyncIOTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + class ResourceSettingsServiceAsyncClient: """An interface to interact with resource settings and setting values @@ -281,6 +291,28 @@ def __init__( client_info=client_info, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.resourcesettings_v1.ResourceSettingsServiceAsyncClient`.", + extra={ + "serviceName": "google.cloud.resourcesettings.v1.ResourceSettingsService", + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { + "serviceName": "google.cloud.resourcesettings.v1.ResourceSettingsService", + "credentialsType": None, + }, + ) + async def list_settings( self, request: Optional[Union[resource_settings.ListSettingsRequest, dict]] = None, @@ -288,7 +320,7 @@ async def list_settings( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListSettingsAsyncPager: r"""Lists all the settings that are available on the Cloud resource ``parent``. @@ -338,8 +370,10 @@ async def sample_list_settings(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcesettings_v1.services.resource_settings_service.pagers.ListSettingsAsyncPager: @@ -414,7 +448,7 @@ async def get_setting( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resource_settings.Setting: r"""Gets a setting. @@ -461,8 +495,10 @@ async def sample_get_setting(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcesettings_v1.types.Setting: @@ -520,7 +556,7 @@ async def update_setting( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resource_settings.Setting: r"""Updates a setting. @@ -570,8 +606,10 @@ async def sample_update_setting(): retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcesettings_v1.types.Setting: diff --git a/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/client.py b/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/client.py index 3987d9d7f3ce..58b17256d332 100644 --- a/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/client.py +++ b/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import ( @@ -48,6 +49,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.cloud.resourcesettings_v1.services.resource_settings_service import pagers from google.cloud.resourcesettings_v1.types import resource_settings @@ -600,6 +610,10 @@ def __init__( # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError( @@ -666,6 +680,29 @@ def __init__( api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.resourcesettings_v1.ResourceSettingsServiceClient`.", + extra={ + "serviceName": "google.cloud.resourcesettings.v1.ResourceSettingsService", + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { + "serviceName": "google.cloud.resourcesettings.v1.ResourceSettingsService", + "credentialsType": None, + }, + ) + def list_settings( self, request: Optional[Union[resource_settings.ListSettingsRequest, dict]] = None, @@ -673,7 +710,7 @@ def list_settings( parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> pagers.ListSettingsPager: r"""Lists all the settings that are available on the Cloud resource ``parent``. @@ -723,8 +760,10 @@ def sample_list_settings(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcesettings_v1.services.resource_settings_service.pagers.ListSettingsPager: @@ -796,7 +835,7 @@ def get_setting( name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resource_settings.Setting: r"""Gets a setting. @@ -843,8 +882,10 @@ def sample_get_setting(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcesettings_v1.types.Setting: @@ -899,7 +940,7 @@ def update_setting( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resource_settings.Setting: r"""Updates a setting. @@ -949,8 +990,10 @@ def sample_update_setting(): retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: google.cloud.resourcesettings_v1.types.Setting: diff --git a/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/pagers.py b/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/pagers.py index 1d7bfb5de289..8dd526182e06 100644 --- a/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/pagers.py +++ b/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiate the pager. @@ -81,8 +81,10 @@ def __init__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = resource_settings.ListSettingsRequest(request) @@ -141,7 +143,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () ): """Instantiates the pager. @@ -155,8 +157,10 @@ def __init__( retry (google.api_core.retry.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. """ self._method = method self._request = resource_settings.ListSettingsRequest(request) diff --git a/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/transports/grpc.py b/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/transports/grpc.py index e0c02320a362..a484c282e3bf 100644 --- a/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/transports/grpc.py +++ b/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/transports/grpc.py @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import logging as std_logging +import pickle from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -20,12 +23,90 @@ import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore +import proto # type: ignore from google.cloud.resourcesettings_v1.types import resource_settings from .base import DEFAULT_CLIENT_INFO, ResourceSettingsServiceTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.resourcesettings.v1.ResourceSettingsService", + "rpcName": client_call_details.method, + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.resourcesettings.v1.ResourceSettingsService", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class ResourceSettingsServiceGrpcTransport(ResourceSettingsServiceTransport): """gRPC backend transport for ResourceSettingsService. @@ -195,7 +276,12 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) + + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod @@ -272,7 +358,7 @@ def list_settings( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_settings" not in self._stubs: - self._stubs["list_settings"] = self.grpc_channel.unary_unary( + self._stubs["list_settings"] = self._logged_channel.unary_unary( "/google.cloud.resourcesettings.v1.ResourceSettingsService/ListSettings", request_serializer=resource_settings.ListSettingsRequest.serialize, response_deserializer=resource_settings.ListSettingsResponse.deserialize, @@ -301,7 +387,7 @@ def get_setting( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_setting" not in self._stubs: - self._stubs["get_setting"] = self.grpc_channel.unary_unary( + self._stubs["get_setting"] = self._logged_channel.unary_unary( "/google.cloud.resourcesettings.v1.ResourceSettingsService/GetSetting", request_serializer=resource_settings.GetSettingRequest.serialize, response_deserializer=resource_settings.Setting.deserialize, @@ -342,7 +428,7 @@ def update_setting( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_setting" not in self._stubs: - self._stubs["update_setting"] = self.grpc_channel.unary_unary( + self._stubs["update_setting"] = self._logged_channel.unary_unary( "/google.cloud.resourcesettings.v1.ResourceSettingsService/UpdateSetting", request_serializer=resource_settings.UpdateSettingRequest.serialize, response_deserializer=resource_settings.Setting.deserialize, @@ -350,7 +436,7 @@ def update_setting( return self._stubs["update_setting"] def close(self): - self.grpc_channel.close() + self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/transports/grpc_asyncio.py b/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/transports/grpc_asyncio.py index ac5e0cc0276c..f42c7b43da18 100644 --- a/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/transports/grpc_asyncio.py @@ -14,6 +14,9 @@ # limitations under the License. # import inspect +import json +import logging as std_logging +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings @@ -22,14 +25,93 @@ from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.cloud.resourcesettings_v1.types import resource_settings from .base import DEFAULT_CLIENT_INFO, ResourceSettingsServiceTransport from .grpc import ResourceSettingsServiceGrpcTransport +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra={ + "serviceName": "google.cloud.resourcesettings.v1.ResourceSettingsService", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra={ + "serviceName": "google.cloud.resourcesettings.v1.ResourceSettingsService", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + class ResourceSettingsServiceGrpcAsyncIOTransport(ResourceSettingsServiceTransport): """gRPC AsyncIO backend transport for ResourceSettingsService. @@ -242,10 +324,13 @@ def __init__( ], ) - # Wrap messages. This must be done after self._grpc_channel exists + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel self._wrap_with_kind = ( "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters ) + # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @property @@ -281,7 +366,7 @@ def list_settings( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "list_settings" not in self._stubs: - self._stubs["list_settings"] = self.grpc_channel.unary_unary( + self._stubs["list_settings"] = self._logged_channel.unary_unary( "/google.cloud.resourcesettings.v1.ResourceSettingsService/ListSettings", request_serializer=resource_settings.ListSettingsRequest.serialize, response_deserializer=resource_settings.ListSettingsResponse.deserialize, @@ -312,7 +397,7 @@ def get_setting( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "get_setting" not in self._stubs: - self._stubs["get_setting"] = self.grpc_channel.unary_unary( + self._stubs["get_setting"] = self._logged_channel.unary_unary( "/google.cloud.resourcesettings.v1.ResourceSettingsService/GetSetting", request_serializer=resource_settings.GetSettingRequest.serialize, response_deserializer=resource_settings.Setting.deserialize, @@ -355,7 +440,7 @@ def update_setting( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "update_setting" not in self._stubs: - self._stubs["update_setting"] = self.grpc_channel.unary_unary( + self._stubs["update_setting"] = self._logged_channel.unary_unary( "/google.cloud.resourcesettings.v1.ResourceSettingsService/UpdateSetting", request_serializer=resource_settings.UpdateSettingRequest.serialize, response_deserializer=resource_settings.Setting.deserialize, @@ -418,7 +503,7 @@ def _wrap_method(self, func, *args, **kwargs): return gapic_v1.method_async.wrap_method(func, *args, **kwargs) def close(self): - return self.grpc_channel.close() + return self._logged_channel.close() @property def kind(self) -> str: diff --git a/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/transports/rest.py b/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/transports/rest.py index f5faab470b13..2d86da54e90c 100644 --- a/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/transports/rest.py +++ b/packages/google-cloud-resource-settings/google/cloud/resourcesettings_v1/services/resource_settings_service/transports/rest.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings @@ -37,6 +37,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, @@ -93,8 +101,10 @@ def post_update_setting(self, response): def pre_get_setting( self, request: resource_settings.GetSettingRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[resource_settings.GetSettingRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + resource_settings.GetSettingRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for get_setting Override in a subclass to manipulate the request or metadata @@ -116,8 +126,10 @@ def post_get_setting( def pre_list_settings( self, request: resource_settings.ListSettingsRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[resource_settings.ListSettingsRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + resource_settings.ListSettingsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for list_settings Override in a subclass to manipulate the request or metadata @@ -139,8 +151,10 @@ def post_list_settings( def pre_update_setting( self, request: resource_settings.UpdateSettingRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[resource_settings.UpdateSettingRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + resource_settings.UpdateSettingRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for update_setting Override in a subclass to manipulate the request or metadata @@ -297,7 +311,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resource_settings.Setting: r"""Call the get setting method over HTTP. @@ -307,8 +321,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resource_settings.Setting: @@ -318,6 +334,7 @@ def __call__( http_options = ( _BaseResourceSettingsServiceRestTransport._BaseGetSetting._get_http_options() ) + request, metadata = self._interceptor.pre_get_setting(request, metadata) transcoded_request = _BaseResourceSettingsServiceRestTransport._BaseGetSetting._get_transcoded_request( http_options, request @@ -328,6 +345,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcesettings_v1.ResourceSettingsServiceClient.GetSetting", + extra={ + "serviceName": "google.cloud.resourcesettings.v1.ResourceSettingsService", + "rpcName": "GetSetting", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ResourceSettingsServiceRestTransport._GetSetting._get_response( self._host, @@ -348,7 +392,29 @@ def __call__( pb_resp = resource_settings.Setting.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_setting(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resource_settings.Setting.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcesettings_v1.ResourceSettingsServiceClient.get_setting", + extra={ + "serviceName": "google.cloud.resourcesettings.v1.ResourceSettingsService", + "rpcName": "GetSetting", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _ListSettings( @@ -386,7 +452,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resource_settings.ListSettingsResponse: r"""Call the list settings method over HTTP. @@ -396,8 +462,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resource_settings.ListSettingsResponse: @@ -407,6 +475,7 @@ def __call__( http_options = ( _BaseResourceSettingsServiceRestTransport._BaseListSettings._get_http_options() ) + request, metadata = self._interceptor.pre_list_settings(request, metadata) transcoded_request = _BaseResourceSettingsServiceRestTransport._BaseListSettings._get_transcoded_request( http_options, request @@ -417,6 +486,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcesettings_v1.ResourceSettingsServiceClient.ListSettings", + extra={ + "serviceName": "google.cloud.resourcesettings.v1.ResourceSettingsService", + "rpcName": "ListSettings", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ResourceSettingsServiceRestTransport._ListSettings._get_response( self._host, @@ -437,7 +533,31 @@ def __call__( pb_resp = resource_settings.ListSettingsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_settings(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resource_settings.ListSettingsResponse.to_json( + response + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcesettings_v1.ResourceSettingsServiceClient.list_settings", + extra={ + "serviceName": "google.cloud.resourcesettings.v1.ResourceSettingsService", + "rpcName": "ListSettings", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp class _UpdateSetting( @@ -476,7 +596,7 @@ def __call__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> resource_settings.Setting: r"""Call the update setting method over HTTP. @@ -486,8 +606,10 @@ def __call__( retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.resource_settings.Setting: @@ -497,6 +619,7 @@ def __call__( http_options = ( _BaseResourceSettingsServiceRestTransport._BaseUpdateSetting._get_http_options() ) + request, metadata = self._interceptor.pre_update_setting(request, metadata) transcoded_request = _BaseResourceSettingsServiceRestTransport._BaseUpdateSetting._get_transcoded_request( http_options, request @@ -511,6 +634,33 @@ def __call__( transcoded_request ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.resourcesettings_v1.ResourceSettingsServiceClient.UpdateSetting", + extra={ + "serviceName": "google.cloud.resourcesettings.v1.ResourceSettingsService", + "rpcName": "UpdateSetting", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + # Send the request response = ( ResourceSettingsServiceRestTransport._UpdateSetting._get_response( @@ -534,7 +684,29 @@ def __call__( pb_resp = resource_settings.Setting.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_setting(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = resource_settings.Setting.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.resourcesettings_v1.ResourceSettingsServiceClient.update_setting", + extra={ + "serviceName": "google.cloud.resourcesettings.v1.ResourceSettingsService", + "rpcName": "UpdateSetting", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property diff --git a/packages/google-cloud-resource-settings/samples/generated_samples/snippet_metadata_google.cloud.resourcesettings.v1.json b/packages/google-cloud-resource-settings/samples/generated_samples/snippet_metadata_google.cloud.resourcesettings.v1.json index 58660108368f..61a2b1d93fba 100644 --- a/packages/google-cloud-resource-settings/samples/generated_samples/snippet_metadata_google.cloud.resourcesettings.v1.json +++ b/packages/google-cloud-resource-settings/samples/generated_samples/snippet_metadata_google.cloud.resourcesettings.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-resource-settings", - "version": "1.10.1" + "version": "0.1.0" }, "snippets": [ { @@ -47,7 +47,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcesettings_v1.types.Setting", @@ -127,7 +127,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcesettings_v1.types.Setting", @@ -208,7 +208,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcesettings_v1.services.resource_settings_service.pagers.ListSettingsAsyncPager", @@ -288,7 +288,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcesettings_v1.services.resource_settings_service.pagers.ListSettingsPager", @@ -365,7 +365,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcesettings_v1.types.Setting", @@ -441,7 +441,7 @@ }, { "name": "metadata", - "type": "Sequence[Tuple[str, str]" + "type": "Sequence[Tuple[str, Union[str, bytes]]]" } ], "resultType": "google.cloud.resourcesettings_v1.types.Setting", diff --git a/packages/google-cloud-resource-settings/tests/unit/gapic/resourcesettings_v1/test_resource_settings_service.py b/packages/google-cloud-resource-settings/tests/unit/gapic/resourcesettings_v1/test_resource_settings_service.py index 000034ea7c75..3b9ad3ebf0e9 100644 --- a/packages/google-cloud-resource-settings/tests/unit/gapic/resourcesettings_v1/test_resource_settings_service.py +++ b/packages/google-cloud-resource-settings/tests/unit/gapic/resourcesettings_v1/test_resource_settings_service.py @@ -2321,6 +2321,7 @@ def test_list_settings_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_settings(request) @@ -2375,6 +2376,7 @@ def test_list_settings_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_settings(**mock_args) @@ -2569,6 +2571,7 @@ def test_get_setting_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_setting(request) @@ -2614,6 +2617,7 @@ def test_get_setting_rest_flattened(): json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_setting(**mock_args) @@ -2739,6 +2743,7 @@ def test_update_setting_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_setting(request) @@ -3050,6 +3055,7 @@ def test_list_settings_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.list_settings(request) @@ -3085,6 +3091,7 @@ def test_list_settings_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_settings(request) # Establish that the response is the type that we expect. @@ -3125,6 +3132,7 @@ def test_list_settings_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resource_settings.ListSettingsResponse.to_json( resource_settings.ListSettingsResponse() ) @@ -3169,6 +3177,7 @@ def test_get_setting_rest_bad_request(request_type=resource_settings.GetSettingR response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.get_setting(request) @@ -3205,6 +3214,7 @@ def test_get_setting_rest_call_success(request_type): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_setting(request) # Establish that the response is the type that we expect. @@ -3246,6 +3256,7 @@ def test_get_setting_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resource_settings.Setting.to_json(resource_settings.Setting()) req.return_value.content = return_value @@ -3290,6 +3301,7 @@ def test_update_setting_rest_bad_request( response_value.status_code = 400 response_value.request = mock.Mock() req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} client.update_setting(request) @@ -3411,6 +3423,7 @@ def get_message_fields(field): json_return_value = json_format.MessageToJson(return_value) response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_setting(request) # Establish that the response is the type that we expect. @@ -3452,6 +3465,7 @@ def test_update_setting_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} return_value = resource_settings.Setting.to_json(resource_settings.Setting()) req.return_value.content = return_value