From 6d60f59f9cacf64f0e071ecabcbda89f9825035f Mon Sep 17 00:00:00 2001 From: Heba Alazzeh Date: Wed, 8 Jul 2026 02:36:49 +0000 Subject: [PATCH 01/13] ci: add import profiler check across monorepo --- .github/workflows/import-profiler.yml | 38 +++++++++++++++++++ .../gapic/templates/noxfile.py.j2 | 13 +++++++ 2 files changed, 51 insertions(+) create mode 100644 .github/workflows/import-profiler.yml diff --git a/.github/workflows/import-profiler.yml b/.github/workflows/import-profiler.yml new file mode 100644 index 000000000000..bf4825995a8f --- /dev/null +++ b/.github/workflows/import-profiler.yml @@ -0,0 +1,38 @@ +name: import-profiler + +on: + pull_request: + branches: + - main + - preview + # Trigger workflow on GitHub merge queue events + merge_group: + types: [checks_requested] + +permissions: + contents: read + +jobs: + import-profile: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + fetch-depth: 2 + - name: Setup Python + uses: actions/setup-python@v6 + with: + python-version: "3.15" + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run import profiler + env: + BUILD_TYPE: presubmit + TARGET_BRANCH: ${{ github.base_ref || github.event.merge_group.base_ref }} + TEST_TYPE: import_profile + PY_VERSION: "3.15" + run: | + ci/run_conditional_tests.sh diff --git a/packages/gapic-generator/gapic/templates/noxfile.py.j2 b/packages/gapic-generator/gapic/templates/noxfile.py.j2 index 8db595319396..ec3fe238b5b7 100644 --- a/packages/gapic-generator/gapic/templates/noxfile.py.j2 +++ b/packages/gapic-generator/gapic/templates/noxfile.py.j2 @@ -86,6 +86,7 @@ nox.options.sessions = [ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -641,4 +642,16 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + {% if api.naming.module_namespace %} + session.run("python", profiler_script, "--module", "{{ api.naming.module_namespace[0] }}", "--iterations", "10") + {% else %} + session.run("python", profiler_script, "--module", "{{ api.naming.versioned_module_name }}", "--iterations", "10") + {% endif %} {% endblock %} From da118aacf64621300674ea229d581b60dc0f9ffc Mon Sep 17 00:00:00 2001 From: Heba Alazzeh Date: Wed, 8 Jul 2026 02:43:28 +0000 Subject: [PATCH 02/13] ci: allow prerelease for python 3.15 in setup-python --- .github/workflows/import-profiler.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/import-profiler.yml b/.github/workflows/import-profiler.yml index bf4825995a8f..14671c5c878d 100644 --- a/.github/workflows/import-profiler.yml +++ b/.github/workflows/import-profiler.yml @@ -24,6 +24,7 @@ jobs: uses: actions/setup-python@v6 with: python-version: "3.15" + allow-prereleases: true - name: Install nox run: | python -m pip install --upgrade setuptools pip wheel From 5eab435736562a33e5126a553cf0d80a641d20bf Mon Sep 17 00:00:00 2001 From: Heba Alazzeh Date: Wed, 8 Jul 2026 02:52:45 +0000 Subject: [PATCH 03/13] chore: propagate import_profile nox session across all packages and goldens --- packages/bigframes/noxfile.py | 16 ++++++++++++++++ packages/bigquery-magics/noxfile.py | 16 ++++++++++++++++ packages/db-dtypes/noxfile.py | 16 ++++++++++++++++ packages/django-google-spanner/noxfile.py | 16 ++++++++++++++++ packages/gapic-generator/noxfile.py | 17 ++++++++++++++++- .../tests/integration/goldens/asset/noxfile.py | 9 +++++++++ .../integration/goldens/credentials/noxfile.py | 9 +++++++++ .../integration/goldens/eventarc/noxfile.py | 9 +++++++++ .../integration/goldens/logging/noxfile.py | 9 +++++++++ .../goldens/logging_internal/noxfile.py | 9 +++++++++ .../tests/integration/goldens/redis/noxfile.py | 9 +++++++++ .../goldens/redis_selective/noxfile.py | 9 +++++++++ .../goldens/storagebatchoperations/noxfile.py | 9 +++++++++ packages/gcp-sphinx-docfx-yaml/noxfile.py | 16 ++++++++++++++++ packages/google-ads-admanager/noxfile.py | 9 +++++++++ packages/google-ads-datamanager/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../google-ai-generativelanguage/noxfile.py | 9 +++++++++ packages/google-analytics-admin/noxfile.py | 9 +++++++++ packages/google-analytics-data/noxfile.py | 9 +++++++++ packages/google-api-core/noxfile.py | 16 ++++++++++++++++ packages/google-apps-card/noxfile.py | 9 +++++++++ packages/google-apps-chat/noxfile.py | 9 +++++++++ .../google-apps-events-subscriptions/noxfile.py | 9 +++++++++ packages/google-apps-meet/noxfile.py | 9 +++++++++ packages/google-apps-script-type/noxfile.py | 9 +++++++++ packages/google-area120-tables/noxfile.py | 9 +++++++++ packages/google-auth-httplib2/noxfile.py | 16 ++++++++++++++++ packages/google-auth-oauthlib/noxfile.py | 16 ++++++++++++++++ packages/google-auth/noxfile.py | 9 +++++++++ packages/google-backstory/noxfile.py | 9 +++++++++ .../google-cloud-access-approval/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ packages/google-cloud-agentregistry/noxfile.py | 9 +++++++++ .../google-cloud-alloydb-connectors/noxfile.py | 9 +++++++++ packages/google-cloud-alloydb/noxfile.py | 9 +++++++++ packages/google-cloud-api-gateway/noxfile.py | 9 +++++++++ packages/google-cloud-api-keys/noxfile.py | 9 +++++++++ packages/google-cloud-apigee-connect/noxfile.py | 9 +++++++++ .../google-cloud-apigee-registry/noxfile.py | 9 +++++++++ packages/google-cloud-apihub/noxfile.py | 9 +++++++++ packages/google-cloud-apiregistry/noxfile.py | 9 +++++++++ .../google-cloud-appengine-admin/noxfile.py | 9 +++++++++ .../google-cloud-appengine-logging/noxfile.py | 9 +++++++++ packages/google-cloud-apphub/noxfile.py | 9 +++++++++ packages/google-cloud-appoptimize/noxfile.py | 9 +++++++++ .../google-cloud-artifact-registry/noxfile.py | 9 +++++++++ packages/google-cloud-asset/noxfile.py | 9 +++++++++ .../google-cloud-assured-workloads/noxfile.py | 9 +++++++++ packages/google-cloud-audit-log/noxfile.py | 9 +++++++++ packages/google-cloud-auditmanager/noxfile.py | 9 +++++++++ packages/google-cloud-automl/noxfile.py | 9 +++++++++ packages/google-cloud-backupdr/noxfile.py | 9 +++++++++ .../google-cloud-bare-metal-solution/noxfile.py | 9 +++++++++ packages/google-cloud-batch/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ packages/google-cloud-biglake-hive/noxfile.py | 9 +++++++++ packages/google-cloud-biglake/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../google-cloud-bigquery-biglake/noxfile.py | 9 +++++++++ .../google-cloud-bigquery-connection/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../google-cloud-bigquery-logging/noxfile.py | 9 +++++++++ .../google-cloud-bigquery-migration/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../google-cloud-bigquery-storage/noxfile.py | 9 +++++++++ packages/google-cloud-bigquery/noxfile.py | 16 ++++++++++++++++ packages/google-cloud-bigtable/noxfile.py | 16 ++++++++++++++++ .../google-cloud-billing-budgets/noxfile.py | 9 +++++++++ packages/google-cloud-billing/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ packages/google-cloud-build/noxfile.py | 9 +++++++++ .../google-cloud-capacityplanner/noxfile.py | 9 +++++++++ .../google-cloud-certificate-manager/noxfile.py | 9 +++++++++ packages/google-cloud-ces/noxfile.py | 9 +++++++++ packages/google-cloud-channel/noxfile.py | 9 +++++++++ packages/google-cloud-chronicle/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ packages/google-cloud-common/noxfile.py | 9 +++++++++ packages/google-cloud-compute-v1beta/noxfile.py | 9 +++++++++ packages/google-cloud-compute/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ packages/google-cloud-config/noxfile.py | 9 +++++++++ packages/google-cloud-configdelivery/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ packages/google-cloud-container/noxfile.py | 9 +++++++++ .../google-cloud-containeranalysis/noxfile.py | 9 +++++++++ .../google-cloud-contentwarehouse/noxfile.py | 9 +++++++++ packages/google-cloud-core/noxfile.py | 16 ++++++++++++++++ packages/google-cloud-data-fusion/noxfile.py | 9 +++++++++ packages/google-cloud-data-qna/noxfile.py | 9 +++++++++ packages/google-cloud-databasecenter/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../google-cloud-datacatalog-lineage/noxfile.py | 9 +++++++++ packages/google-cloud-datacatalog/noxfile.py | 9 +++++++++ .../google-cloud-dataflow-client/noxfile.py | 9 +++++++++ packages/google-cloud-dataform/noxfile.py | 9 +++++++++ packages/google-cloud-datalabeling/noxfile.py | 9 +++++++++ packages/google-cloud-dataplex/noxfile.py | 9 +++++++++ .../google-cloud-dataproc-metastore/noxfile.py | 9 +++++++++ packages/google-cloud-dataproc/noxfile.py | 9 +++++++++ packages/google-cloud-datastore/noxfile.py | 9 +++++++++ packages/google-cloud-datastream/noxfile.py | 9 +++++++++ packages/google-cloud-deploy/noxfile.py | 9 +++++++++ .../google-cloud-developerconnect/noxfile.py | 9 +++++++++ .../google-cloud-devicestreaming/noxfile.py | 9 +++++++++ packages/google-cloud-dialogflow-cx/noxfile.py | 9 +++++++++ packages/google-cloud-dialogflow/noxfile.py | 9 +++++++++ .../google-cloud-discoveryengine/noxfile.py | 9 +++++++++ packages/google-cloud-dlp/noxfile.py | 9 +++++++++ packages/google-cloud-dms/noxfile.py | 9 +++++++++ packages/google-cloud-dns/noxfile.py | 16 ++++++++++++++++ .../google-cloud-documentai-toolbox/noxfile.py | 16 ++++++++++++++++ packages/google-cloud-documentai/noxfile.py | 9 +++++++++ packages/google-cloud-domains/noxfile.py | 9 +++++++++ packages/google-cloud-edgecontainer/noxfile.py | 9 +++++++++ packages/google-cloud-edgenetwork/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../google-cloud-error-reporting/noxfile.py | 9 +++++++++ .../google-cloud-essential-contacts/noxfile.py | 9 +++++++++ .../google-cloud-eventarc-publishing/noxfile.py | 9 +++++++++ packages/google-cloud-eventarc/noxfile.py | 9 +++++++++ packages/google-cloud-filestore/noxfile.py | 9 +++++++++ .../google-cloud-financialservices/noxfile.py | 9 +++++++++ packages/google-cloud-firestore/noxfile.py | 9 +++++++++ packages/google-cloud-functions/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../google-cloud-geminidataanalytics/noxfile.py | 9 +++++++++ packages/google-cloud-gke-backup/noxfile.py | 9 +++++++++ .../google-cloud-gke-connect-gateway/noxfile.py | 9 +++++++++ packages/google-cloud-gke-hub/noxfile.py | 9 +++++++++ packages/google-cloud-gke-multicloud/noxfile.py | 9 +++++++++ packages/google-cloud-gkerecommender/noxfile.py | 9 +++++++++ packages/google-cloud-gsuiteaddons/noxfile.py | 9 +++++++++ .../google-cloud-hypercomputecluster/noxfile.py | 9 +++++++++ packages/google-cloud-iam-logging/noxfile.py | 9 +++++++++ packages/google-cloud-iam/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ packages/google-cloud-iap/noxfile.py | 9 +++++++++ packages/google-cloud-ids/noxfile.py | 9 +++++++++ packages/google-cloud-kms-inventory/noxfile.py | 9 +++++++++ packages/google-cloud-kms/noxfile.py | 9 +++++++++ packages/google-cloud-language/noxfile.py | 9 +++++++++ packages/google-cloud-licensemanager/noxfile.py | 9 +++++++++ packages/google-cloud-life-sciences/noxfile.py | 9 +++++++++ packages/google-cloud-locationfinder/noxfile.py | 9 +++++++++ packages/google-cloud-logging/noxfile.py | 9 +++++++++ packages/google-cloud-lustre/noxfile.py | 9 +++++++++ .../google-cloud-maintenance-api/noxfile.py | 9 +++++++++ .../google-cloud-managed-identities/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ packages/google-cloud-managedkafka/noxfile.py | 9 +++++++++ .../google-cloud-media-translation/noxfile.py | 9 +++++++++ packages/google-cloud-memcache/noxfile.py | 9 +++++++++ packages/google-cloud-memorystore/noxfile.py | 9 +++++++++ .../google-cloud-migrationcenter/noxfile.py | 9 +++++++++ packages/google-cloud-modelarmor/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ packages/google-cloud-monitoring/noxfile.py | 9 +++++++++ packages/google-cloud-ndb/noxfile.py | 16 ++++++++++++++++ packages/google-cloud-netapp/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../google-cloud-network-management/noxfile.py | 9 +++++++++ .../google-cloud-network-security/noxfile.py | 9 +++++++++ .../google-cloud-network-services/noxfile.py | 9 +++++++++ packages/google-cloud-notebooks/noxfile.py | 9 +++++++++ packages/google-cloud-optimization/noxfile.py | 9 +++++++++ packages/google-cloud-oracledatabase/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ packages/google-cloud-org-policy/noxfile.py | 9 +++++++++ packages/google-cloud-os-config/noxfile.py | 9 +++++++++ packages/google-cloud-os-login/noxfile.py | 9 +++++++++ packages/google-cloud-parallelstore/noxfile.py | 9 +++++++++ .../google-cloud-parametermanager/noxfile.py | 9 +++++++++ .../google-cloud-phishing-protection/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../google-cloud-policysimulator/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ packages/google-cloud-private-ca/noxfile.py | 9 +++++++++ .../google-cloud-private-catalog/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ packages/google-cloud-pubsub/noxfile.py | 16 ++++++++++++++++ packages/google-cloud-quotas/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../google-cloud-recommendations-ai/noxfile.py | 9 +++++++++ packages/google-cloud-recommender/noxfile.py | 9 +++++++++ packages/google-cloud-redis-cluster/noxfile.py | 9 +++++++++ packages/google-cloud-redis/noxfile.py | 9 +++++++++ .../google-cloud-resource-manager/noxfile.py | 9 +++++++++ packages/google-cloud-retail/noxfile.py | 9 +++++++++ packages/google-cloud-run/noxfile.py | 9 +++++++++ packages/google-cloud-runtimeconfig/noxfile.py | 16 ++++++++++++++++ .../noxfile.py | 9 +++++++++ packages/google-cloud-scheduler/noxfile.py | 9 +++++++++ packages/google-cloud-secret-manager/noxfile.py | 9 +++++++++ .../google-cloud-securesourcemanager/noxfile.py | 9 +++++++++ .../google-cloud-security-publicca/noxfile.py | 9 +++++++++ packages/google-cloud-securitycenter/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../google-cloud-service-control/noxfile.py | 9 +++++++++ .../google-cloud-service-directory/noxfile.py | 9 +++++++++ .../google-cloud-service-management/noxfile.py | 9 +++++++++ packages/google-cloud-service-usage/noxfile.py | 9 +++++++++ packages/google-cloud-servicehealth/noxfile.py | 9 +++++++++ packages/google-cloud-shell/noxfile.py | 9 +++++++++ packages/google-cloud-source-context/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ packages/google-cloud-spanner/noxfile.py | 16 ++++++++++++++++ packages/google-cloud-speech/noxfile.py | 9 +++++++++ .../google-cloud-storage-control/noxfile.py | 9 +++++++++ .../google-cloud-storage-transfer/noxfile.py | 9 +++++++++ packages/google-cloud-storage/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../google-cloud-storageinsights/noxfile.py | 9 +++++++++ packages/google-cloud-support/noxfile.py | 9 +++++++++ packages/google-cloud-talent/noxfile.py | 9 +++++++++ packages/google-cloud-tasks/noxfile.py | 9 +++++++++ .../google-cloud-telcoautomation/noxfile.py | 9 +++++++++ packages/google-cloud-testutils/noxfile.py | 16 ++++++++++++++++ packages/google-cloud-texttospeech/noxfile.py | 9 +++++++++ packages/google-cloud-tpu/noxfile.py | 9 +++++++++ packages/google-cloud-trace/noxfile.py | 9 +++++++++ packages/google-cloud-translate/noxfile.py | 9 +++++++++ packages/google-cloud-vectorsearch/noxfile.py | 9 +++++++++ .../google-cloud-video-live-stream/noxfile.py | 9 +++++++++ packages/google-cloud-video-stitcher/noxfile.py | 9 +++++++++ .../google-cloud-video-transcoder/noxfile.py | 9 +++++++++ .../google-cloud-videointelligence/noxfile.py | 9 +++++++++ packages/google-cloud-vision/noxfile.py | 9 +++++++++ packages/google-cloud-visionai/noxfile.py | 9 +++++++++ packages/google-cloud-vm-migration/noxfile.py | 9 +++++++++ packages/google-cloud-vmwareengine/noxfile.py | 9 +++++++++ packages/google-cloud-vpc-access/noxfile.py | 9 +++++++++ packages/google-cloud-webrisk/noxfile.py | 9 +++++++++ .../google-cloud-websecurityscanner/noxfile.py | 9 +++++++++ packages/google-cloud-workflows/noxfile.py | 9 +++++++++ .../google-cloud-workloadmanager/noxfile.py | 9 +++++++++ packages/google-cloud-workstations/noxfile.py | 9 +++++++++ packages/google-crc32c/noxfile.py | 16 ++++++++++++++++ packages/google-developer-knowledge/noxfile.py | 9 +++++++++ .../google-devicesandservices-health/noxfile.py | 9 +++++++++ packages/google-geo-type/noxfile.py | 9 +++++++++ .../google-maps-addressvalidation/noxfile.py | 9 +++++++++ packages/google-maps-areainsights/noxfile.py | 9 +++++++++ .../google-maps-fleetengine-delivery/noxfile.py | 9 +++++++++ packages/google-maps-fleetengine/noxfile.py | 9 +++++++++ packages/google-maps-geocode/noxfile.py | 9 +++++++++ packages/google-maps-mapmanagement/noxfile.py | 9 +++++++++ .../google-maps-mapsplatformdatasets/noxfile.py | 9 +++++++++ packages/google-maps-navconnect/noxfile.py | 9 +++++++++ packages/google-maps-places/noxfile.py | 9 +++++++++ .../google-maps-routeoptimization/noxfile.py | 9 +++++++++ packages/google-maps-routing/noxfile.py | 9 +++++++++ packages/google-maps-solar/noxfile.py | 9 +++++++++ packages/google-resumable-media/noxfile.py | 16 ++++++++++++++++ packages/google-shopping-css/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../google-shopping-merchant-lfp/noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../noxfile.py | 9 +++++++++ .../google-shopping-merchant-quota/noxfile.py | 9 +++++++++ .../google-shopping-merchant-reports/noxfile.py | 9 +++++++++ .../google-shopping-merchant-reviews/noxfile.py | 9 +++++++++ packages/google-shopping-type/noxfile.py | 9 +++++++++ packages/googleapis-common-protos/noxfile.py | 9 +++++++++ packages/grafeas/noxfile.py | 9 +++++++++ packages/grpc-google-iam-v1/noxfile.py | 9 +++++++++ packages/pandas-gbq/noxfile.py | 9 +++++++++ packages/proto-plus/noxfile.py | 16 ++++++++++++++++ packages/sqlalchemy-bigquery/noxfile.py | 16 ++++++++++++++++ packages/sqlalchemy-spanner/noxfile.py | 16 ++++++++++++++++ 290 files changed, 2778 insertions(+), 1 deletion(-) diff --git a/packages/bigframes/noxfile.py b/packages/bigframes/noxfile.py index 0a33264aa8ea..37c41d05645e 100644 --- a/packages/bigframes/noxfile.py +++ b/packages/bigframes/noxfile.py @@ -1092,3 +1092,19 @@ def mypy(session): "--explicit-package-bases", '--exclude="^third_party"', ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") diff --git a/packages/bigquery-magics/noxfile.py b/packages/bigquery-magics/noxfile.py index f275406b6905..8ab763cdec40 100644 --- a/packages/bigquery-magics/noxfile.py +++ b/packages/bigquery-magics/noxfile.py @@ -546,3 +546,19 @@ def mypy(session): # TODO(https://github.com/googleapis/google-cloud-python/issues/16014): # Add mypy tests session.skip("mypy tests are not yet supported") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") diff --git a/packages/db-dtypes/noxfile.py b/packages/db-dtypes/noxfile.py index b80b1df6832a..8bc53cd0c1d0 100644 --- a/packages/db-dtypes/noxfile.py +++ b/packages/db-dtypes/noxfile.py @@ -547,3 +547,19 @@ def mypy(session): "--ignore-missing-imports", *session.posargs, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "db_dtypes", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "db_dtypes", "--iterations", "10") diff --git a/packages/django-google-spanner/noxfile.py b/packages/django-google-spanner/noxfile.py index 0b94e5b87bff..0911b8eebcb0 100644 --- a/packages/django-google-spanner/noxfile.py +++ b/packages/django-google-spanner/noxfile.py @@ -491,3 +491,19 @@ def format(session: nox.sessions.Session) -> None: "--line-length=88", # Standard Black line length *LINT_PATHS, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") diff --git a/packages/gapic-generator/noxfile.py b/packages/gapic-generator/noxfile.py index 6fac5c48853d..5ae4d6a41f7a 100644 --- a/packages/gapic-generator/noxfile.py +++ b/packages/gapic-generator/noxfile.py @@ -847,4 +847,19 @@ def core_deps_from_source(session, protobuf_implementation): """Run all tests with core dependencies installed from source.""" # TODO(https://github.com/googleapis/google-cloud-python/issues/16185): # Implement logic to install core packages directly from the mono-repo directories. - session.skip("core_deps_from_source session is not yet implemented for gapic-generator-python.") \ No newline at end of file + session.skip("core_deps_from_source session is not yet implemented for gapic-generator-python.") + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py b/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py index 09d28712c73c..7a9b2086d467 100755 --- a/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py @@ -93,6 +93,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -633,3 +634,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py b/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py index 65e26efe21d3..01077da09e24 100755 --- a/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py @@ -93,6 +93,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -633,3 +634,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py b/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py index 42b2349e2cc1..20fdc24fd81a 100755 --- a/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py @@ -93,6 +93,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -633,3 +634,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py b/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py index 09e4b345592a..0c506da149e6 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py @@ -93,6 +93,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -633,3 +634,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py b/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py index 09e4b345592a..0c506da149e6 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py @@ -93,6 +93,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -633,3 +634,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py b/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py index 9b3356dd1272..13bb8c07a21c 100755 --- a/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py @@ -93,6 +93,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -633,3 +634,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py b/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py index 9b3356dd1272..13bb8c07a21c 100755 --- a/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py @@ -93,6 +93,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -633,3 +634,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py b/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py index db370dd3dd0f..f14e5ef4b463 100755 --- a/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py @@ -93,6 +93,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -633,3 +634,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/gcp-sphinx-docfx-yaml/noxfile.py b/packages/gcp-sphinx-docfx-yaml/noxfile.py index ba5658c0e24f..d53c29e52dfd 100644 --- a/packages/gcp-sphinx-docfx-yaml/noxfile.py +++ b/packages/gcp-sphinx-docfx-yaml/noxfile.py @@ -173,3 +173,19 @@ def docfx(session): "DocFX build postponed during migration. " "Requires resolution of Sphinx 1.5.5 / Jinja2 compatibility." ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") diff --git a/packages/google-ads-admanager/noxfile.py b/packages/google-ads-admanager/noxfile.py index 266ed37fd871..ca2afd6f48e1 100644 --- a/packages/google-ads-admanager/noxfile.py +++ b/packages/google-ads-admanager/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-ads-datamanager/noxfile.py b/packages/google-ads-datamanager/noxfile.py index f2936e9406bd..79465ad9ecce 100644 --- a/packages/google-ads-datamanager/noxfile.py +++ b/packages/google-ads-datamanager/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-ads-marketingplatform-admin/noxfile.py b/packages/google-ads-marketingplatform-admin/noxfile.py index 6671718f045c..da03039590cd 100644 --- a/packages/google-ads-marketingplatform-admin/noxfile.py +++ b/packages/google-ads-marketingplatform-admin/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-ai-generativelanguage/noxfile.py b/packages/google-ai-generativelanguage/noxfile.py index 770a51d82198..b6e1588212de 100644 --- a/packages/google-ai-generativelanguage/noxfile.py +++ b/packages/google-ai-generativelanguage/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-analytics-admin/noxfile.py b/packages/google-analytics-admin/noxfile.py index c1cb27ce5fce..a5b525255184 100644 --- a/packages/google-analytics-admin/noxfile.py +++ b/packages/google-analytics-admin/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-analytics-data/noxfile.py b/packages/google-analytics-data/noxfile.py index 0fcdca3b449b..e98dda52579e 100644 --- a/packages/google-analytics-data/noxfile.py +++ b/packages/google-analytics-data/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-api-core/noxfile.py b/packages/google-api-core/noxfile.py index 0bad668a80dd..76381fb2fa80 100644 --- a/packages/google-api-core/noxfile.py +++ b/packages/google-api-core/noxfile.py @@ -464,3 +464,19 @@ def docfx(session): os.path.join("docs", ""), os.path.join("docs", "_build", "html", ""), ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") diff --git a/packages/google-apps-card/noxfile.py b/packages/google-apps-card/noxfile.py index 07e5821e034b..e8bb14c8f4a2 100644 --- a/packages/google-apps-card/noxfile.py +++ b/packages/google-apps-card/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-apps-chat/noxfile.py b/packages/google-apps-chat/noxfile.py index 068d9b29104c..799c357470f5 100644 --- a/packages/google-apps-chat/noxfile.py +++ b/packages/google-apps-chat/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-apps-events-subscriptions/noxfile.py b/packages/google-apps-events-subscriptions/noxfile.py index 13b14c1d293c..63282c8337c1 100644 --- a/packages/google-apps-events-subscriptions/noxfile.py +++ b/packages/google-apps-events-subscriptions/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-apps-meet/noxfile.py b/packages/google-apps-meet/noxfile.py index e10102a15d42..2d175fc68cab 100644 --- a/packages/google-apps-meet/noxfile.py +++ b/packages/google-apps-meet/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-apps-script-type/noxfile.py b/packages/google-apps-script-type/noxfile.py index a40e278a5761..79974a529be6 100644 --- a/packages/google-apps-script-type/noxfile.py +++ b/packages/google-apps-script-type/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-area120-tables/noxfile.py b/packages/google-area120-tables/noxfile.py index 4bcfad6e486e..f983a841280f 100644 --- a/packages/google-area120-tables/noxfile.py +++ b/packages/google-area120-tables/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-auth-httplib2/noxfile.py b/packages/google-auth-httplib2/noxfile.py index 67b1bd420cc5..2b8bfd0b5738 100644 --- a/packages/google-auth-httplib2/noxfile.py +++ b/packages/google-auth-httplib2/noxfile.py @@ -529,3 +529,19 @@ def core_deps_from_source(session): system_test_folder_path, *session.posargs, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") diff --git a/packages/google-auth-oauthlib/noxfile.py b/packages/google-auth-oauthlib/noxfile.py index a028eb1f1900..fac9e73f3b76 100644 --- a/packages/google-auth-oauthlib/noxfile.py +++ b/packages/google-auth-oauthlib/noxfile.py @@ -474,3 +474,19 @@ def mypy(session): "-p", "google_auth_oauthlib", ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google_auth_oauthlib", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google_auth_oauthlib", "--iterations", "10") diff --git a/packages/google-auth/noxfile.py b/packages/google-auth/noxfile.py index 19cc47a02a03..eef980a39375 100644 --- a/packages/google-auth/noxfile.py +++ b/packages/google-auth/noxfile.py @@ -69,6 +69,7 @@ "mypy", # cover must be last to avoid error `No data to report` "docs", + "import_profile", ] @@ -314,3 +315,11 @@ def core_deps_from_source(session): rather than pulling the dependencies from PyPI. """ session.skip("Skipping: Not applicable for google-auth.") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-backstory/noxfile.py b/packages/google-backstory/noxfile.py index 44eaafe8e0f6..68d2459104b1 100644 --- a/packages/google-backstory/noxfile.py +++ b/packages/google-backstory/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-access-approval/noxfile.py b/packages/google-cloud-access-approval/noxfile.py index 82e2a49f059d..95e330555c2c 100644 --- a/packages/google-cloud-access-approval/noxfile.py +++ b/packages/google-cloud-access-approval/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-access-context-manager/noxfile.py b/packages/google-cloud-access-context-manager/noxfile.py index b6ae8c821dca..b92178695792 100644 --- a/packages/google-cloud-access-context-manager/noxfile.py +++ b/packages/google-cloud-access-context-manager/noxfile.py @@ -85,6 +85,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -577,3 +578,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") diff --git a/packages/google-cloud-advisorynotifications/noxfile.py b/packages/google-cloud-advisorynotifications/noxfile.py index af26b1ac1af3..b5b96d5b2ff0 100644 --- a/packages/google-cloud-advisorynotifications/noxfile.py +++ b/packages/google-cloud-advisorynotifications/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-agentidentitycredentials/noxfile.py b/packages/google-cloud-agentidentitycredentials/noxfile.py index e7d8e25739ad..46d10d4e51e5 100644 --- a/packages/google-cloud-agentidentitycredentials/noxfile.py +++ b/packages/google-cloud-agentidentitycredentials/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-agentregistry/noxfile.py b/packages/google-cloud-agentregistry/noxfile.py index 30cc228cfbd6..eca6f6769167 100644 --- a/packages/google-cloud-agentregistry/noxfile.py +++ b/packages/google-cloud-agentregistry/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-alloydb-connectors/noxfile.py b/packages/google-cloud-alloydb-connectors/noxfile.py index a050f3c1881d..c52b728b8992 100644 --- a/packages/google-cloud-alloydb-connectors/noxfile.py +++ b/packages/google-cloud-alloydb-connectors/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-alloydb/noxfile.py b/packages/google-cloud-alloydb/noxfile.py index 1f0b150ae2c6..42d769f8f43d 100644 --- a/packages/google-cloud-alloydb/noxfile.py +++ b/packages/google-cloud-alloydb/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-api-gateway/noxfile.py b/packages/google-cloud-api-gateway/noxfile.py index 5d48da9f9b29..3f298cda6e73 100644 --- a/packages/google-cloud-api-gateway/noxfile.py +++ b/packages/google-cloud-api-gateway/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-api-keys/noxfile.py b/packages/google-cloud-api-keys/noxfile.py index 086c9842c20b..f91fe138b7f0 100644 --- a/packages/google-cloud-api-keys/noxfile.py +++ b/packages/google-cloud-api-keys/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-apigee-connect/noxfile.py b/packages/google-cloud-apigee-connect/noxfile.py index 3d316ce17189..87b894dbc6ab 100644 --- a/packages/google-cloud-apigee-connect/noxfile.py +++ b/packages/google-cloud-apigee-connect/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-apigee-registry/noxfile.py b/packages/google-cloud-apigee-registry/noxfile.py index 48e99b7dc8f1..29c04e4dce4f 100644 --- a/packages/google-cloud-apigee-registry/noxfile.py +++ b/packages/google-cloud-apigee-registry/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-apihub/noxfile.py b/packages/google-cloud-apihub/noxfile.py index ce015b92c88c..decdaa88c608 100644 --- a/packages/google-cloud-apihub/noxfile.py +++ b/packages/google-cloud-apihub/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-apiregistry/noxfile.py b/packages/google-cloud-apiregistry/noxfile.py index eea4a81bee54..d170c57f7949 100644 --- a/packages/google-cloud-apiregistry/noxfile.py +++ b/packages/google-cloud-apiregistry/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-appengine-admin/noxfile.py b/packages/google-cloud-appengine-admin/noxfile.py index ab3410edfff2..e4eadae1ae75 100644 --- a/packages/google-cloud-appengine-admin/noxfile.py +++ b/packages/google-cloud-appengine-admin/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-appengine-logging/noxfile.py b/packages/google-cloud-appengine-logging/noxfile.py index 9d295bb84faa..b85f344a88ff 100644 --- a/packages/google-cloud-appengine-logging/noxfile.py +++ b/packages/google-cloud-appengine-logging/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-apphub/noxfile.py b/packages/google-cloud-apphub/noxfile.py index 1ef74909a0de..fbb7567dbcd7 100644 --- a/packages/google-cloud-apphub/noxfile.py +++ b/packages/google-cloud-apphub/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-appoptimize/noxfile.py b/packages/google-cloud-appoptimize/noxfile.py index 00436f115a7e..c2ecb5fe7bc2 100644 --- a/packages/google-cloud-appoptimize/noxfile.py +++ b/packages/google-cloud-appoptimize/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-artifact-registry/noxfile.py b/packages/google-cloud-artifact-registry/noxfile.py index a5ca48ed78cc..7e22473d8349 100644 --- a/packages/google-cloud-artifact-registry/noxfile.py +++ b/packages/google-cloud-artifact-registry/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-asset/noxfile.py b/packages/google-cloud-asset/noxfile.py index b044cb25e9bd..66c00771daf5 100644 --- a/packages/google-cloud-asset/noxfile.py +++ b/packages/google-cloud-asset/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-assured-workloads/noxfile.py b/packages/google-cloud-assured-workloads/noxfile.py index a643c7d6ccd9..dc0f6a9f3352 100644 --- a/packages/google-cloud-assured-workloads/noxfile.py +++ b/packages/google-cloud-assured-workloads/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-audit-log/noxfile.py b/packages/google-cloud-audit-log/noxfile.py index 4724255759ff..0546c27a5e07 100644 --- a/packages/google-cloud-audit-log/noxfile.py +++ b/packages/google-cloud-audit-log/noxfile.py @@ -85,6 +85,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -563,3 +564,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") diff --git a/packages/google-cloud-auditmanager/noxfile.py b/packages/google-cloud-auditmanager/noxfile.py index 20b95fcccee0..1066b5041b19 100644 --- a/packages/google-cloud-auditmanager/noxfile.py +++ b/packages/google-cloud-auditmanager/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-automl/noxfile.py b/packages/google-cloud-automl/noxfile.py index a819955ec879..60a79d5ec781 100644 --- a/packages/google-cloud-automl/noxfile.py +++ b/packages/google-cloud-automl/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -638,3 +639,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-backupdr/noxfile.py b/packages/google-cloud-backupdr/noxfile.py index 6a226a08584d..f03df29a1833 100644 --- a/packages/google-cloud-backupdr/noxfile.py +++ b/packages/google-cloud-backupdr/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bare-metal-solution/noxfile.py b/packages/google-cloud-bare-metal-solution/noxfile.py index ff32011b2c06..56570d0ddf0c 100644 --- a/packages/google-cloud-bare-metal-solution/noxfile.py +++ b/packages/google-cloud-bare-metal-solution/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-batch/noxfile.py b/packages/google-cloud-batch/noxfile.py index 976947da12cf..0826d78e856a 100644 --- a/packages/google-cloud-batch/noxfile.py +++ b/packages/google-cloud-batch/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-beyondcorp-appconnections/noxfile.py b/packages/google-cloud-beyondcorp-appconnections/noxfile.py index b4957d8a7c4b..037c5b93ce95 100644 --- a/packages/google-cloud-beyondcorp-appconnections/noxfile.py +++ b/packages/google-cloud-beyondcorp-appconnections/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-beyondcorp-appconnectors/noxfile.py b/packages/google-cloud-beyondcorp-appconnectors/noxfile.py index 7b8f48b26a26..9a71eea19947 100644 --- a/packages/google-cloud-beyondcorp-appconnectors/noxfile.py +++ b/packages/google-cloud-beyondcorp-appconnectors/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-beyondcorp-appgateways/noxfile.py b/packages/google-cloud-beyondcorp-appgateways/noxfile.py index dd399e3a0da4..b30d80d527ce 100644 --- a/packages/google-cloud-beyondcorp-appgateways/noxfile.py +++ b/packages/google-cloud-beyondcorp-appgateways/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py b/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py index 60ca6ca1fcb1..a342162cd27d 100644 --- a/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py +++ b/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-beyondcorp-clientgateways/noxfile.py b/packages/google-cloud-beyondcorp-clientgateways/noxfile.py index b97d73b7ebe9..e78d1be85aba 100644 --- a/packages/google-cloud-beyondcorp-clientgateways/noxfile.py +++ b/packages/google-cloud-beyondcorp-clientgateways/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-biglake-hive/noxfile.py b/packages/google-cloud-biglake-hive/noxfile.py index 77c7118d3dfd..3ae2f827c952 100644 --- a/packages/google-cloud-biglake-hive/noxfile.py +++ b/packages/google-cloud-biglake-hive/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-biglake/noxfile.py b/packages/google-cloud-biglake/noxfile.py index 1ebc50a53211..8fe1028844b4 100644 --- a/packages/google-cloud-biglake/noxfile.py +++ b/packages/google-cloud-biglake/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigquery-analyticshub/noxfile.py b/packages/google-cloud-bigquery-analyticshub/noxfile.py index be6693d95ee7..1f875933e865 100644 --- a/packages/google-cloud-bigquery-analyticshub/noxfile.py +++ b/packages/google-cloud-bigquery-analyticshub/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigquery-biglake/noxfile.py b/packages/google-cloud-bigquery-biglake/noxfile.py index 0e743d519c6b..a50212705b2e 100644 --- a/packages/google-cloud-bigquery-biglake/noxfile.py +++ b/packages/google-cloud-bigquery-biglake/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigquery-connection/noxfile.py b/packages/google-cloud-bigquery-connection/noxfile.py index b6a28dbb4efc..1769eb65113d 100644 --- a/packages/google-cloud-bigquery-connection/noxfile.py +++ b/packages/google-cloud-bigquery-connection/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigquery-data-exchange/noxfile.py b/packages/google-cloud-bigquery-data-exchange/noxfile.py index fb619fb7bb1a..edd7d15a42dc 100644 --- a/packages/google-cloud-bigquery-data-exchange/noxfile.py +++ b/packages/google-cloud-bigquery-data-exchange/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigquery-datapolicies/noxfile.py b/packages/google-cloud-bigquery-datapolicies/noxfile.py index aabe19bd4e27..7b299c16b8d3 100644 --- a/packages/google-cloud-bigquery-datapolicies/noxfile.py +++ b/packages/google-cloud-bigquery-datapolicies/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigquery-datatransfer/noxfile.py b/packages/google-cloud-bigquery-datatransfer/noxfile.py index 44d603729ba5..0173c555c200 100644 --- a/packages/google-cloud-bigquery-datatransfer/noxfile.py +++ b/packages/google-cloud-bigquery-datatransfer/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigquery-logging/noxfile.py b/packages/google-cloud-bigquery-logging/noxfile.py index 357903bd6d52..6a7c2595a2ff 100644 --- a/packages/google-cloud-bigquery-logging/noxfile.py +++ b/packages/google-cloud-bigquery-logging/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigquery-migration/noxfile.py b/packages/google-cloud-bigquery-migration/noxfile.py index 4b9be68bf2a8..a33d454e9a46 100644 --- a/packages/google-cloud-bigquery-migration/noxfile.py +++ b/packages/google-cloud-bigquery-migration/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigquery-reservation/noxfile.py b/packages/google-cloud-bigquery-reservation/noxfile.py index 839f10246119..5ee35b08e38c 100644 --- a/packages/google-cloud-bigquery-reservation/noxfile.py +++ b/packages/google-cloud-bigquery-reservation/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigquery-storage/noxfile.py b/packages/google-cloud-bigquery-storage/noxfile.py index 4ec53338e333..af717048c974 100644 --- a/packages/google-cloud-bigquery-storage/noxfile.py +++ b/packages/google-cloud-bigquery-storage/noxfile.py @@ -99,6 +99,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -678,3 +679,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigquery/noxfile.py b/packages/google-cloud-bigquery/noxfile.py index c1dd1692b744..6adff6a96ce1 100644 --- a/packages/google-cloud-bigquery/noxfile.py +++ b/packages/google-cloud-bigquery/noxfile.py @@ -586,3 +586,19 @@ def format(session: nox.sessions.Session) -> None: # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections session.run("isort", "--fss", *python_files) session.run("black", *python_files) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigtable/noxfile.py b/packages/google-cloud-bigtable/noxfile.py index e6ef8c1e9911..cd4a7fecbd21 100644 --- a/packages/google-cloud-bigtable/noxfile.py +++ b/packages/google-cloud-bigtable/noxfile.py @@ -625,3 +625,19 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google.cloud.bigtable.data", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google.cloud.bigtable.data", "--iterations", "10") diff --git a/packages/google-cloud-billing-budgets/noxfile.py b/packages/google-cloud-billing-budgets/noxfile.py index d1f4e6341b46..683032a8f414 100644 --- a/packages/google-cloud-billing-budgets/noxfile.py +++ b/packages/google-cloud-billing-budgets/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-billing/noxfile.py b/packages/google-cloud-billing/noxfile.py index 3f1f9d83aaf2..632251eb9314 100644 --- a/packages/google-cloud-billing/noxfile.py +++ b/packages/google-cloud-billing/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-binary-authorization/noxfile.py b/packages/google-cloud-binary-authorization/noxfile.py index 4ed4e5ad9604..2ec3e160e213 100644 --- a/packages/google-cloud-binary-authorization/noxfile.py +++ b/packages/google-cloud-binary-authorization/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-build/noxfile.py b/packages/google-cloud-build/noxfile.py index a0694e258d3f..9d793a0d7b1d 100644 --- a/packages/google-cloud-build/noxfile.py +++ b/packages/google-cloud-build/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-capacityplanner/noxfile.py b/packages/google-cloud-capacityplanner/noxfile.py index 100e4db93531..8a0c64eacca8 100644 --- a/packages/google-cloud-capacityplanner/noxfile.py +++ b/packages/google-cloud-capacityplanner/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-certificate-manager/noxfile.py b/packages/google-cloud-certificate-manager/noxfile.py index 7d2237416f29..4b1b0e3201bf 100644 --- a/packages/google-cloud-certificate-manager/noxfile.py +++ b/packages/google-cloud-certificate-manager/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-ces/noxfile.py b/packages/google-cloud-ces/noxfile.py index e52903354c45..e82481b3c36b 100644 --- a/packages/google-cloud-ces/noxfile.py +++ b/packages/google-cloud-ces/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-channel/noxfile.py b/packages/google-cloud-channel/noxfile.py index 026a1cb20eec..964477ceb20e 100644 --- a/packages/google-cloud-channel/noxfile.py +++ b/packages/google-cloud-channel/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-chronicle/noxfile.py b/packages/google-cloud-chronicle/noxfile.py index 0bd323608bc8..1157454d8fb8 100644 --- a/packages/google-cloud-chronicle/noxfile.py +++ b/packages/google-cloud-chronicle/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-cloudcontrolspartner/noxfile.py b/packages/google-cloud-cloudcontrolspartner/noxfile.py index 26cc3368c7ba..85968af11e3b 100644 --- a/packages/google-cloud-cloudcontrolspartner/noxfile.py +++ b/packages/google-cloud-cloudcontrolspartner/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-cloudsecuritycompliance/noxfile.py b/packages/google-cloud-cloudsecuritycompliance/noxfile.py index 5f79e1a8c2b5..0791d2726bea 100644 --- a/packages/google-cloud-cloudsecuritycompliance/noxfile.py +++ b/packages/google-cloud-cloudsecuritycompliance/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-commerce-consumer-procurement/noxfile.py b/packages/google-cloud-commerce-consumer-procurement/noxfile.py index 620844bc9d4f..19886a434f99 100644 --- a/packages/google-cloud-commerce-consumer-procurement/noxfile.py +++ b/packages/google-cloud-commerce-consumer-procurement/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-common/noxfile.py b/packages/google-cloud-common/noxfile.py index 58d097ef35dc..ad14e50332a0 100644 --- a/packages/google-cloud-common/noxfile.py +++ b/packages/google-cloud-common/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-compute-v1beta/noxfile.py b/packages/google-cloud-compute-v1beta/noxfile.py index b0d0ee4f53ec..a9cfec4c7576 100644 --- a/packages/google-cloud-compute-v1beta/noxfile.py +++ b/packages/google-cloud-compute-v1beta/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-compute/noxfile.py b/packages/google-cloud-compute/noxfile.py index e4103b0c9ffb..3c46f1845e11 100644 --- a/packages/google-cloud-compute/noxfile.py +++ b/packages/google-cloud-compute/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-confidentialcomputing/noxfile.py b/packages/google-cloud-confidentialcomputing/noxfile.py index 2a3d9e9aa558..652071b2da2a 100644 --- a/packages/google-cloud-confidentialcomputing/noxfile.py +++ b/packages/google-cloud-confidentialcomputing/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-config/noxfile.py b/packages/google-cloud-config/noxfile.py index 9e253aa7bb01..a5ee0e2a08cb 100644 --- a/packages/google-cloud-config/noxfile.py +++ b/packages/google-cloud-config/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-configdelivery/noxfile.py b/packages/google-cloud-configdelivery/noxfile.py index b030cca9d976..437634bf1f36 100644 --- a/packages/google-cloud-configdelivery/noxfile.py +++ b/packages/google-cloud-configdelivery/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-contact-center-insights/noxfile.py b/packages/google-cloud-contact-center-insights/noxfile.py index fa7a8ecf4016..f46454a2a9eb 100644 --- a/packages/google-cloud-contact-center-insights/noxfile.py +++ b/packages/google-cloud-contact-center-insights/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-container/noxfile.py b/packages/google-cloud-container/noxfile.py index c681b455965e..b55694d26301 100644 --- a/packages/google-cloud-container/noxfile.py +++ b/packages/google-cloud-container/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-containeranalysis/noxfile.py b/packages/google-cloud-containeranalysis/noxfile.py index a919287d3dc0..e57e9978ec0f 100644 --- a/packages/google-cloud-containeranalysis/noxfile.py +++ b/packages/google-cloud-containeranalysis/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-contentwarehouse/noxfile.py b/packages/google-cloud-contentwarehouse/noxfile.py index b276ac47b184..aba0e6a7763b 100644 --- a/packages/google-cloud-contentwarehouse/noxfile.py +++ b/packages/google-cloud-contentwarehouse/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-core/noxfile.py b/packages/google-cloud-core/noxfile.py index 2de40dfb9234..f76d074b1f44 100644 --- a/packages/google-cloud-core/noxfile.py +++ b/packages/google-cloud-core/noxfile.py @@ -418,3 +418,19 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-data-fusion/noxfile.py b/packages/google-cloud-data-fusion/noxfile.py index bd3ea36f0386..934e1ba9b6d9 100644 --- a/packages/google-cloud-data-fusion/noxfile.py +++ b/packages/google-cloud-data-fusion/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-data-qna/noxfile.py b/packages/google-cloud-data-qna/noxfile.py index 043ebd79a0bb..e698594e04bb 100644 --- a/packages/google-cloud-data-qna/noxfile.py +++ b/packages/google-cloud-data-qna/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-databasecenter/noxfile.py b/packages/google-cloud-databasecenter/noxfile.py index 003b7dd3c53f..c439ae3b9d8e 100644 --- a/packages/google-cloud-databasecenter/noxfile.py +++ b/packages/google-cloud-databasecenter/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-datacatalog-lineage-configmanagement/noxfile.py b/packages/google-cloud-datacatalog-lineage-configmanagement/noxfile.py index 5ba2db6104ad..6def24ef233b 100644 --- a/packages/google-cloud-datacatalog-lineage-configmanagement/noxfile.py +++ b/packages/google-cloud-datacatalog-lineage-configmanagement/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-datacatalog-lineage/noxfile.py b/packages/google-cloud-datacatalog-lineage/noxfile.py index 1cf9b67d7e28..445f6ff21408 100644 --- a/packages/google-cloud-datacatalog-lineage/noxfile.py +++ b/packages/google-cloud-datacatalog-lineage/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-datacatalog/noxfile.py b/packages/google-cloud-datacatalog/noxfile.py index f1d0baa07491..0b6db6580366 100644 --- a/packages/google-cloud-datacatalog/noxfile.py +++ b/packages/google-cloud-datacatalog/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-dataflow-client/noxfile.py b/packages/google-cloud-dataflow-client/noxfile.py index eb858582eda7..6160a6c4a9c8 100644 --- a/packages/google-cloud-dataflow-client/noxfile.py +++ b/packages/google-cloud-dataflow-client/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-dataform/noxfile.py b/packages/google-cloud-dataform/noxfile.py index 19c4147fe1de..192a57896004 100644 --- a/packages/google-cloud-dataform/noxfile.py +++ b/packages/google-cloud-dataform/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-datalabeling/noxfile.py b/packages/google-cloud-datalabeling/noxfile.py index e4f28c74368b..099f126fc39f 100644 --- a/packages/google-cloud-datalabeling/noxfile.py +++ b/packages/google-cloud-datalabeling/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-dataplex/noxfile.py b/packages/google-cloud-dataplex/noxfile.py index 861b281f03a7..d95aa4d8f47b 100644 --- a/packages/google-cloud-dataplex/noxfile.py +++ b/packages/google-cloud-dataplex/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-dataproc-metastore/noxfile.py b/packages/google-cloud-dataproc-metastore/noxfile.py index 47eff28054f9..74fbc13c6c5f 100644 --- a/packages/google-cloud-dataproc-metastore/noxfile.py +++ b/packages/google-cloud-dataproc-metastore/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-dataproc/noxfile.py b/packages/google-cloud-dataproc/noxfile.py index 4c1c13c5d053..ca769307aa0f 100644 --- a/packages/google-cloud-dataproc/noxfile.py +++ b/packages/google-cloud-dataproc/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-datastore/noxfile.py b/packages/google-cloud-datastore/noxfile.py index af42d740478e..bcc70d808b97 100644 --- a/packages/google-cloud-datastore/noxfile.py +++ b/packages/google-cloud-datastore/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -645,3 +646,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-datastream/noxfile.py b/packages/google-cloud-datastream/noxfile.py index 2769c61b3d26..d5fb283a633c 100644 --- a/packages/google-cloud-datastream/noxfile.py +++ b/packages/google-cloud-datastream/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-deploy/noxfile.py b/packages/google-cloud-deploy/noxfile.py index 8b14ce1ff03a..b5ae98f39e63 100644 --- a/packages/google-cloud-deploy/noxfile.py +++ b/packages/google-cloud-deploy/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-developerconnect/noxfile.py b/packages/google-cloud-developerconnect/noxfile.py index e4b4e0709514..48815e7d2c12 100644 --- a/packages/google-cloud-developerconnect/noxfile.py +++ b/packages/google-cloud-developerconnect/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-devicestreaming/noxfile.py b/packages/google-cloud-devicestreaming/noxfile.py index 35e6971161be..5c5e37bcb14a 100644 --- a/packages/google-cloud-devicestreaming/noxfile.py +++ b/packages/google-cloud-devicestreaming/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-dialogflow-cx/noxfile.py b/packages/google-cloud-dialogflow-cx/noxfile.py index 805659bdd66f..2a642add9182 100644 --- a/packages/google-cloud-dialogflow-cx/noxfile.py +++ b/packages/google-cloud-dialogflow-cx/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-dialogflow/noxfile.py b/packages/google-cloud-dialogflow/noxfile.py index 16dd69716f10..46a0c568cc98 100644 --- a/packages/google-cloud-dialogflow/noxfile.py +++ b/packages/google-cloud-dialogflow/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-discoveryengine/noxfile.py b/packages/google-cloud-discoveryengine/noxfile.py index 762d1dda8f95..15997e360056 100644 --- a/packages/google-cloud-discoveryengine/noxfile.py +++ b/packages/google-cloud-discoveryengine/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-dlp/noxfile.py b/packages/google-cloud-dlp/noxfile.py index 08977f0c92b7..94c086e4a478 100644 --- a/packages/google-cloud-dlp/noxfile.py +++ b/packages/google-cloud-dlp/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-dms/noxfile.py b/packages/google-cloud-dms/noxfile.py index e7c9e6377709..7f6336f5170e 100644 --- a/packages/google-cloud-dms/noxfile.py +++ b/packages/google-cloud-dms/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-dns/noxfile.py b/packages/google-cloud-dns/noxfile.py index bb38d1e08a91..2732e966caaf 100644 --- a/packages/google-cloud-dns/noxfile.py +++ b/packages/google-cloud-dns/noxfile.py @@ -513,3 +513,19 @@ def core_deps_from_source(session): "py.test", "tests/unit", ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-documentai-toolbox/noxfile.py b/packages/google-cloud-documentai-toolbox/noxfile.py index db70716c5d6b..9cb0de91312c 100644 --- a/packages/google-cloud-documentai-toolbox/noxfile.py +++ b/packages/google-cloud-documentai-toolbox/noxfile.py @@ -547,3 +547,19 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google.cloud.documentai_toolbox", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google.cloud.documentai_toolbox", "--iterations", "10") diff --git a/packages/google-cloud-documentai/noxfile.py b/packages/google-cloud-documentai/noxfile.py index 8dcff8465a6c..bf516b858975 100644 --- a/packages/google-cloud-documentai/noxfile.py +++ b/packages/google-cloud-documentai/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-domains/noxfile.py b/packages/google-cloud-domains/noxfile.py index e1810b6976dd..7add4ad4561a 100644 --- a/packages/google-cloud-domains/noxfile.py +++ b/packages/google-cloud-domains/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-edgecontainer/noxfile.py b/packages/google-cloud-edgecontainer/noxfile.py index 43042ab41c58..fa79b2aa4cff 100644 --- a/packages/google-cloud-edgecontainer/noxfile.py +++ b/packages/google-cloud-edgecontainer/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-edgenetwork/noxfile.py b/packages/google-cloud-edgenetwork/noxfile.py index 52259b092b2c..e7ec5d6bd3f7 100644 --- a/packages/google-cloud-edgenetwork/noxfile.py +++ b/packages/google-cloud-edgenetwork/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-enterpriseknowledgegraph/noxfile.py b/packages/google-cloud-enterpriseknowledgegraph/noxfile.py index d8171fa7ea3a..7cc9ea6a019a 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/noxfile.py +++ b/packages/google-cloud-enterpriseknowledgegraph/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-error-reporting/noxfile.py b/packages/google-cloud-error-reporting/noxfile.py index e13108291d94..1340d0fd57b2 100644 --- a/packages/google-cloud-error-reporting/noxfile.py +++ b/packages/google-cloud-error-reporting/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -638,3 +639,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-essential-contacts/noxfile.py b/packages/google-cloud-essential-contacts/noxfile.py index 4da6f982d14b..3852efc0dacc 100644 --- a/packages/google-cloud-essential-contacts/noxfile.py +++ b/packages/google-cloud-essential-contacts/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-eventarc-publishing/noxfile.py b/packages/google-cloud-eventarc-publishing/noxfile.py index 4ab114200c08..927ebf6706fe 100644 --- a/packages/google-cloud-eventarc-publishing/noxfile.py +++ b/packages/google-cloud-eventarc-publishing/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-eventarc/noxfile.py b/packages/google-cloud-eventarc/noxfile.py index 6d8722a224dc..b4038a1d4f08 100644 --- a/packages/google-cloud-eventarc/noxfile.py +++ b/packages/google-cloud-eventarc/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-filestore/noxfile.py b/packages/google-cloud-filestore/noxfile.py index dcb7a07707a3..920ae400c144 100644 --- a/packages/google-cloud-filestore/noxfile.py +++ b/packages/google-cloud-filestore/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-financialservices/noxfile.py b/packages/google-cloud-financialservices/noxfile.py index e9376f8c2c18..45d52a1eddbc 100644 --- a/packages/google-cloud-financialservices/noxfile.py +++ b/packages/google-cloud-financialservices/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-firestore/noxfile.py b/packages/google-cloud-firestore/noxfile.py index 4df37240719c..2fa9b42ad61a 100644 --- a/packages/google-cloud-firestore/noxfile.py +++ b/packages/google-cloud-firestore/noxfile.py @@ -96,6 +96,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -700,3 +701,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-functions/noxfile.py b/packages/google-cloud-functions/noxfile.py index c46cf4fc5cad..cdc2208b0ee0 100644 --- a/packages/google-cloud-functions/noxfile.py +++ b/packages/google-cloud-functions/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-gdchardwaremanagement/noxfile.py b/packages/google-cloud-gdchardwaremanagement/noxfile.py index 6f51ea26c38b..274e700fa1b2 100644 --- a/packages/google-cloud-gdchardwaremanagement/noxfile.py +++ b/packages/google-cloud-gdchardwaremanagement/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-geminidataanalytics/noxfile.py b/packages/google-cloud-geminidataanalytics/noxfile.py index 8e27ba9291da..37de84d01bec 100644 --- a/packages/google-cloud-geminidataanalytics/noxfile.py +++ b/packages/google-cloud-geminidataanalytics/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-gke-backup/noxfile.py b/packages/google-cloud-gke-backup/noxfile.py index 56fab5920e83..0733e6297977 100644 --- a/packages/google-cloud-gke-backup/noxfile.py +++ b/packages/google-cloud-gke-backup/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-gke-connect-gateway/noxfile.py b/packages/google-cloud-gke-connect-gateway/noxfile.py index 0154a64bc1b5..e8da4de4533f 100644 --- a/packages/google-cloud-gke-connect-gateway/noxfile.py +++ b/packages/google-cloud-gke-connect-gateway/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-gke-hub/noxfile.py b/packages/google-cloud-gke-hub/noxfile.py index a5124d5be99a..de2ffec731fc 100644 --- a/packages/google-cloud-gke-hub/noxfile.py +++ b/packages/google-cloud-gke-hub/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-gke-multicloud/noxfile.py b/packages/google-cloud-gke-multicloud/noxfile.py index 6dbc9a81300b..f4c986d13295 100644 --- a/packages/google-cloud-gke-multicloud/noxfile.py +++ b/packages/google-cloud-gke-multicloud/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-gkerecommender/noxfile.py b/packages/google-cloud-gkerecommender/noxfile.py index b11b2a44dfee..edc9d909e3e7 100644 --- a/packages/google-cloud-gkerecommender/noxfile.py +++ b/packages/google-cloud-gkerecommender/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-gsuiteaddons/noxfile.py b/packages/google-cloud-gsuiteaddons/noxfile.py index da154872a469..8491dd06e578 100644 --- a/packages/google-cloud-gsuiteaddons/noxfile.py +++ b/packages/google-cloud-gsuiteaddons/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-hypercomputecluster/noxfile.py b/packages/google-cloud-hypercomputecluster/noxfile.py index 0a5b009a3092..ed0d8a0a8a76 100644 --- a/packages/google-cloud-hypercomputecluster/noxfile.py +++ b/packages/google-cloud-hypercomputecluster/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-iam-logging/noxfile.py b/packages/google-cloud-iam-logging/noxfile.py index eb1274b44083..27db30e997ba 100644 --- a/packages/google-cloud-iam-logging/noxfile.py +++ b/packages/google-cloud-iam-logging/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-iam/noxfile.py b/packages/google-cloud-iam/noxfile.py index 60be3c6e4e18..886dbb28e78a 100644 --- a/packages/google-cloud-iam/noxfile.py +++ b/packages/google-cloud-iam/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-iamconnectorcredentials/noxfile.py b/packages/google-cloud-iamconnectorcredentials/noxfile.py index 1fff9f2e6f1e..182d72c18fb3 100644 --- a/packages/google-cloud-iamconnectorcredentials/noxfile.py +++ b/packages/google-cloud-iamconnectorcredentials/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-iap/noxfile.py b/packages/google-cloud-iap/noxfile.py index 239436d95342..21a1436a321c 100644 --- a/packages/google-cloud-iap/noxfile.py +++ b/packages/google-cloud-iap/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-ids/noxfile.py b/packages/google-cloud-ids/noxfile.py index 039b77ebbb70..15e835478fc5 100644 --- a/packages/google-cloud-ids/noxfile.py +++ b/packages/google-cloud-ids/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-kms-inventory/noxfile.py b/packages/google-cloud-kms-inventory/noxfile.py index beb750ab1711..ae9e73fe2630 100644 --- a/packages/google-cloud-kms-inventory/noxfile.py +++ b/packages/google-cloud-kms-inventory/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-kms/noxfile.py b/packages/google-cloud-kms/noxfile.py index 0468f42a5bc4..adf4ba32fe7e 100644 --- a/packages/google-cloud-kms/noxfile.py +++ b/packages/google-cloud-kms/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-language/noxfile.py b/packages/google-cloud-language/noxfile.py index 7c8f31734518..711dbd8d97de 100644 --- a/packages/google-cloud-language/noxfile.py +++ b/packages/google-cloud-language/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-licensemanager/noxfile.py b/packages/google-cloud-licensemanager/noxfile.py index faab51c77445..98aedceeb6d6 100644 --- a/packages/google-cloud-licensemanager/noxfile.py +++ b/packages/google-cloud-licensemanager/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-life-sciences/noxfile.py b/packages/google-cloud-life-sciences/noxfile.py index 21cf5135ed89..16fa282d26b9 100644 --- a/packages/google-cloud-life-sciences/noxfile.py +++ b/packages/google-cloud-life-sciences/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-locationfinder/noxfile.py b/packages/google-cloud-locationfinder/noxfile.py index cc2ef53e813b..866dcfb8293a 100644 --- a/packages/google-cloud-locationfinder/noxfile.py +++ b/packages/google-cloud-locationfinder/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-logging/noxfile.py b/packages/google-cloud-logging/noxfile.py index f243539c2d21..9b2446944be1 100644 --- a/packages/google-cloud-logging/noxfile.py +++ b/packages/google-cloud-logging/noxfile.py @@ -98,6 +98,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -636,3 +637,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") diff --git a/packages/google-cloud-lustre/noxfile.py b/packages/google-cloud-lustre/noxfile.py index adedfe930707..d0faa014d6b8 100644 --- a/packages/google-cloud-lustre/noxfile.py +++ b/packages/google-cloud-lustre/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-maintenance-api/noxfile.py b/packages/google-cloud-maintenance-api/noxfile.py index c454a3334353..f468415e7910 100644 --- a/packages/google-cloud-maintenance-api/noxfile.py +++ b/packages/google-cloud-maintenance-api/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-managed-identities/noxfile.py b/packages/google-cloud-managed-identities/noxfile.py index a9c496f3b4cf..076e179c3916 100644 --- a/packages/google-cloud-managed-identities/noxfile.py +++ b/packages/google-cloud-managed-identities/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-managedkafka-schemaregistry/noxfile.py b/packages/google-cloud-managedkafka-schemaregistry/noxfile.py index 84a7800166e5..52601b6888f4 100644 --- a/packages/google-cloud-managedkafka-schemaregistry/noxfile.py +++ b/packages/google-cloud-managedkafka-schemaregistry/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-managedkafka/noxfile.py b/packages/google-cloud-managedkafka/noxfile.py index c37d675428ee..2c78efa7dcef 100644 --- a/packages/google-cloud-managedkafka/noxfile.py +++ b/packages/google-cloud-managedkafka/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-media-translation/noxfile.py b/packages/google-cloud-media-translation/noxfile.py index 32561ecc46e5..4e239db52d5d 100644 --- a/packages/google-cloud-media-translation/noxfile.py +++ b/packages/google-cloud-media-translation/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-memcache/noxfile.py b/packages/google-cloud-memcache/noxfile.py index 53eca79c60e2..5cee21d049ae 100644 --- a/packages/google-cloud-memcache/noxfile.py +++ b/packages/google-cloud-memcache/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-memorystore/noxfile.py b/packages/google-cloud-memorystore/noxfile.py index f25e737a088f..0bdd4333e6b5 100644 --- a/packages/google-cloud-memorystore/noxfile.py +++ b/packages/google-cloud-memorystore/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-migrationcenter/noxfile.py b/packages/google-cloud-migrationcenter/noxfile.py index 24d0f586240d..c9698f875554 100644 --- a/packages/google-cloud-migrationcenter/noxfile.py +++ b/packages/google-cloud-migrationcenter/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-modelarmor/noxfile.py b/packages/google-cloud-modelarmor/noxfile.py index 543e80995c76..103e1586e73b 100644 --- a/packages/google-cloud-modelarmor/noxfile.py +++ b/packages/google-cloud-modelarmor/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-monitoring-dashboards/noxfile.py b/packages/google-cloud-monitoring-dashboards/noxfile.py index f74cd9919ad2..afef0f523f28 100644 --- a/packages/google-cloud-monitoring-dashboards/noxfile.py +++ b/packages/google-cloud-monitoring-dashboards/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -638,3 +639,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-monitoring-metrics-scopes/noxfile.py b/packages/google-cloud-monitoring-metrics-scopes/noxfile.py index c28daef40ff2..de335e09224e 100644 --- a/packages/google-cloud-monitoring-metrics-scopes/noxfile.py +++ b/packages/google-cloud-monitoring-metrics-scopes/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-monitoring/noxfile.py b/packages/google-cloud-monitoring/noxfile.py index ed53a8853665..a726d3df94bc 100644 --- a/packages/google-cloud-monitoring/noxfile.py +++ b/packages/google-cloud-monitoring/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -639,3 +640,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-ndb/noxfile.py b/packages/google-cloud-ndb/noxfile.py index e447badd711c..44beb5962377 100644 --- a/packages/google-cloud-ndb/noxfile.py +++ b/packages/google-cloud-ndb/noxfile.py @@ -548,3 +548,19 @@ def lint_setup_py(session): """Verify that setup.py is valid (including RST check).""" session.install("setuptools", "docutils", "pygments") session.run("python", "setup.py", "check", "--restructuredtext", "--strict") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google.cloud.ndb", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google.cloud.ndb", "--iterations", "10") diff --git a/packages/google-cloud-netapp/noxfile.py b/packages/google-cloud-netapp/noxfile.py index 9cdc985be32a..085c92d354ee 100644 --- a/packages/google-cloud-netapp/noxfile.py +++ b/packages/google-cloud-netapp/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-network-connectivity/noxfile.py b/packages/google-cloud-network-connectivity/noxfile.py index 52a57bff4416..a4e0365becd0 100644 --- a/packages/google-cloud-network-connectivity/noxfile.py +++ b/packages/google-cloud-network-connectivity/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-network-management/noxfile.py b/packages/google-cloud-network-management/noxfile.py index c30a6b93d952..8888d2ac0383 100644 --- a/packages/google-cloud-network-management/noxfile.py +++ b/packages/google-cloud-network-management/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-network-security/noxfile.py b/packages/google-cloud-network-security/noxfile.py index 14d2cb6a6f53..5641a221dfc4 100644 --- a/packages/google-cloud-network-security/noxfile.py +++ b/packages/google-cloud-network-security/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-network-services/noxfile.py b/packages/google-cloud-network-services/noxfile.py index 7061cef385ac..75a9ff55abfe 100644 --- a/packages/google-cloud-network-services/noxfile.py +++ b/packages/google-cloud-network-services/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-notebooks/noxfile.py b/packages/google-cloud-notebooks/noxfile.py index 215850a5af4b..fb5f28ab947c 100644 --- a/packages/google-cloud-notebooks/noxfile.py +++ b/packages/google-cloud-notebooks/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-optimization/noxfile.py b/packages/google-cloud-optimization/noxfile.py index b023be356097..fb47f3a7a43c 100644 --- a/packages/google-cloud-optimization/noxfile.py +++ b/packages/google-cloud-optimization/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-oracledatabase/noxfile.py b/packages/google-cloud-oracledatabase/noxfile.py index 22a47f0fa4ff..3bc933ce904a 100644 --- a/packages/google-cloud-oracledatabase/noxfile.py +++ b/packages/google-cloud-oracledatabase/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-orchestration-airflow/noxfile.py b/packages/google-cloud-orchestration-airflow/noxfile.py index 0d1aed8f2c70..82acef83ca73 100644 --- a/packages/google-cloud-orchestration-airflow/noxfile.py +++ b/packages/google-cloud-orchestration-airflow/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-org-policy/noxfile.py b/packages/google-cloud-org-policy/noxfile.py index 6cf84cb47c03..614884eda907 100644 --- a/packages/google-cloud-org-policy/noxfile.py +++ b/packages/google-cloud-org-policy/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-os-config/noxfile.py b/packages/google-cloud-os-config/noxfile.py index 5a23e3023a8b..ae8aa92abd86 100644 --- a/packages/google-cloud-os-config/noxfile.py +++ b/packages/google-cloud-os-config/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-os-login/noxfile.py b/packages/google-cloud-os-login/noxfile.py index 8f85dfe7f505..a655ab9771d7 100644 --- a/packages/google-cloud-os-login/noxfile.py +++ b/packages/google-cloud-os-login/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-parallelstore/noxfile.py b/packages/google-cloud-parallelstore/noxfile.py index 9797fedc7bb5..824c3b1d8de3 100644 --- a/packages/google-cloud-parallelstore/noxfile.py +++ b/packages/google-cloud-parallelstore/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-parametermanager/noxfile.py b/packages/google-cloud-parametermanager/noxfile.py index 7cc0bf8cba28..f27d80e95d49 100644 --- a/packages/google-cloud-parametermanager/noxfile.py +++ b/packages/google-cloud-parametermanager/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-phishing-protection/noxfile.py b/packages/google-cloud-phishing-protection/noxfile.py index 26b29d321260..ba5ac6ce1a06 100644 --- a/packages/google-cloud-phishing-protection/noxfile.py +++ b/packages/google-cloud-phishing-protection/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-policy-troubleshooter/noxfile.py b/packages/google-cloud-policy-troubleshooter/noxfile.py index e58bdb90dc5d..d25945b17503 100644 --- a/packages/google-cloud-policy-troubleshooter/noxfile.py +++ b/packages/google-cloud-policy-troubleshooter/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-policysimulator/noxfile.py b/packages/google-cloud-policysimulator/noxfile.py index 3d3c18d50ed7..bc8a194a0848 100644 --- a/packages/google-cloud-policysimulator/noxfile.py +++ b/packages/google-cloud-policysimulator/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-policytroubleshooter-iam/noxfile.py b/packages/google-cloud-policytroubleshooter-iam/noxfile.py index 64b3a1946ab8..50b10d38d7eb 100644 --- a/packages/google-cloud-policytroubleshooter-iam/noxfile.py +++ b/packages/google-cloud-policytroubleshooter-iam/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-private-ca/noxfile.py b/packages/google-cloud-private-ca/noxfile.py index 63dbc9f15da1..ec8158da72c0 100644 --- a/packages/google-cloud-private-ca/noxfile.py +++ b/packages/google-cloud-private-ca/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-private-catalog/noxfile.py b/packages/google-cloud-private-catalog/noxfile.py index 6c62e204bc2c..c8b007e1c8cb 100644 --- a/packages/google-cloud-private-catalog/noxfile.py +++ b/packages/google-cloud-private-catalog/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-privilegedaccessmanager/noxfile.py b/packages/google-cloud-privilegedaccessmanager/noxfile.py index 59636262695a..5ba0978bdc6d 100644 --- a/packages/google-cloud-privilegedaccessmanager/noxfile.py +++ b/packages/google-cloud-privilegedaccessmanager/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-pubsub/noxfile.py b/packages/google-cloud-pubsub/noxfile.py index fb01bc8d1105..e99b49fcd8a1 100644 --- a/packages/google-cloud-pubsub/noxfile.py +++ b/packages/google-cloud-pubsub/noxfile.py @@ -623,3 +623,19 @@ def prerelease_deps(session, protobuf_implementation): def core_deps_from_source(session, protobuf_implementation): """Skipping until Pub/Sub migration is complete.""" session.skip("Skipping core_deps_from_source for google-cloud-pubsub.") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google.cloud", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google.cloud", "--iterations", "10") diff --git a/packages/google-cloud-quotas/noxfile.py b/packages/google-cloud-quotas/noxfile.py index 53416e6741d4..34dc9845ea30 100644 --- a/packages/google-cloud-quotas/noxfile.py +++ b/packages/google-cloud-quotas/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-rapidmigrationassessment/noxfile.py b/packages/google-cloud-rapidmigrationassessment/noxfile.py index 7963a1ae7b82..1565c8ca0efe 100644 --- a/packages/google-cloud-rapidmigrationassessment/noxfile.py +++ b/packages/google-cloud-rapidmigrationassessment/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-recaptcha-enterprise/noxfile.py b/packages/google-cloud-recaptcha-enterprise/noxfile.py index cc7f5fec5d0c..1bc6f5b9e919 100644 --- a/packages/google-cloud-recaptcha-enterprise/noxfile.py +++ b/packages/google-cloud-recaptcha-enterprise/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-recommendations-ai/noxfile.py b/packages/google-cloud-recommendations-ai/noxfile.py index 1b1048928076..087bdb6ca81b 100644 --- a/packages/google-cloud-recommendations-ai/noxfile.py +++ b/packages/google-cloud-recommendations-ai/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-recommender/noxfile.py b/packages/google-cloud-recommender/noxfile.py index 144f17361952..f03f04c44e40 100644 --- a/packages/google-cloud-recommender/noxfile.py +++ b/packages/google-cloud-recommender/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-redis-cluster/noxfile.py b/packages/google-cloud-redis-cluster/noxfile.py index 04445b2b2ed8..345534d3326b 100644 --- a/packages/google-cloud-redis-cluster/noxfile.py +++ b/packages/google-cloud-redis-cluster/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-redis/noxfile.py b/packages/google-cloud-redis/noxfile.py index 1aaaa5ee824f..ab7f1e396f1c 100644 --- a/packages/google-cloud-redis/noxfile.py +++ b/packages/google-cloud-redis/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-resource-manager/noxfile.py b/packages/google-cloud-resource-manager/noxfile.py index d767a44baff2..5494b26703d0 100644 --- a/packages/google-cloud-resource-manager/noxfile.py +++ b/packages/google-cloud-resource-manager/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-retail/noxfile.py b/packages/google-cloud-retail/noxfile.py index fab57e38aee8..fe572593cc84 100644 --- a/packages/google-cloud-retail/noxfile.py +++ b/packages/google-cloud-retail/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-run/noxfile.py b/packages/google-cloud-run/noxfile.py index 4c75b5e990d9..1831cdb1d70f 100644 --- a/packages/google-cloud-run/noxfile.py +++ b/packages/google-cloud-run/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-runtimeconfig/noxfile.py b/packages/google-cloud-runtimeconfig/noxfile.py index 42e77572607e..88ac1e09e792 100644 --- a/packages/google-cloud-runtimeconfig/noxfile.py +++ b/packages/google-cloud-runtimeconfig/noxfile.py @@ -509,3 +509,19 @@ def core_deps_from_source(session): system_test_folder_path, *session.posargs, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-saasplatform-saasservicemgmt/noxfile.py b/packages/google-cloud-saasplatform-saasservicemgmt/noxfile.py index 554ed2d56036..c1da0df46539 100644 --- a/packages/google-cloud-saasplatform-saasservicemgmt/noxfile.py +++ b/packages/google-cloud-saasplatform-saasservicemgmt/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-scheduler/noxfile.py b/packages/google-cloud-scheduler/noxfile.py index 55917f9775bc..c543b5965771 100644 --- a/packages/google-cloud-scheduler/noxfile.py +++ b/packages/google-cloud-scheduler/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-secret-manager/noxfile.py b/packages/google-cloud-secret-manager/noxfile.py index 3efeca5e9834..218389fd19b3 100644 --- a/packages/google-cloud-secret-manager/noxfile.py +++ b/packages/google-cloud-secret-manager/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-securesourcemanager/noxfile.py b/packages/google-cloud-securesourcemanager/noxfile.py index 1f33a21f0c23..579fa9537b6e 100644 --- a/packages/google-cloud-securesourcemanager/noxfile.py +++ b/packages/google-cloud-securesourcemanager/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-security-publicca/noxfile.py b/packages/google-cloud-security-publicca/noxfile.py index e7c9130eecea..328d609feb52 100644 --- a/packages/google-cloud-security-publicca/noxfile.py +++ b/packages/google-cloud-security-publicca/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-securitycenter/noxfile.py b/packages/google-cloud-securitycenter/noxfile.py index f0c5e28a829e..9ddf3849596e 100644 --- a/packages/google-cloud-securitycenter/noxfile.py +++ b/packages/google-cloud-securitycenter/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-securitycentermanagement/noxfile.py b/packages/google-cloud-securitycentermanagement/noxfile.py index 6a6d67de2999..d498b93536d2 100644 --- a/packages/google-cloud-securitycentermanagement/noxfile.py +++ b/packages/google-cloud-securitycentermanagement/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-service-control/noxfile.py b/packages/google-cloud-service-control/noxfile.py index 3d3b1d64d329..fc37980e12aa 100644 --- a/packages/google-cloud-service-control/noxfile.py +++ b/packages/google-cloud-service-control/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-service-directory/noxfile.py b/packages/google-cloud-service-directory/noxfile.py index 70e9c93bbe31..dfafd64c6340 100644 --- a/packages/google-cloud-service-directory/noxfile.py +++ b/packages/google-cloud-service-directory/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-service-management/noxfile.py b/packages/google-cloud-service-management/noxfile.py index b647a373a1ed..8ed55b895a38 100644 --- a/packages/google-cloud-service-management/noxfile.py +++ b/packages/google-cloud-service-management/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-service-usage/noxfile.py b/packages/google-cloud-service-usage/noxfile.py index 257a0a3d32c2..3cfb046d24da 100644 --- a/packages/google-cloud-service-usage/noxfile.py +++ b/packages/google-cloud-service-usage/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-servicehealth/noxfile.py b/packages/google-cloud-servicehealth/noxfile.py index 0fc8677b4458..e965bb7ed2bb 100644 --- a/packages/google-cloud-servicehealth/noxfile.py +++ b/packages/google-cloud-servicehealth/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-shell/noxfile.py b/packages/google-cloud-shell/noxfile.py index e28e2365335d..f9a18094cc29 100644 --- a/packages/google-cloud-shell/noxfile.py +++ b/packages/google-cloud-shell/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-source-context/noxfile.py b/packages/google-cloud-source-context/noxfile.py index 6488b4a11907..6b328821d331 100644 --- a/packages/google-cloud-source-context/noxfile.py +++ b/packages/google-cloud-source-context/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-spanner-dbapi-driver/noxfile.py b/packages/google-cloud-spanner-dbapi-driver/noxfile.py index 2fedee7ee5af..d4ee7bd3e4a4 100644 --- a/packages/google-cloud-spanner-dbapi-driver/noxfile.py +++ b/packages/google-cloud-spanner-dbapi-driver/noxfile.py @@ -94,6 +94,7 @@ "lint", "lint_setup_py", "docs", + "import_profile", ] # Error if a python version is missing @@ -604,3 +605,11 @@ def install(session): Install locally """ session.install("-e", ".") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-spanner/noxfile.py b/packages/google-cloud-spanner/noxfile.py index fa74716b8142..d33ab2281b90 100644 --- a/packages/google-cloud-spanner/noxfile.py +++ b/packages/google-cloud-spanner/noxfile.py @@ -848,3 +848,19 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-speech/noxfile.py b/packages/google-cloud-speech/noxfile.py index bc07809189ba..41f334557c47 100644 --- a/packages/google-cloud-speech/noxfile.py +++ b/packages/google-cloud-speech/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -638,3 +639,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-storage-control/noxfile.py b/packages/google-cloud-storage-control/noxfile.py index b4ade172c441..6cb99e501121 100644 --- a/packages/google-cloud-storage-control/noxfile.py +++ b/packages/google-cloud-storage-control/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-storage-transfer/noxfile.py b/packages/google-cloud-storage-transfer/noxfile.py index ef9feee7ac3a..59fc64f5be82 100644 --- a/packages/google-cloud-storage-transfer/noxfile.py +++ b/packages/google-cloud-storage-transfer/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-storage/noxfile.py b/packages/google-cloud-storage/noxfile.py index 6e8d41c60b3d..8de52914a8bf 100644 --- a/packages/google-cloud-storage/noxfile.py +++ b/packages/google-cloud-storage/noxfile.py @@ -94,6 +94,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -712,3 +713,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") diff --git a/packages/google-cloud-storagebatchoperations/noxfile.py b/packages/google-cloud-storagebatchoperations/noxfile.py index dbd49e2ac733..dcff2dcbdfe3 100644 --- a/packages/google-cloud-storagebatchoperations/noxfile.py +++ b/packages/google-cloud-storagebatchoperations/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-storageinsights/noxfile.py b/packages/google-cloud-storageinsights/noxfile.py index dfe9e473684a..b8d8913706b6 100644 --- a/packages/google-cloud-storageinsights/noxfile.py +++ b/packages/google-cloud-storageinsights/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-support/noxfile.py b/packages/google-cloud-support/noxfile.py index f5db58067a57..e7a82c36d248 100644 --- a/packages/google-cloud-support/noxfile.py +++ b/packages/google-cloud-support/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-talent/noxfile.py b/packages/google-cloud-talent/noxfile.py index c77bb19d1a87..f723f738b8a7 100644 --- a/packages/google-cloud-talent/noxfile.py +++ b/packages/google-cloud-talent/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-tasks/noxfile.py b/packages/google-cloud-tasks/noxfile.py index 5d43c1960802..2c0d71024b1e 100644 --- a/packages/google-cloud-tasks/noxfile.py +++ b/packages/google-cloud-tasks/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-telcoautomation/noxfile.py b/packages/google-cloud-telcoautomation/noxfile.py index 0516d14eba3d..004876169e8e 100644 --- a/packages/google-cloud-telcoautomation/noxfile.py +++ b/packages/google-cloud-telcoautomation/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-testutils/noxfile.py b/packages/google-cloud-testutils/noxfile.py index 0e86a298190e..5c8a99aa725f 100644 --- a/packages/google-cloud-testutils/noxfile.py +++ b/packages/google-cloud-testutils/noxfile.py @@ -383,3 +383,19 @@ def core_deps_from_source(session): "py.test", "tests/unit", ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") diff --git a/packages/google-cloud-texttospeech/noxfile.py b/packages/google-cloud-texttospeech/noxfile.py index b5467a458b91..fbe8bdfe764d 100644 --- a/packages/google-cloud-texttospeech/noxfile.py +++ b/packages/google-cloud-texttospeech/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-tpu/noxfile.py b/packages/google-cloud-tpu/noxfile.py index ad1769c6ddb5..d2ec5370f16b 100644 --- a/packages/google-cloud-tpu/noxfile.py +++ b/packages/google-cloud-tpu/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-trace/noxfile.py b/packages/google-cloud-trace/noxfile.py index 39a6649e1562..65e68e470dac 100644 --- a/packages/google-cloud-trace/noxfile.py +++ b/packages/google-cloud-trace/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-translate/noxfile.py b/packages/google-cloud-translate/noxfile.py index 0f6ce885ea75..f747f8763d1c 100644 --- a/packages/google-cloud-translate/noxfile.py +++ b/packages/google-cloud-translate/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-vectorsearch/noxfile.py b/packages/google-cloud-vectorsearch/noxfile.py index a0a96a3b681b..b29eb619e34e 100644 --- a/packages/google-cloud-vectorsearch/noxfile.py +++ b/packages/google-cloud-vectorsearch/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-video-live-stream/noxfile.py b/packages/google-cloud-video-live-stream/noxfile.py index f655209973ee..7f0b861f20eb 100644 --- a/packages/google-cloud-video-live-stream/noxfile.py +++ b/packages/google-cloud-video-live-stream/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-video-stitcher/noxfile.py b/packages/google-cloud-video-stitcher/noxfile.py index 0aee9c67760b..174ad4aad5f5 100644 --- a/packages/google-cloud-video-stitcher/noxfile.py +++ b/packages/google-cloud-video-stitcher/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-video-transcoder/noxfile.py b/packages/google-cloud-video-transcoder/noxfile.py index 6947719b3abd..7b920ab77a2a 100644 --- a/packages/google-cloud-video-transcoder/noxfile.py +++ b/packages/google-cloud-video-transcoder/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-videointelligence/noxfile.py b/packages/google-cloud-videointelligence/noxfile.py index ea240e5ae562..056ab3247553 100644 --- a/packages/google-cloud-videointelligence/noxfile.py +++ b/packages/google-cloud-videointelligence/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-vision/noxfile.py b/packages/google-cloud-vision/noxfile.py index a8c68f537b0c..861411feceee 100644 --- a/packages/google-cloud-vision/noxfile.py +++ b/packages/google-cloud-vision/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -638,3 +639,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-visionai/noxfile.py b/packages/google-cloud-visionai/noxfile.py index 14c9964d9a0e..203febe58b09 100644 --- a/packages/google-cloud-visionai/noxfile.py +++ b/packages/google-cloud-visionai/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-vm-migration/noxfile.py b/packages/google-cloud-vm-migration/noxfile.py index d8f091d84d1d..64baa3759372 100644 --- a/packages/google-cloud-vm-migration/noxfile.py +++ b/packages/google-cloud-vm-migration/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-vmwareengine/noxfile.py b/packages/google-cloud-vmwareengine/noxfile.py index 7f6b1caa7cca..3c01dc333fc4 100644 --- a/packages/google-cloud-vmwareengine/noxfile.py +++ b/packages/google-cloud-vmwareengine/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-vpc-access/noxfile.py b/packages/google-cloud-vpc-access/noxfile.py index a7fb5d0c91e1..40b55c25b399 100644 --- a/packages/google-cloud-vpc-access/noxfile.py +++ b/packages/google-cloud-vpc-access/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-webrisk/noxfile.py b/packages/google-cloud-webrisk/noxfile.py index 0f2c3773d9fe..35b79e79e66c 100644 --- a/packages/google-cloud-webrisk/noxfile.py +++ b/packages/google-cloud-webrisk/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-websecurityscanner/noxfile.py b/packages/google-cloud-websecurityscanner/noxfile.py index 9f29ec42138c..300b9c452da7 100644 --- a/packages/google-cloud-websecurityscanner/noxfile.py +++ b/packages/google-cloud-websecurityscanner/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-workflows/noxfile.py b/packages/google-cloud-workflows/noxfile.py index 1dcb81730459..a348eb3663c7 100644 --- a/packages/google-cloud-workflows/noxfile.py +++ b/packages/google-cloud-workflows/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-workloadmanager/noxfile.py b/packages/google-cloud-workloadmanager/noxfile.py index b6227bea2e3b..a1b67a1b2a66 100644 --- a/packages/google-cloud-workloadmanager/noxfile.py +++ b/packages/google-cloud-workloadmanager/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-workstations/noxfile.py b/packages/google-cloud-workstations/noxfile.py index 29ad30aa8dce..be92dab6c22f 100644 --- a/packages/google-cloud-workstations/noxfile.py +++ b/packages/google-cloud-workstations/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-crc32c/noxfile.py b/packages/google-crc32c/noxfile.py index b44c502ccd0c..9115a55ddc00 100644 --- a/packages/google-crc32c/noxfile.py +++ b/packages/google-crc32c/noxfile.py @@ -184,3 +184,19 @@ def docs(session): def docfx(session): """Run all docfx tests.""" session.skip("Docfx tests are not supported") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") diff --git a/packages/google-developer-knowledge/noxfile.py b/packages/google-developer-knowledge/noxfile.py index 24048446e495..97533cf2b865 100644 --- a/packages/google-developer-knowledge/noxfile.py +++ b/packages/google-developer-knowledge/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-devicesandservices-health/noxfile.py b/packages/google-devicesandservices-health/noxfile.py index 167314ff8a7a..8a4a9650142a 100644 --- a/packages/google-devicesandservices-health/noxfile.py +++ b/packages/google-devicesandservices-health/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-geo-type/noxfile.py b/packages/google-geo-type/noxfile.py index c7dd9bef9aaa..5fe773718b9e 100644 --- a/packages/google-geo-type/noxfile.py +++ b/packages/google-geo-type/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-addressvalidation/noxfile.py b/packages/google-maps-addressvalidation/noxfile.py index 680ee645d9d6..277a94658afe 100644 --- a/packages/google-maps-addressvalidation/noxfile.py +++ b/packages/google-maps-addressvalidation/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-areainsights/noxfile.py b/packages/google-maps-areainsights/noxfile.py index 6c48887a54f5..7379c5b48709 100644 --- a/packages/google-maps-areainsights/noxfile.py +++ b/packages/google-maps-areainsights/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-fleetengine-delivery/noxfile.py b/packages/google-maps-fleetengine-delivery/noxfile.py index 965946a51d4c..8adc77c27665 100644 --- a/packages/google-maps-fleetengine-delivery/noxfile.py +++ b/packages/google-maps-fleetengine-delivery/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-fleetengine/noxfile.py b/packages/google-maps-fleetengine/noxfile.py index a4e7bf463821..a691ebc9a9a6 100644 --- a/packages/google-maps-fleetengine/noxfile.py +++ b/packages/google-maps-fleetengine/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-geocode/noxfile.py b/packages/google-maps-geocode/noxfile.py index 6a24a982cd73..742c66f86296 100644 --- a/packages/google-maps-geocode/noxfile.py +++ b/packages/google-maps-geocode/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-mapmanagement/noxfile.py b/packages/google-maps-mapmanagement/noxfile.py index 253e9b89e435..0da377a91a1e 100644 --- a/packages/google-maps-mapmanagement/noxfile.py +++ b/packages/google-maps-mapmanagement/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-mapsplatformdatasets/noxfile.py b/packages/google-maps-mapsplatformdatasets/noxfile.py index d04d30a53abe..f60a76ce45bc 100644 --- a/packages/google-maps-mapsplatformdatasets/noxfile.py +++ b/packages/google-maps-mapsplatformdatasets/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-navconnect/noxfile.py b/packages/google-maps-navconnect/noxfile.py index 1d057e793d4b..79c850d7900e 100644 --- a/packages/google-maps-navconnect/noxfile.py +++ b/packages/google-maps-navconnect/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-places/noxfile.py b/packages/google-maps-places/noxfile.py index e27fd8dfee63..89dbb4edbb97 100644 --- a/packages/google-maps-places/noxfile.py +++ b/packages/google-maps-places/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-routeoptimization/noxfile.py b/packages/google-maps-routeoptimization/noxfile.py index 8293b48192cf..5f59de6b8f42 100644 --- a/packages/google-maps-routeoptimization/noxfile.py +++ b/packages/google-maps-routeoptimization/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-routing/noxfile.py b/packages/google-maps-routing/noxfile.py index e2059db87494..f28fb8b80931 100644 --- a/packages/google-maps-routing/noxfile.py +++ b/packages/google-maps-routing/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-solar/noxfile.py b/packages/google-maps-solar/noxfile.py index f08fec5fb5d2..0607c0b92610 100644 --- a/packages/google-maps-solar/noxfile.py +++ b/packages/google-maps-solar/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-resumable-media/noxfile.py b/packages/google-resumable-media/noxfile.py index a1c1ae199709..aa9af0aa84b4 100644 --- a/packages/google-resumable-media/noxfile.py +++ b/packages/google-resumable-media/noxfile.py @@ -448,3 +448,19 @@ def core_deps_from_source(session): os.path.join("tests_async", "unit"), *session.posargs, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-css/noxfile.py b/packages/google-shopping-css/noxfile.py index 02e587c9552e..2e307140ce59 100644 --- a/packages/google-shopping-css/noxfile.py +++ b/packages/google-shopping-css/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-accounts/noxfile.py b/packages/google-shopping-merchant-accounts/noxfile.py index 0616e719e46a..8d365554cee4 100644 --- a/packages/google-shopping-merchant-accounts/noxfile.py +++ b/packages/google-shopping-merchant-accounts/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-conversions/noxfile.py b/packages/google-shopping-merchant-conversions/noxfile.py index a68d0e59fb95..287a3b04e7e0 100644 --- a/packages/google-shopping-merchant-conversions/noxfile.py +++ b/packages/google-shopping-merchant-conversions/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-datasources/noxfile.py b/packages/google-shopping-merchant-datasources/noxfile.py index a127b28df77e..d51b6fcbf626 100644 --- a/packages/google-shopping-merchant-datasources/noxfile.py +++ b/packages/google-shopping-merchant-datasources/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-inventories/noxfile.py b/packages/google-shopping-merchant-inventories/noxfile.py index 0e2b1e69e4c3..cfb5aca4ff38 100644 --- a/packages/google-shopping-merchant-inventories/noxfile.py +++ b/packages/google-shopping-merchant-inventories/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-issueresolution/noxfile.py b/packages/google-shopping-merchant-issueresolution/noxfile.py index 2969c82734bc..202a2596398e 100644 --- a/packages/google-shopping-merchant-issueresolution/noxfile.py +++ b/packages/google-shopping-merchant-issueresolution/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-lfp/noxfile.py b/packages/google-shopping-merchant-lfp/noxfile.py index 9afbefc28ecc..ec159991de76 100644 --- a/packages/google-shopping-merchant-lfp/noxfile.py +++ b/packages/google-shopping-merchant-lfp/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-notifications/noxfile.py b/packages/google-shopping-merchant-notifications/noxfile.py index 469d1b1ee453..7dc35edea60b 100644 --- a/packages/google-shopping-merchant-notifications/noxfile.py +++ b/packages/google-shopping-merchant-notifications/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-ordertracking/noxfile.py b/packages/google-shopping-merchant-ordertracking/noxfile.py index 8d7bfd0b33cb..afbc0973e1c6 100644 --- a/packages/google-shopping-merchant-ordertracking/noxfile.py +++ b/packages/google-shopping-merchant-ordertracking/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-products/noxfile.py b/packages/google-shopping-merchant-products/noxfile.py index f4f76c8c8be5..c937eef5c181 100644 --- a/packages/google-shopping-merchant-products/noxfile.py +++ b/packages/google-shopping-merchant-products/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-productstudio/noxfile.py b/packages/google-shopping-merchant-productstudio/noxfile.py index dbb49a1245ba..65068f4ef380 100644 --- a/packages/google-shopping-merchant-productstudio/noxfile.py +++ b/packages/google-shopping-merchant-productstudio/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-promotions/noxfile.py b/packages/google-shopping-merchant-promotions/noxfile.py index 1202be8a0b25..34be9afe1f38 100644 --- a/packages/google-shopping-merchant-promotions/noxfile.py +++ b/packages/google-shopping-merchant-promotions/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-quota/noxfile.py b/packages/google-shopping-merchant-quota/noxfile.py index a6fe68f6bdbc..ffc5e63703a7 100644 --- a/packages/google-shopping-merchant-quota/noxfile.py +++ b/packages/google-shopping-merchant-quota/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-reports/noxfile.py b/packages/google-shopping-merchant-reports/noxfile.py index 2d85b52ed1b7..f8c109625f8a 100644 --- a/packages/google-shopping-merchant-reports/noxfile.py +++ b/packages/google-shopping-merchant-reports/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-reviews/noxfile.py b/packages/google-shopping-merchant-reviews/noxfile.py index 676575644598..edcb7f0c7283 100644 --- a/packages/google-shopping-merchant-reviews/noxfile.py +++ b/packages/google-shopping-merchant-reviews/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-type/noxfile.py b/packages/google-shopping-type/noxfile.py index ca47d4a3725e..a138dd4af611 100644 --- a/packages/google-shopping-type/noxfile.py +++ b/packages/google-shopping-type/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "google", "--iterations", "10") diff --git a/packages/googleapis-common-protos/noxfile.py b/packages/googleapis-common-protos/noxfile.py index ce20cdcfcad8..435fb3289b48 100644 --- a/packages/googleapis-common-protos/noxfile.py +++ b/packages/googleapis-common-protos/noxfile.py @@ -85,6 +85,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -599,3 +600,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") diff --git a/packages/grafeas/noxfile.py b/packages/grafeas/noxfile.py index d0d5199c2bd5..571fa60e7d41 100644 --- a/packages/grafeas/noxfile.py +++ b/packages/grafeas/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "grafeas", "--iterations", "10") diff --git a/packages/grpc-google-iam-v1/noxfile.py b/packages/grpc-google-iam-v1/noxfile.py index 6d0703ed100b..8b67d7d6ab9a 100644 --- a/packages/grpc-google-iam-v1/noxfile.py +++ b/packages/grpc-google-iam-v1/noxfile.py @@ -85,6 +85,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -584,3 +585,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") diff --git a/packages/pandas-gbq/noxfile.py b/packages/pandas-gbq/noxfile.py index 8e58d09628bc..e8d0fff76e99 100644 --- a/packages/pandas-gbq/noxfile.py +++ b/packages/pandas-gbq/noxfile.py @@ -110,6 +110,7 @@ def wrapper(*args, **kwargs): "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -595,3 +596,11 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") diff --git a/packages/proto-plus/noxfile.py b/packages/proto-plus/noxfile.py index 4e07083cd49c..2e9fec7ff929 100644 --- a/packages/proto-plus/noxfile.py +++ b/packages/proto-plus/noxfile.py @@ -353,3 +353,19 @@ def format(session): "--line-length=88", *LINT_PATHS, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") diff --git a/packages/sqlalchemy-bigquery/noxfile.py b/packages/sqlalchemy-bigquery/noxfile.py index b1e6b068c872..a79a915fea79 100644 --- a/packages/sqlalchemy-bigquery/noxfile.py +++ b/packages/sqlalchemy-bigquery/noxfile.py @@ -742,3 +742,19 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") diff --git a/packages/sqlalchemy-spanner/noxfile.py b/packages/sqlalchemy-spanner/noxfile.py index 187d4e7e8924..a840d2bf1981 100644 --- a/packages/sqlalchemy-spanner/noxfile.py +++ b/packages/sqlalchemy-spanner/noxfile.py @@ -604,3 +604,19 @@ def format(session): "--line-length=88", *LINT_PATHS, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + session.install(".") + profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") + session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") From 8ccfb28bf559aef0514bf8d346cb4c7d43595a78 Mon Sep 17 00:00:00 2001 From: Heba Alazzeh Date: Wed, 8 Jul 2026 02:54:37 +0000 Subject: [PATCH 04/13] fix(ci): gracefully skip import_profile session if profiler script missing --- packages/bigframes/noxfile.py | 14 ++++++++++---- packages/bigquery-magics/noxfile.py | 14 ++++++++++---- packages/db-dtypes/noxfile.py | 14 ++++++++++---- packages/django-google-spanner/noxfile.py | 14 ++++++++++---- .../gapic-generator/gapic/templates/noxfile.py.j2 | 9 ++++++--- packages/gapic-generator/noxfile.py | 14 ++++++++++---- .../tests/integration/goldens/asset/noxfile.py | 7 +++++-- .../integration/goldens/credentials/noxfile.py | 7 +++++-- .../tests/integration/goldens/eventarc/noxfile.py | 7 +++++-- .../tests/integration/goldens/logging/noxfile.py | 7 +++++-- .../goldens/logging_internal/noxfile.py | 7 +++++-- .../tests/integration/goldens/redis/noxfile.py | 7 +++++-- .../integration/goldens/redis_selective/noxfile.py | 7 +++++-- .../goldens/storagebatchoperations/noxfile.py | 7 +++++-- packages/gcp-sphinx-docfx-yaml/noxfile.py | 14 ++++++++++---- packages/google-ads-admanager/noxfile.py | 7 +++++-- packages/google-ads-datamanager/noxfile.py | 7 +++++-- .../google-ads-marketingplatform-admin/noxfile.py | 7 +++++-- packages/google-ai-generativelanguage/noxfile.py | 7 +++++-- packages/google-analytics-admin/noxfile.py | 7 +++++-- packages/google-analytics-data/noxfile.py | 7 +++++-- packages/google-api-core/noxfile.py | 14 ++++++++++---- packages/google-apps-card/noxfile.py | 7 +++++-- packages/google-apps-chat/noxfile.py | 7 +++++-- .../google-apps-events-subscriptions/noxfile.py | 7 +++++-- packages/google-apps-meet/noxfile.py | 7 +++++-- packages/google-apps-script-type/noxfile.py | 7 +++++-- packages/google-area120-tables/noxfile.py | 7 +++++-- packages/google-auth-httplib2/noxfile.py | 14 ++++++++++---- packages/google-auth-oauthlib/noxfile.py | 14 ++++++++++---- packages/google-auth/noxfile.py | 7 +++++-- packages/google-backstory/noxfile.py | 7 +++++-- packages/google-cloud-access-approval/noxfile.py | 7 +++++-- .../google-cloud-access-context-manager/noxfile.py | 7 +++++-- .../google-cloud-advisorynotifications/noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- packages/google-cloud-agentregistry/noxfile.py | 7 +++++-- .../google-cloud-alloydb-connectors/noxfile.py | 7 +++++-- packages/google-cloud-alloydb/noxfile.py | 7 +++++-- packages/google-cloud-api-gateway/noxfile.py | 7 +++++-- packages/google-cloud-api-keys/noxfile.py | 7 +++++-- packages/google-cloud-apigee-connect/noxfile.py | 7 +++++-- packages/google-cloud-apigee-registry/noxfile.py | 7 +++++-- packages/google-cloud-apihub/noxfile.py | 7 +++++-- packages/google-cloud-apiregistry/noxfile.py | 7 +++++-- packages/google-cloud-appengine-admin/noxfile.py | 7 +++++-- packages/google-cloud-appengine-logging/noxfile.py | 7 +++++-- packages/google-cloud-apphub/noxfile.py | 7 +++++-- packages/google-cloud-appoptimize/noxfile.py | 7 +++++-- packages/google-cloud-artifact-registry/noxfile.py | 7 +++++-- packages/google-cloud-asset/noxfile.py | 7 +++++-- packages/google-cloud-assured-workloads/noxfile.py | 7 +++++-- packages/google-cloud-audit-log/noxfile.py | 7 +++++-- packages/google-cloud-auditmanager/noxfile.py | 7 +++++-- packages/google-cloud-automl/noxfile.py | 7 +++++-- packages/google-cloud-backupdr/noxfile.py | 7 +++++-- .../google-cloud-bare-metal-solution/noxfile.py | 7 +++++-- packages/google-cloud-batch/noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- .../google-cloud-beyondcorp-appgateways/noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- packages/google-cloud-biglake-hive/noxfile.py | 7 +++++-- packages/google-cloud-biglake/noxfile.py | 7 +++++-- .../google-cloud-bigquery-analyticshub/noxfile.py | 7 +++++-- packages/google-cloud-bigquery-biglake/noxfile.py | 7 +++++-- .../google-cloud-bigquery-connection/noxfile.py | 7 +++++-- .../google-cloud-bigquery-data-exchange/noxfile.py | 7 +++++-- .../google-cloud-bigquery-datapolicies/noxfile.py | 7 +++++-- .../google-cloud-bigquery-datatransfer/noxfile.py | 7 +++++-- packages/google-cloud-bigquery-logging/noxfile.py | 7 +++++-- .../google-cloud-bigquery-migration/noxfile.py | 7 +++++-- .../google-cloud-bigquery-reservation/noxfile.py | 7 +++++-- packages/google-cloud-bigquery-storage/noxfile.py | 7 +++++-- packages/google-cloud-bigquery/noxfile.py | 14 ++++++++++---- packages/google-cloud-bigtable/noxfile.py | 14 ++++++++++---- packages/google-cloud-billing-budgets/noxfile.py | 7 +++++-- packages/google-cloud-billing/noxfile.py | 7 +++++-- .../google-cloud-binary-authorization/noxfile.py | 7 +++++-- packages/google-cloud-build/noxfile.py | 7 +++++-- packages/google-cloud-capacityplanner/noxfile.py | 7 +++++-- .../google-cloud-certificate-manager/noxfile.py | 7 +++++-- packages/google-cloud-ces/noxfile.py | 7 +++++-- packages/google-cloud-channel/noxfile.py | 7 +++++-- packages/google-cloud-chronicle/noxfile.py | 7 +++++-- .../google-cloud-cloudcontrolspartner/noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- packages/google-cloud-common/noxfile.py | 7 +++++-- packages/google-cloud-compute-v1beta/noxfile.py | 7 +++++-- packages/google-cloud-compute/noxfile.py | 7 +++++-- .../google-cloud-confidentialcomputing/noxfile.py | 7 +++++-- packages/google-cloud-config/noxfile.py | 7 +++++-- packages/google-cloud-configdelivery/noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- packages/google-cloud-container/noxfile.py | 7 +++++-- packages/google-cloud-containeranalysis/noxfile.py | 7 +++++-- packages/google-cloud-contentwarehouse/noxfile.py | 7 +++++-- packages/google-cloud-core/noxfile.py | 14 ++++++++++---- packages/google-cloud-data-fusion/noxfile.py | 7 +++++-- packages/google-cloud-data-qna/noxfile.py | 7 +++++-- packages/google-cloud-databasecenter/noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- .../google-cloud-datacatalog-lineage/noxfile.py | 7 +++++-- packages/google-cloud-datacatalog/noxfile.py | 7 +++++-- packages/google-cloud-dataflow-client/noxfile.py | 7 +++++-- packages/google-cloud-dataform/noxfile.py | 7 +++++-- packages/google-cloud-datalabeling/noxfile.py | 7 +++++-- packages/google-cloud-dataplex/noxfile.py | 7 +++++-- .../google-cloud-dataproc-metastore/noxfile.py | 7 +++++-- packages/google-cloud-dataproc/noxfile.py | 7 +++++-- packages/google-cloud-datastore/noxfile.py | 7 +++++-- packages/google-cloud-datastream/noxfile.py | 7 +++++-- packages/google-cloud-deploy/noxfile.py | 7 +++++-- packages/google-cloud-developerconnect/noxfile.py | 7 +++++-- packages/google-cloud-devicestreaming/noxfile.py | 7 +++++-- packages/google-cloud-dialogflow-cx/noxfile.py | 7 +++++-- packages/google-cloud-dialogflow/noxfile.py | 7 +++++-- packages/google-cloud-discoveryengine/noxfile.py | 7 +++++-- packages/google-cloud-dlp/noxfile.py | 7 +++++-- packages/google-cloud-dms/noxfile.py | 7 +++++-- packages/google-cloud-dns/noxfile.py | 14 ++++++++++---- .../google-cloud-documentai-toolbox/noxfile.py | 14 ++++++++++---- packages/google-cloud-documentai/noxfile.py | 7 +++++-- packages/google-cloud-domains/noxfile.py | 7 +++++-- packages/google-cloud-edgecontainer/noxfile.py | 7 +++++-- packages/google-cloud-edgenetwork/noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- packages/google-cloud-error-reporting/noxfile.py | 7 +++++-- .../google-cloud-essential-contacts/noxfile.py | 7 +++++-- .../google-cloud-eventarc-publishing/noxfile.py | 7 +++++-- packages/google-cloud-eventarc/noxfile.py | 7 +++++-- packages/google-cloud-filestore/noxfile.py | 7 +++++-- packages/google-cloud-financialservices/noxfile.py | 7 +++++-- packages/google-cloud-firestore/noxfile.py | 7 +++++-- packages/google-cloud-functions/noxfile.py | 7 +++++-- .../google-cloud-gdchardwaremanagement/noxfile.py | 7 +++++-- .../google-cloud-geminidataanalytics/noxfile.py | 7 +++++-- packages/google-cloud-gke-backup/noxfile.py | 7 +++++-- .../google-cloud-gke-connect-gateway/noxfile.py | 7 +++++-- packages/google-cloud-gke-hub/noxfile.py | 7 +++++-- packages/google-cloud-gke-multicloud/noxfile.py | 7 +++++-- packages/google-cloud-gkerecommender/noxfile.py | 7 +++++-- packages/google-cloud-gsuiteaddons/noxfile.py | 7 +++++-- .../google-cloud-hypercomputecluster/noxfile.py | 7 +++++-- packages/google-cloud-iam-logging/noxfile.py | 7 +++++-- packages/google-cloud-iam/noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- packages/google-cloud-iap/noxfile.py | 7 +++++-- packages/google-cloud-ids/noxfile.py | 7 +++++-- packages/google-cloud-kms-inventory/noxfile.py | 7 +++++-- packages/google-cloud-kms/noxfile.py | 7 +++++-- packages/google-cloud-language/noxfile.py | 7 +++++-- packages/google-cloud-licensemanager/noxfile.py | 7 +++++-- packages/google-cloud-life-sciences/noxfile.py | 7 +++++-- packages/google-cloud-locationfinder/noxfile.py | 7 +++++-- packages/google-cloud-logging/noxfile.py | 7 +++++-- packages/google-cloud-lustre/noxfile.py | 7 +++++-- packages/google-cloud-maintenance-api/noxfile.py | 7 +++++-- .../google-cloud-managed-identities/noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- packages/google-cloud-managedkafka/noxfile.py | 7 +++++-- packages/google-cloud-media-translation/noxfile.py | 7 +++++-- packages/google-cloud-memcache/noxfile.py | 7 +++++-- packages/google-cloud-memorystore/noxfile.py | 7 +++++-- packages/google-cloud-migrationcenter/noxfile.py | 7 +++++-- packages/google-cloud-modelarmor/noxfile.py | 7 +++++-- .../google-cloud-monitoring-dashboards/noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- packages/google-cloud-monitoring/noxfile.py | 7 +++++-- packages/google-cloud-ndb/noxfile.py | 14 ++++++++++---- packages/google-cloud-netapp/noxfile.py | 7 +++++-- .../google-cloud-network-connectivity/noxfile.py | 7 +++++-- .../google-cloud-network-management/noxfile.py | 7 +++++-- packages/google-cloud-network-security/noxfile.py | 7 +++++-- packages/google-cloud-network-services/noxfile.py | 7 +++++-- packages/google-cloud-notebooks/noxfile.py | 7 +++++-- packages/google-cloud-optimization/noxfile.py | 7 +++++-- packages/google-cloud-oracledatabase/noxfile.py | 7 +++++-- .../google-cloud-orchestration-airflow/noxfile.py | 7 +++++-- packages/google-cloud-org-policy/noxfile.py | 7 +++++-- packages/google-cloud-os-config/noxfile.py | 7 +++++-- packages/google-cloud-os-login/noxfile.py | 7 +++++-- packages/google-cloud-parallelstore/noxfile.py | 7 +++++-- packages/google-cloud-parametermanager/noxfile.py | 7 +++++-- .../google-cloud-phishing-protection/noxfile.py | 7 +++++-- .../google-cloud-policy-troubleshooter/noxfile.py | 7 +++++-- packages/google-cloud-policysimulator/noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- packages/google-cloud-private-ca/noxfile.py | 7 +++++-- packages/google-cloud-private-catalog/noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- packages/google-cloud-pubsub/noxfile.py | 14 ++++++++++---- packages/google-cloud-quotas/noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- .../google-cloud-recaptcha-enterprise/noxfile.py | 7 +++++-- .../google-cloud-recommendations-ai/noxfile.py | 7 +++++-- packages/google-cloud-recommender/noxfile.py | 7 +++++-- packages/google-cloud-redis-cluster/noxfile.py | 7 +++++-- packages/google-cloud-redis/noxfile.py | 7 +++++-- packages/google-cloud-resource-manager/noxfile.py | 7 +++++-- packages/google-cloud-retail/noxfile.py | 7 +++++-- packages/google-cloud-run/noxfile.py | 7 +++++-- packages/google-cloud-runtimeconfig/noxfile.py | 14 ++++++++++---- .../noxfile.py | 7 +++++-- packages/google-cloud-scheduler/noxfile.py | 7 +++++-- packages/google-cloud-secret-manager/noxfile.py | 7 +++++-- .../google-cloud-securesourcemanager/noxfile.py | 7 +++++-- packages/google-cloud-security-publicca/noxfile.py | 7 +++++-- packages/google-cloud-securitycenter/noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- packages/google-cloud-service-control/noxfile.py | 7 +++++-- packages/google-cloud-service-directory/noxfile.py | 7 +++++-- .../google-cloud-service-management/noxfile.py | 7 +++++-- packages/google-cloud-service-usage/noxfile.py | 7 +++++-- packages/google-cloud-servicehealth/noxfile.py | 7 +++++-- packages/google-cloud-shell/noxfile.py | 7 +++++-- packages/google-cloud-source-context/noxfile.py | 7 +++++-- .../google-cloud-spanner-dbapi-driver/noxfile.py | 7 +++++-- packages/google-cloud-spanner/noxfile.py | 14 ++++++++++---- packages/google-cloud-speech/noxfile.py | 7 +++++-- packages/google-cloud-storage-control/noxfile.py | 7 +++++-- packages/google-cloud-storage-transfer/noxfile.py | 7 +++++-- packages/google-cloud-storage/noxfile.py | 7 +++++-- .../google-cloud-storagebatchoperations/noxfile.py | 7 +++++-- packages/google-cloud-storageinsights/noxfile.py | 7 +++++-- packages/google-cloud-support/noxfile.py | 7 +++++-- packages/google-cloud-talent/noxfile.py | 7 +++++-- packages/google-cloud-tasks/noxfile.py | 7 +++++-- packages/google-cloud-telcoautomation/noxfile.py | 7 +++++-- packages/google-cloud-testutils/noxfile.py | 14 ++++++++++---- packages/google-cloud-texttospeech/noxfile.py | 7 +++++-- packages/google-cloud-tpu/noxfile.py | 7 +++++-- packages/google-cloud-trace/noxfile.py | 7 +++++-- packages/google-cloud-translate/noxfile.py | 7 +++++-- packages/google-cloud-vectorsearch/noxfile.py | 7 +++++-- packages/google-cloud-video-live-stream/noxfile.py | 7 +++++-- packages/google-cloud-video-stitcher/noxfile.py | 7 +++++-- packages/google-cloud-video-transcoder/noxfile.py | 7 +++++-- packages/google-cloud-videointelligence/noxfile.py | 7 +++++-- packages/google-cloud-vision/noxfile.py | 7 +++++-- packages/google-cloud-visionai/noxfile.py | 7 +++++-- packages/google-cloud-vm-migration/noxfile.py | 7 +++++-- packages/google-cloud-vmwareengine/noxfile.py | 7 +++++-- packages/google-cloud-vpc-access/noxfile.py | 7 +++++-- packages/google-cloud-webrisk/noxfile.py | 7 +++++-- .../google-cloud-websecurityscanner/noxfile.py | 7 +++++-- packages/google-cloud-workflows/noxfile.py | 7 +++++-- packages/google-cloud-workloadmanager/noxfile.py | 7 +++++-- packages/google-cloud-workstations/noxfile.py | 7 +++++-- packages/google-crc32c/noxfile.py | 14 ++++++++++---- packages/google-developer-knowledge/noxfile.py | 7 +++++-- .../google-devicesandservices-health/noxfile.py | 7 +++++-- packages/google-geo-type/noxfile.py | 7 +++++-- packages/google-maps-addressvalidation/noxfile.py | 7 +++++-- packages/google-maps-areainsights/noxfile.py | 7 +++++-- .../google-maps-fleetengine-delivery/noxfile.py | 7 +++++-- packages/google-maps-fleetengine/noxfile.py | 7 +++++-- packages/google-maps-geocode/noxfile.py | 7 +++++-- packages/google-maps-mapmanagement/noxfile.py | 7 +++++-- .../google-maps-mapsplatformdatasets/noxfile.py | 7 +++++-- packages/google-maps-navconnect/noxfile.py | 7 +++++-- packages/google-maps-places/noxfile.py | 7 +++++-- packages/google-maps-routeoptimization/noxfile.py | 7 +++++-- packages/google-maps-routing/noxfile.py | 7 +++++-- packages/google-maps-solar/noxfile.py | 7 +++++-- packages/google-resumable-media/noxfile.py | 14 ++++++++++---- packages/google-shopping-css/noxfile.py | 7 +++++-- .../google-shopping-merchant-accounts/noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- packages/google-shopping-merchant-lfp/noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- .../google-shopping-merchant-products/noxfile.py | 7 +++++-- .../noxfile.py | 7 +++++-- .../google-shopping-merchant-promotions/noxfile.py | 7 +++++-- packages/google-shopping-merchant-quota/noxfile.py | 7 +++++-- .../google-shopping-merchant-reports/noxfile.py | 7 +++++-- .../google-shopping-merchant-reviews/noxfile.py | 7 +++++-- packages/google-shopping-type/noxfile.py | 7 +++++-- packages/googleapis-common-protos/noxfile.py | 7 +++++-- packages/grafeas/noxfile.py | 7 +++++-- packages/grpc-google-iam-v1/noxfile.py | 7 +++++-- packages/pandas-gbq/noxfile.py | 7 +++++-- packages/proto-plus/noxfile.py | 14 ++++++++++---- packages/sqlalchemy-bigquery/noxfile.py | 14 ++++++++++---- packages/sqlalchemy-spanner/noxfile.py | 14 ++++++++++---- 291 files changed, 1576 insertions(+), 631 deletions(-) diff --git a/packages/bigframes/noxfile.py b/packages/bigframes/noxfile.py index 37c41d05645e..496c2d4b1657 100644 --- a/packages/bigframes/noxfile.py +++ b/packages/bigframes/noxfile.py @@ -1097,14 +1097,20 @@ def mypy(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") diff --git a/packages/bigquery-magics/noxfile.py b/packages/bigquery-magics/noxfile.py index 8ab763cdec40..f5a945c2f864 100644 --- a/packages/bigquery-magics/noxfile.py +++ b/packages/bigquery-magics/noxfile.py @@ -551,14 +551,20 @@ def mypy(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") diff --git a/packages/db-dtypes/noxfile.py b/packages/db-dtypes/noxfile.py index 8bc53cd0c1d0..65dc1a722bd6 100644 --- a/packages/db-dtypes/noxfile.py +++ b/packages/db-dtypes/noxfile.py @@ -552,14 +552,20 @@ def mypy(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "db_dtypes", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "db_dtypes", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "db_dtypes", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "db_dtypes", "--iterations", "10") diff --git a/packages/django-google-spanner/noxfile.py b/packages/django-google-spanner/noxfile.py index 0911b8eebcb0..01400f503d73 100644 --- a/packages/django-google-spanner/noxfile.py +++ b/packages/django-google-spanner/noxfile.py @@ -496,14 +496,20 @@ def format(session: nox.sessions.Session) -> None: @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") diff --git a/packages/gapic-generator/gapic/templates/noxfile.py.j2 b/packages/gapic-generator/gapic/templates/noxfile.py.j2 index ec3fe238b5b7..36e693412398 100644 --- a/packages/gapic-generator/gapic/templates/noxfile.py.j2 +++ b/packages/gapic-generator/gapic/templates/noxfile.py.j2 @@ -647,11 +647,14 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") {% if api.naming.module_namespace %} - session.run("python", profiler_script, "--module", "{{ api.naming.module_namespace[0] }}", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "{{ api.naming.module_namespace[0] }}", "--iterations", "10") {% else %} - session.run("python", profiler_script, "--module", "{{ api.naming.versioned_module_name }}", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "{{ api.naming.versioned_module_name }}", "--iterations", "10") {% endif %} {% endblock %} diff --git a/packages/gapic-generator/noxfile.py b/packages/gapic-generator/noxfile.py index 5ae4d6a41f7a..74e399d573e0 100644 --- a/packages/gapic-generator/noxfile.py +++ b/packages/gapic-generator/noxfile.py @@ -852,14 +852,20 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py b/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py index 7a9b2086d467..1885a2683db1 100755 --- a/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py @@ -639,6 +639,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py b/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py index 01077da09e24..e447c81b9dd3 100755 --- a/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py @@ -639,6 +639,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py b/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py index 20fdc24fd81a..e9a6e9779a2b 100755 --- a/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py @@ -639,6 +639,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py b/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py index 0c506da149e6..6ffbbff69aa4 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py @@ -639,6 +639,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py b/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py index 0c506da149e6..6ffbbff69aa4 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py @@ -639,6 +639,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py b/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py index 13bb8c07a21c..855f4d2f0df9 100755 --- a/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py @@ -639,6 +639,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py b/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py index 13bb8c07a21c..855f4d2f0df9 100755 --- a/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py @@ -639,6 +639,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py b/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py index f14e5ef4b463..d6ad1c1638c6 100755 --- a/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py @@ -639,6 +639,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/gcp-sphinx-docfx-yaml/noxfile.py b/packages/gcp-sphinx-docfx-yaml/noxfile.py index d53c29e52dfd..831320d8859c 100644 --- a/packages/gcp-sphinx-docfx-yaml/noxfile.py +++ b/packages/gcp-sphinx-docfx-yaml/noxfile.py @@ -178,14 +178,20 @@ def docfx(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") diff --git a/packages/google-ads-admanager/noxfile.py b/packages/google-ads-admanager/noxfile.py index ca2afd6f48e1..7b5846c6af8c 100644 --- a/packages/google-ads-admanager/noxfile.py +++ b/packages/google-ads-admanager/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-ads-datamanager/noxfile.py b/packages/google-ads-datamanager/noxfile.py index 79465ad9ecce..54b9753ebf22 100644 --- a/packages/google-ads-datamanager/noxfile.py +++ b/packages/google-ads-datamanager/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-ads-marketingplatform-admin/noxfile.py b/packages/google-ads-marketingplatform-admin/noxfile.py index da03039590cd..ce2e6ebac363 100644 --- a/packages/google-ads-marketingplatform-admin/noxfile.py +++ b/packages/google-ads-marketingplatform-admin/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-ai-generativelanguage/noxfile.py b/packages/google-ai-generativelanguage/noxfile.py index b6e1588212de..c0653be6b998 100644 --- a/packages/google-ai-generativelanguage/noxfile.py +++ b/packages/google-ai-generativelanguage/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-analytics-admin/noxfile.py b/packages/google-analytics-admin/noxfile.py index a5b525255184..17843932c73e 100644 --- a/packages/google-analytics-admin/noxfile.py +++ b/packages/google-analytics-admin/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-analytics-data/noxfile.py b/packages/google-analytics-data/noxfile.py index e98dda52579e..59a18e6bbbee 100644 --- a/packages/google-analytics-data/noxfile.py +++ b/packages/google-analytics-data/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-api-core/noxfile.py b/packages/google-api-core/noxfile.py index 76381fb2fa80..ccafe9d306df 100644 --- a/packages/google-api-core/noxfile.py +++ b/packages/google-api-core/noxfile.py @@ -469,14 +469,20 @@ def docfx(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") diff --git a/packages/google-apps-card/noxfile.py b/packages/google-apps-card/noxfile.py index e8bb14c8f4a2..8df8b6008263 100644 --- a/packages/google-apps-card/noxfile.py +++ b/packages/google-apps-card/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-apps-chat/noxfile.py b/packages/google-apps-chat/noxfile.py index 799c357470f5..4a1e1735ef3c 100644 --- a/packages/google-apps-chat/noxfile.py +++ b/packages/google-apps-chat/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-apps-events-subscriptions/noxfile.py b/packages/google-apps-events-subscriptions/noxfile.py index 63282c8337c1..a6fdcd46d2fd 100644 --- a/packages/google-apps-events-subscriptions/noxfile.py +++ b/packages/google-apps-events-subscriptions/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-apps-meet/noxfile.py b/packages/google-apps-meet/noxfile.py index 2d175fc68cab..1549a3d26157 100644 --- a/packages/google-apps-meet/noxfile.py +++ b/packages/google-apps-meet/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-apps-script-type/noxfile.py b/packages/google-apps-script-type/noxfile.py index 79974a529be6..ba75e8ea1712 100644 --- a/packages/google-apps-script-type/noxfile.py +++ b/packages/google-apps-script-type/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-area120-tables/noxfile.py b/packages/google-area120-tables/noxfile.py index f983a841280f..1e79cbee6b3b 100644 --- a/packages/google-area120-tables/noxfile.py +++ b/packages/google-area120-tables/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-auth-httplib2/noxfile.py b/packages/google-auth-httplib2/noxfile.py index 2b8bfd0b5738..69d9e5ec2a03 100644 --- a/packages/google-auth-httplib2/noxfile.py +++ b/packages/google-auth-httplib2/noxfile.py @@ -534,14 +534,20 @@ def core_deps_from_source(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") diff --git a/packages/google-auth-oauthlib/noxfile.py b/packages/google-auth-oauthlib/noxfile.py index fac9e73f3b76..676fc0f6f676 100644 --- a/packages/google-auth-oauthlib/noxfile.py +++ b/packages/google-auth-oauthlib/noxfile.py @@ -479,14 +479,20 @@ def mypy(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google_auth_oauthlib", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google_auth_oauthlib", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google_auth_oauthlib", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google_auth_oauthlib", "--iterations", "10") diff --git a/packages/google-auth/noxfile.py b/packages/google-auth/noxfile.py index eef980a39375..6290254a760c 100644 --- a/packages/google-auth/noxfile.py +++ b/packages/google-auth/noxfile.py @@ -320,6 +320,9 @@ def core_deps_from_source(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-backstory/noxfile.py b/packages/google-backstory/noxfile.py index 68d2459104b1..f6d2d02fc2a5 100644 --- a/packages/google-backstory/noxfile.py +++ b/packages/google-backstory/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-access-approval/noxfile.py b/packages/google-cloud-access-approval/noxfile.py index 95e330555c2c..e534c419d651 100644 --- a/packages/google-cloud-access-approval/noxfile.py +++ b/packages/google-cloud-access-approval/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-access-context-manager/noxfile.py b/packages/google-cloud-access-context-manager/noxfile.py index b92178695792..7f9a8209e9df 100644 --- a/packages/google-cloud-access-context-manager/noxfile.py +++ b/packages/google-cloud-access-context-manager/noxfile.py @@ -583,6 +583,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") diff --git a/packages/google-cloud-advisorynotifications/noxfile.py b/packages/google-cloud-advisorynotifications/noxfile.py index b5b96d5b2ff0..2f88e9557a66 100644 --- a/packages/google-cloud-advisorynotifications/noxfile.py +++ b/packages/google-cloud-advisorynotifications/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-agentidentitycredentials/noxfile.py b/packages/google-cloud-agentidentitycredentials/noxfile.py index 46d10d4e51e5..f9357d466a43 100644 --- a/packages/google-cloud-agentidentitycredentials/noxfile.py +++ b/packages/google-cloud-agentidentitycredentials/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-agentregistry/noxfile.py b/packages/google-cloud-agentregistry/noxfile.py index eca6f6769167..8bf7a77f7ff9 100644 --- a/packages/google-cloud-agentregistry/noxfile.py +++ b/packages/google-cloud-agentregistry/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-alloydb-connectors/noxfile.py b/packages/google-cloud-alloydb-connectors/noxfile.py index c52b728b8992..ee364a7ddb12 100644 --- a/packages/google-cloud-alloydb-connectors/noxfile.py +++ b/packages/google-cloud-alloydb-connectors/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-alloydb/noxfile.py b/packages/google-cloud-alloydb/noxfile.py index 42d769f8f43d..1185272bf86a 100644 --- a/packages/google-cloud-alloydb/noxfile.py +++ b/packages/google-cloud-alloydb/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-api-gateway/noxfile.py b/packages/google-cloud-api-gateway/noxfile.py index 3f298cda6e73..c9a0bdbdb855 100644 --- a/packages/google-cloud-api-gateway/noxfile.py +++ b/packages/google-cloud-api-gateway/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-api-keys/noxfile.py b/packages/google-cloud-api-keys/noxfile.py index f91fe138b7f0..55f5d21afd48 100644 --- a/packages/google-cloud-api-keys/noxfile.py +++ b/packages/google-cloud-api-keys/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-apigee-connect/noxfile.py b/packages/google-cloud-apigee-connect/noxfile.py index 87b894dbc6ab..100ba24c5ffe 100644 --- a/packages/google-cloud-apigee-connect/noxfile.py +++ b/packages/google-cloud-apigee-connect/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-apigee-registry/noxfile.py b/packages/google-cloud-apigee-registry/noxfile.py index 29c04e4dce4f..a6b2b4ba5f48 100644 --- a/packages/google-cloud-apigee-registry/noxfile.py +++ b/packages/google-cloud-apigee-registry/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-apihub/noxfile.py b/packages/google-cloud-apihub/noxfile.py index decdaa88c608..dd5d323c757c 100644 --- a/packages/google-cloud-apihub/noxfile.py +++ b/packages/google-cloud-apihub/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-apiregistry/noxfile.py b/packages/google-cloud-apiregistry/noxfile.py index d170c57f7949..b6c1d6ac7481 100644 --- a/packages/google-cloud-apiregistry/noxfile.py +++ b/packages/google-cloud-apiregistry/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-appengine-admin/noxfile.py b/packages/google-cloud-appengine-admin/noxfile.py index e4eadae1ae75..25883de1067d 100644 --- a/packages/google-cloud-appengine-admin/noxfile.py +++ b/packages/google-cloud-appengine-admin/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-appengine-logging/noxfile.py b/packages/google-cloud-appengine-logging/noxfile.py index b85f344a88ff..55e7593b8934 100644 --- a/packages/google-cloud-appengine-logging/noxfile.py +++ b/packages/google-cloud-appengine-logging/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-apphub/noxfile.py b/packages/google-cloud-apphub/noxfile.py index fbb7567dbcd7..6f90381fde57 100644 --- a/packages/google-cloud-apphub/noxfile.py +++ b/packages/google-cloud-apphub/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-appoptimize/noxfile.py b/packages/google-cloud-appoptimize/noxfile.py index c2ecb5fe7bc2..6a011c8dc7f5 100644 --- a/packages/google-cloud-appoptimize/noxfile.py +++ b/packages/google-cloud-appoptimize/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-artifact-registry/noxfile.py b/packages/google-cloud-artifact-registry/noxfile.py index 7e22473d8349..ec6500e50a3d 100644 --- a/packages/google-cloud-artifact-registry/noxfile.py +++ b/packages/google-cloud-artifact-registry/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-asset/noxfile.py b/packages/google-cloud-asset/noxfile.py index 66c00771daf5..fade43d2ff51 100644 --- a/packages/google-cloud-asset/noxfile.py +++ b/packages/google-cloud-asset/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-assured-workloads/noxfile.py b/packages/google-cloud-assured-workloads/noxfile.py index dc0f6a9f3352..dff167c9c185 100644 --- a/packages/google-cloud-assured-workloads/noxfile.py +++ b/packages/google-cloud-assured-workloads/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-audit-log/noxfile.py b/packages/google-cloud-audit-log/noxfile.py index 0546c27a5e07..a1494188c877 100644 --- a/packages/google-cloud-audit-log/noxfile.py +++ b/packages/google-cloud-audit-log/noxfile.py @@ -569,6 +569,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") diff --git a/packages/google-cloud-auditmanager/noxfile.py b/packages/google-cloud-auditmanager/noxfile.py index 1066b5041b19..6315274c6303 100644 --- a/packages/google-cloud-auditmanager/noxfile.py +++ b/packages/google-cloud-auditmanager/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-automl/noxfile.py b/packages/google-cloud-automl/noxfile.py index 60a79d5ec781..3e99d09897cf 100644 --- a/packages/google-cloud-automl/noxfile.py +++ b/packages/google-cloud-automl/noxfile.py @@ -644,6 +644,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-backupdr/noxfile.py b/packages/google-cloud-backupdr/noxfile.py index f03df29a1833..67cce62d83f4 100644 --- a/packages/google-cloud-backupdr/noxfile.py +++ b/packages/google-cloud-backupdr/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bare-metal-solution/noxfile.py b/packages/google-cloud-bare-metal-solution/noxfile.py index 56570d0ddf0c..0c3ec658bbdb 100644 --- a/packages/google-cloud-bare-metal-solution/noxfile.py +++ b/packages/google-cloud-bare-metal-solution/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-batch/noxfile.py b/packages/google-cloud-batch/noxfile.py index 0826d78e856a..68d429a14b14 100644 --- a/packages/google-cloud-batch/noxfile.py +++ b/packages/google-cloud-batch/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-beyondcorp-appconnections/noxfile.py b/packages/google-cloud-beyondcorp-appconnections/noxfile.py index 037c5b93ce95..3e1ac6477f1a 100644 --- a/packages/google-cloud-beyondcorp-appconnections/noxfile.py +++ b/packages/google-cloud-beyondcorp-appconnections/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-beyondcorp-appconnectors/noxfile.py b/packages/google-cloud-beyondcorp-appconnectors/noxfile.py index 9a71eea19947..d491ec676771 100644 --- a/packages/google-cloud-beyondcorp-appconnectors/noxfile.py +++ b/packages/google-cloud-beyondcorp-appconnectors/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-beyondcorp-appgateways/noxfile.py b/packages/google-cloud-beyondcorp-appgateways/noxfile.py index b30d80d527ce..f3abdded611b 100644 --- a/packages/google-cloud-beyondcorp-appgateways/noxfile.py +++ b/packages/google-cloud-beyondcorp-appgateways/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py b/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py index a342162cd27d..b4938335fe66 100644 --- a/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py +++ b/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-beyondcorp-clientgateways/noxfile.py b/packages/google-cloud-beyondcorp-clientgateways/noxfile.py index e78d1be85aba..7e87fd5b17fc 100644 --- a/packages/google-cloud-beyondcorp-clientgateways/noxfile.py +++ b/packages/google-cloud-beyondcorp-clientgateways/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-biglake-hive/noxfile.py b/packages/google-cloud-biglake-hive/noxfile.py index 3ae2f827c952..743f1082b76c 100644 --- a/packages/google-cloud-biglake-hive/noxfile.py +++ b/packages/google-cloud-biglake-hive/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-biglake/noxfile.py b/packages/google-cloud-biglake/noxfile.py index 8fe1028844b4..c2ec79f71bf3 100644 --- a/packages/google-cloud-biglake/noxfile.py +++ b/packages/google-cloud-biglake/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigquery-analyticshub/noxfile.py b/packages/google-cloud-bigquery-analyticshub/noxfile.py index 1f875933e865..dce2d46f8250 100644 --- a/packages/google-cloud-bigquery-analyticshub/noxfile.py +++ b/packages/google-cloud-bigquery-analyticshub/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigquery-biglake/noxfile.py b/packages/google-cloud-bigquery-biglake/noxfile.py index a50212705b2e..33ef4cb99658 100644 --- a/packages/google-cloud-bigquery-biglake/noxfile.py +++ b/packages/google-cloud-bigquery-biglake/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigquery-connection/noxfile.py b/packages/google-cloud-bigquery-connection/noxfile.py index 1769eb65113d..e16361e6f30d 100644 --- a/packages/google-cloud-bigquery-connection/noxfile.py +++ b/packages/google-cloud-bigquery-connection/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigquery-data-exchange/noxfile.py b/packages/google-cloud-bigquery-data-exchange/noxfile.py index edd7d15a42dc..d16b8d11c685 100644 --- a/packages/google-cloud-bigquery-data-exchange/noxfile.py +++ b/packages/google-cloud-bigquery-data-exchange/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigquery-datapolicies/noxfile.py b/packages/google-cloud-bigquery-datapolicies/noxfile.py index 7b299c16b8d3..81271a06b1f3 100644 --- a/packages/google-cloud-bigquery-datapolicies/noxfile.py +++ b/packages/google-cloud-bigquery-datapolicies/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigquery-datatransfer/noxfile.py b/packages/google-cloud-bigquery-datatransfer/noxfile.py index 0173c555c200..1ff577f7b490 100644 --- a/packages/google-cloud-bigquery-datatransfer/noxfile.py +++ b/packages/google-cloud-bigquery-datatransfer/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigquery-logging/noxfile.py b/packages/google-cloud-bigquery-logging/noxfile.py index 6a7c2595a2ff..e5fa221f0a7b 100644 --- a/packages/google-cloud-bigquery-logging/noxfile.py +++ b/packages/google-cloud-bigquery-logging/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigquery-migration/noxfile.py b/packages/google-cloud-bigquery-migration/noxfile.py index a33d454e9a46..bcc2078df6e3 100644 --- a/packages/google-cloud-bigquery-migration/noxfile.py +++ b/packages/google-cloud-bigquery-migration/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigquery-reservation/noxfile.py b/packages/google-cloud-bigquery-reservation/noxfile.py index 5ee35b08e38c..19fc4345593a 100644 --- a/packages/google-cloud-bigquery-reservation/noxfile.py +++ b/packages/google-cloud-bigquery-reservation/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigquery-storage/noxfile.py b/packages/google-cloud-bigquery-storage/noxfile.py index af717048c974..4498c002df3c 100644 --- a/packages/google-cloud-bigquery-storage/noxfile.py +++ b/packages/google-cloud-bigquery-storage/noxfile.py @@ -684,6 +684,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigquery/noxfile.py b/packages/google-cloud-bigquery/noxfile.py index 6adff6a96ce1..86f9a9f406ad 100644 --- a/packages/google-cloud-bigquery/noxfile.py +++ b/packages/google-cloud-bigquery/noxfile.py @@ -591,14 +591,20 @@ def format(session: nox.sessions.Session) -> None: @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-bigtable/noxfile.py b/packages/google-cloud-bigtable/noxfile.py index cd4a7fecbd21..cf6a1e6b6b2e 100644 --- a/packages/google-cloud-bigtable/noxfile.py +++ b/packages/google-cloud-bigtable/noxfile.py @@ -630,14 +630,20 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google.cloud.bigtable.data", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google.cloud.bigtable.data", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google.cloud.bigtable.data", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google.cloud.bigtable.data", "--iterations", "10") diff --git a/packages/google-cloud-billing-budgets/noxfile.py b/packages/google-cloud-billing-budgets/noxfile.py index 683032a8f414..568deec95b25 100644 --- a/packages/google-cloud-billing-budgets/noxfile.py +++ b/packages/google-cloud-billing-budgets/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-billing/noxfile.py b/packages/google-cloud-billing/noxfile.py index 632251eb9314..831460ef7a97 100644 --- a/packages/google-cloud-billing/noxfile.py +++ b/packages/google-cloud-billing/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-binary-authorization/noxfile.py b/packages/google-cloud-binary-authorization/noxfile.py index 2ec3e160e213..b49c60e85c7f 100644 --- a/packages/google-cloud-binary-authorization/noxfile.py +++ b/packages/google-cloud-binary-authorization/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-build/noxfile.py b/packages/google-cloud-build/noxfile.py index 9d793a0d7b1d..e9dc4c3cf4c6 100644 --- a/packages/google-cloud-build/noxfile.py +++ b/packages/google-cloud-build/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-capacityplanner/noxfile.py b/packages/google-cloud-capacityplanner/noxfile.py index 8a0c64eacca8..db4f8b3f4445 100644 --- a/packages/google-cloud-capacityplanner/noxfile.py +++ b/packages/google-cloud-capacityplanner/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-certificate-manager/noxfile.py b/packages/google-cloud-certificate-manager/noxfile.py index 4b1b0e3201bf..063770c91f7b 100644 --- a/packages/google-cloud-certificate-manager/noxfile.py +++ b/packages/google-cloud-certificate-manager/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-ces/noxfile.py b/packages/google-cloud-ces/noxfile.py index e82481b3c36b..6ea471f71210 100644 --- a/packages/google-cloud-ces/noxfile.py +++ b/packages/google-cloud-ces/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-channel/noxfile.py b/packages/google-cloud-channel/noxfile.py index 964477ceb20e..682a7a97bad5 100644 --- a/packages/google-cloud-channel/noxfile.py +++ b/packages/google-cloud-channel/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-chronicle/noxfile.py b/packages/google-cloud-chronicle/noxfile.py index 1157454d8fb8..8e0561c2a8bf 100644 --- a/packages/google-cloud-chronicle/noxfile.py +++ b/packages/google-cloud-chronicle/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-cloudcontrolspartner/noxfile.py b/packages/google-cloud-cloudcontrolspartner/noxfile.py index 85968af11e3b..a45703c76843 100644 --- a/packages/google-cloud-cloudcontrolspartner/noxfile.py +++ b/packages/google-cloud-cloudcontrolspartner/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-cloudsecuritycompliance/noxfile.py b/packages/google-cloud-cloudsecuritycompliance/noxfile.py index 0791d2726bea..2016f309aa6d 100644 --- a/packages/google-cloud-cloudsecuritycompliance/noxfile.py +++ b/packages/google-cloud-cloudsecuritycompliance/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-commerce-consumer-procurement/noxfile.py b/packages/google-cloud-commerce-consumer-procurement/noxfile.py index 19886a434f99..3edbe11eeed0 100644 --- a/packages/google-cloud-commerce-consumer-procurement/noxfile.py +++ b/packages/google-cloud-commerce-consumer-procurement/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-common/noxfile.py b/packages/google-cloud-common/noxfile.py index ad14e50332a0..4bbfa9622c81 100644 --- a/packages/google-cloud-common/noxfile.py +++ b/packages/google-cloud-common/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-compute-v1beta/noxfile.py b/packages/google-cloud-compute-v1beta/noxfile.py index a9cfec4c7576..8010fb748d48 100644 --- a/packages/google-cloud-compute-v1beta/noxfile.py +++ b/packages/google-cloud-compute-v1beta/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-compute/noxfile.py b/packages/google-cloud-compute/noxfile.py index 3c46f1845e11..756175b8b7c5 100644 --- a/packages/google-cloud-compute/noxfile.py +++ b/packages/google-cloud-compute/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-confidentialcomputing/noxfile.py b/packages/google-cloud-confidentialcomputing/noxfile.py index 652071b2da2a..1de7ccf909a7 100644 --- a/packages/google-cloud-confidentialcomputing/noxfile.py +++ b/packages/google-cloud-confidentialcomputing/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-config/noxfile.py b/packages/google-cloud-config/noxfile.py index a5ee0e2a08cb..f44b34c08ec6 100644 --- a/packages/google-cloud-config/noxfile.py +++ b/packages/google-cloud-config/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-configdelivery/noxfile.py b/packages/google-cloud-configdelivery/noxfile.py index 437634bf1f36..00b94e612a98 100644 --- a/packages/google-cloud-configdelivery/noxfile.py +++ b/packages/google-cloud-configdelivery/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-contact-center-insights/noxfile.py b/packages/google-cloud-contact-center-insights/noxfile.py index f46454a2a9eb..05b4590e54e6 100644 --- a/packages/google-cloud-contact-center-insights/noxfile.py +++ b/packages/google-cloud-contact-center-insights/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-container/noxfile.py b/packages/google-cloud-container/noxfile.py index b55694d26301..03bc0c1a0fbe 100644 --- a/packages/google-cloud-container/noxfile.py +++ b/packages/google-cloud-container/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-containeranalysis/noxfile.py b/packages/google-cloud-containeranalysis/noxfile.py index e57e9978ec0f..5c3898b3e14d 100644 --- a/packages/google-cloud-containeranalysis/noxfile.py +++ b/packages/google-cloud-containeranalysis/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-contentwarehouse/noxfile.py b/packages/google-cloud-contentwarehouse/noxfile.py index aba0e6a7763b..9c30a9dabf2a 100644 --- a/packages/google-cloud-contentwarehouse/noxfile.py +++ b/packages/google-cloud-contentwarehouse/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-core/noxfile.py b/packages/google-cloud-core/noxfile.py index f76d074b1f44..55da68a79d32 100644 --- a/packages/google-cloud-core/noxfile.py +++ b/packages/google-cloud-core/noxfile.py @@ -423,14 +423,20 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-data-fusion/noxfile.py b/packages/google-cloud-data-fusion/noxfile.py index 934e1ba9b6d9..a5c450db08cb 100644 --- a/packages/google-cloud-data-fusion/noxfile.py +++ b/packages/google-cloud-data-fusion/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-data-qna/noxfile.py b/packages/google-cloud-data-qna/noxfile.py index e698594e04bb..48bbc441001a 100644 --- a/packages/google-cloud-data-qna/noxfile.py +++ b/packages/google-cloud-data-qna/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-databasecenter/noxfile.py b/packages/google-cloud-databasecenter/noxfile.py index c439ae3b9d8e..5f436d159f54 100644 --- a/packages/google-cloud-databasecenter/noxfile.py +++ b/packages/google-cloud-databasecenter/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-datacatalog-lineage-configmanagement/noxfile.py b/packages/google-cloud-datacatalog-lineage-configmanagement/noxfile.py index 6def24ef233b..2102fa18e34b 100644 --- a/packages/google-cloud-datacatalog-lineage-configmanagement/noxfile.py +++ b/packages/google-cloud-datacatalog-lineage-configmanagement/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-datacatalog-lineage/noxfile.py b/packages/google-cloud-datacatalog-lineage/noxfile.py index 445f6ff21408..d7976a56eed4 100644 --- a/packages/google-cloud-datacatalog-lineage/noxfile.py +++ b/packages/google-cloud-datacatalog-lineage/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-datacatalog/noxfile.py b/packages/google-cloud-datacatalog/noxfile.py index 0b6db6580366..2d3aef27f7d3 100644 --- a/packages/google-cloud-datacatalog/noxfile.py +++ b/packages/google-cloud-datacatalog/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-dataflow-client/noxfile.py b/packages/google-cloud-dataflow-client/noxfile.py index 6160a6c4a9c8..2bc2988f2945 100644 --- a/packages/google-cloud-dataflow-client/noxfile.py +++ b/packages/google-cloud-dataflow-client/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-dataform/noxfile.py b/packages/google-cloud-dataform/noxfile.py index 192a57896004..cb592d2af5b3 100644 --- a/packages/google-cloud-dataform/noxfile.py +++ b/packages/google-cloud-dataform/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-datalabeling/noxfile.py b/packages/google-cloud-datalabeling/noxfile.py index 099f126fc39f..e0eeeb67be3e 100644 --- a/packages/google-cloud-datalabeling/noxfile.py +++ b/packages/google-cloud-datalabeling/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-dataplex/noxfile.py b/packages/google-cloud-dataplex/noxfile.py index d95aa4d8f47b..3ad9d26c2f03 100644 --- a/packages/google-cloud-dataplex/noxfile.py +++ b/packages/google-cloud-dataplex/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-dataproc-metastore/noxfile.py b/packages/google-cloud-dataproc-metastore/noxfile.py index 74fbc13c6c5f..b1545ec301ce 100644 --- a/packages/google-cloud-dataproc-metastore/noxfile.py +++ b/packages/google-cloud-dataproc-metastore/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-dataproc/noxfile.py b/packages/google-cloud-dataproc/noxfile.py index ca769307aa0f..543c5019f031 100644 --- a/packages/google-cloud-dataproc/noxfile.py +++ b/packages/google-cloud-dataproc/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-datastore/noxfile.py b/packages/google-cloud-datastore/noxfile.py index bcc70d808b97..4abe78dbcc96 100644 --- a/packages/google-cloud-datastore/noxfile.py +++ b/packages/google-cloud-datastore/noxfile.py @@ -651,6 +651,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-datastream/noxfile.py b/packages/google-cloud-datastream/noxfile.py index d5fb283a633c..55c24d2f45c2 100644 --- a/packages/google-cloud-datastream/noxfile.py +++ b/packages/google-cloud-datastream/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-deploy/noxfile.py b/packages/google-cloud-deploy/noxfile.py index b5ae98f39e63..d5f9d06bab8e 100644 --- a/packages/google-cloud-deploy/noxfile.py +++ b/packages/google-cloud-deploy/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-developerconnect/noxfile.py b/packages/google-cloud-developerconnect/noxfile.py index 48815e7d2c12..92fef7792914 100644 --- a/packages/google-cloud-developerconnect/noxfile.py +++ b/packages/google-cloud-developerconnect/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-devicestreaming/noxfile.py b/packages/google-cloud-devicestreaming/noxfile.py index 5c5e37bcb14a..f7bb173e0ffb 100644 --- a/packages/google-cloud-devicestreaming/noxfile.py +++ b/packages/google-cloud-devicestreaming/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-dialogflow-cx/noxfile.py b/packages/google-cloud-dialogflow-cx/noxfile.py index 2a642add9182..70466ccdc104 100644 --- a/packages/google-cloud-dialogflow-cx/noxfile.py +++ b/packages/google-cloud-dialogflow-cx/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-dialogflow/noxfile.py b/packages/google-cloud-dialogflow/noxfile.py index 46a0c568cc98..56e97b5e6e72 100644 --- a/packages/google-cloud-dialogflow/noxfile.py +++ b/packages/google-cloud-dialogflow/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-discoveryengine/noxfile.py b/packages/google-cloud-discoveryengine/noxfile.py index 15997e360056..4f79bc93356f 100644 --- a/packages/google-cloud-discoveryengine/noxfile.py +++ b/packages/google-cloud-discoveryengine/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-dlp/noxfile.py b/packages/google-cloud-dlp/noxfile.py index 94c086e4a478..bb09f9d02423 100644 --- a/packages/google-cloud-dlp/noxfile.py +++ b/packages/google-cloud-dlp/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-dms/noxfile.py b/packages/google-cloud-dms/noxfile.py index 7f6336f5170e..3076f7ff7d38 100644 --- a/packages/google-cloud-dms/noxfile.py +++ b/packages/google-cloud-dms/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-dns/noxfile.py b/packages/google-cloud-dns/noxfile.py index 2732e966caaf..1158eb0e06f1 100644 --- a/packages/google-cloud-dns/noxfile.py +++ b/packages/google-cloud-dns/noxfile.py @@ -518,14 +518,20 @@ def core_deps_from_source(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-documentai-toolbox/noxfile.py b/packages/google-cloud-documentai-toolbox/noxfile.py index 9cb0de91312c..0790258815a5 100644 --- a/packages/google-cloud-documentai-toolbox/noxfile.py +++ b/packages/google-cloud-documentai-toolbox/noxfile.py @@ -552,14 +552,20 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google.cloud.documentai_toolbox", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google.cloud.documentai_toolbox", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google.cloud.documentai_toolbox", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google.cloud.documentai_toolbox", "--iterations", "10") diff --git a/packages/google-cloud-documentai/noxfile.py b/packages/google-cloud-documentai/noxfile.py index bf516b858975..a5285c4ea7e3 100644 --- a/packages/google-cloud-documentai/noxfile.py +++ b/packages/google-cloud-documentai/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-domains/noxfile.py b/packages/google-cloud-domains/noxfile.py index 7add4ad4561a..1a80bb3dcd01 100644 --- a/packages/google-cloud-domains/noxfile.py +++ b/packages/google-cloud-domains/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-edgecontainer/noxfile.py b/packages/google-cloud-edgecontainer/noxfile.py index fa79b2aa4cff..8211ae20c908 100644 --- a/packages/google-cloud-edgecontainer/noxfile.py +++ b/packages/google-cloud-edgecontainer/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-edgenetwork/noxfile.py b/packages/google-cloud-edgenetwork/noxfile.py index e7ec5d6bd3f7..220670163ca5 100644 --- a/packages/google-cloud-edgenetwork/noxfile.py +++ b/packages/google-cloud-edgenetwork/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-enterpriseknowledgegraph/noxfile.py b/packages/google-cloud-enterpriseknowledgegraph/noxfile.py index 7cc9ea6a019a..28067e5453f6 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/noxfile.py +++ b/packages/google-cloud-enterpriseknowledgegraph/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-error-reporting/noxfile.py b/packages/google-cloud-error-reporting/noxfile.py index 1340d0fd57b2..a85f76bffa23 100644 --- a/packages/google-cloud-error-reporting/noxfile.py +++ b/packages/google-cloud-error-reporting/noxfile.py @@ -644,6 +644,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-essential-contacts/noxfile.py b/packages/google-cloud-essential-contacts/noxfile.py index 3852efc0dacc..ba58f5eb21cb 100644 --- a/packages/google-cloud-essential-contacts/noxfile.py +++ b/packages/google-cloud-essential-contacts/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-eventarc-publishing/noxfile.py b/packages/google-cloud-eventarc-publishing/noxfile.py index 927ebf6706fe..c052b6d90d50 100644 --- a/packages/google-cloud-eventarc-publishing/noxfile.py +++ b/packages/google-cloud-eventarc-publishing/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-eventarc/noxfile.py b/packages/google-cloud-eventarc/noxfile.py index b4038a1d4f08..05665493bce8 100644 --- a/packages/google-cloud-eventarc/noxfile.py +++ b/packages/google-cloud-eventarc/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-filestore/noxfile.py b/packages/google-cloud-filestore/noxfile.py index 920ae400c144..d982e49d9d89 100644 --- a/packages/google-cloud-filestore/noxfile.py +++ b/packages/google-cloud-filestore/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-financialservices/noxfile.py b/packages/google-cloud-financialservices/noxfile.py index 45d52a1eddbc..f7c50ce6d977 100644 --- a/packages/google-cloud-financialservices/noxfile.py +++ b/packages/google-cloud-financialservices/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-firestore/noxfile.py b/packages/google-cloud-firestore/noxfile.py index 2fa9b42ad61a..e054a7ebcc0a 100644 --- a/packages/google-cloud-firestore/noxfile.py +++ b/packages/google-cloud-firestore/noxfile.py @@ -706,6 +706,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-functions/noxfile.py b/packages/google-cloud-functions/noxfile.py index cdc2208b0ee0..53207de57455 100644 --- a/packages/google-cloud-functions/noxfile.py +++ b/packages/google-cloud-functions/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-gdchardwaremanagement/noxfile.py b/packages/google-cloud-gdchardwaremanagement/noxfile.py index 274e700fa1b2..09a5748ad919 100644 --- a/packages/google-cloud-gdchardwaremanagement/noxfile.py +++ b/packages/google-cloud-gdchardwaremanagement/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-geminidataanalytics/noxfile.py b/packages/google-cloud-geminidataanalytics/noxfile.py index 37de84d01bec..5d11725b0f5a 100644 --- a/packages/google-cloud-geminidataanalytics/noxfile.py +++ b/packages/google-cloud-geminidataanalytics/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-gke-backup/noxfile.py b/packages/google-cloud-gke-backup/noxfile.py index 0733e6297977..980708c79767 100644 --- a/packages/google-cloud-gke-backup/noxfile.py +++ b/packages/google-cloud-gke-backup/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-gke-connect-gateway/noxfile.py b/packages/google-cloud-gke-connect-gateway/noxfile.py index e8da4de4533f..19704536cfce 100644 --- a/packages/google-cloud-gke-connect-gateway/noxfile.py +++ b/packages/google-cloud-gke-connect-gateway/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-gke-hub/noxfile.py b/packages/google-cloud-gke-hub/noxfile.py index de2ffec731fc..05a58c6dc1b6 100644 --- a/packages/google-cloud-gke-hub/noxfile.py +++ b/packages/google-cloud-gke-hub/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-gke-multicloud/noxfile.py b/packages/google-cloud-gke-multicloud/noxfile.py index f4c986d13295..5241f6bd5ccc 100644 --- a/packages/google-cloud-gke-multicloud/noxfile.py +++ b/packages/google-cloud-gke-multicloud/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-gkerecommender/noxfile.py b/packages/google-cloud-gkerecommender/noxfile.py index edc9d909e3e7..ca79f9bd6493 100644 --- a/packages/google-cloud-gkerecommender/noxfile.py +++ b/packages/google-cloud-gkerecommender/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-gsuiteaddons/noxfile.py b/packages/google-cloud-gsuiteaddons/noxfile.py index 8491dd06e578..621ca450f3b7 100644 --- a/packages/google-cloud-gsuiteaddons/noxfile.py +++ b/packages/google-cloud-gsuiteaddons/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-hypercomputecluster/noxfile.py b/packages/google-cloud-hypercomputecluster/noxfile.py index ed0d8a0a8a76..d9b523165e0d 100644 --- a/packages/google-cloud-hypercomputecluster/noxfile.py +++ b/packages/google-cloud-hypercomputecluster/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-iam-logging/noxfile.py b/packages/google-cloud-iam-logging/noxfile.py index 27db30e997ba..f891e7cb7e29 100644 --- a/packages/google-cloud-iam-logging/noxfile.py +++ b/packages/google-cloud-iam-logging/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-iam/noxfile.py b/packages/google-cloud-iam/noxfile.py index 886dbb28e78a..83b06f1534d0 100644 --- a/packages/google-cloud-iam/noxfile.py +++ b/packages/google-cloud-iam/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-iamconnectorcredentials/noxfile.py b/packages/google-cloud-iamconnectorcredentials/noxfile.py index 182d72c18fb3..62ee92cf12b1 100644 --- a/packages/google-cloud-iamconnectorcredentials/noxfile.py +++ b/packages/google-cloud-iamconnectorcredentials/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-iap/noxfile.py b/packages/google-cloud-iap/noxfile.py index 21a1436a321c..69e048874a22 100644 --- a/packages/google-cloud-iap/noxfile.py +++ b/packages/google-cloud-iap/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-ids/noxfile.py b/packages/google-cloud-ids/noxfile.py index 15e835478fc5..2ccf42a69afa 100644 --- a/packages/google-cloud-ids/noxfile.py +++ b/packages/google-cloud-ids/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-kms-inventory/noxfile.py b/packages/google-cloud-kms-inventory/noxfile.py index ae9e73fe2630..822422529300 100644 --- a/packages/google-cloud-kms-inventory/noxfile.py +++ b/packages/google-cloud-kms-inventory/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-kms/noxfile.py b/packages/google-cloud-kms/noxfile.py index adf4ba32fe7e..564d70d191be 100644 --- a/packages/google-cloud-kms/noxfile.py +++ b/packages/google-cloud-kms/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-language/noxfile.py b/packages/google-cloud-language/noxfile.py index 711dbd8d97de..d9f392d1724d 100644 --- a/packages/google-cloud-language/noxfile.py +++ b/packages/google-cloud-language/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-licensemanager/noxfile.py b/packages/google-cloud-licensemanager/noxfile.py index 98aedceeb6d6..05d19c126cb0 100644 --- a/packages/google-cloud-licensemanager/noxfile.py +++ b/packages/google-cloud-licensemanager/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-life-sciences/noxfile.py b/packages/google-cloud-life-sciences/noxfile.py index 16fa282d26b9..e566fe46fed2 100644 --- a/packages/google-cloud-life-sciences/noxfile.py +++ b/packages/google-cloud-life-sciences/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-locationfinder/noxfile.py b/packages/google-cloud-locationfinder/noxfile.py index 866dcfb8293a..69af041f04c6 100644 --- a/packages/google-cloud-locationfinder/noxfile.py +++ b/packages/google-cloud-locationfinder/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-logging/noxfile.py b/packages/google-cloud-logging/noxfile.py index 9b2446944be1..0119be93a12d 100644 --- a/packages/google-cloud-logging/noxfile.py +++ b/packages/google-cloud-logging/noxfile.py @@ -642,6 +642,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") diff --git a/packages/google-cloud-lustre/noxfile.py b/packages/google-cloud-lustre/noxfile.py index d0faa014d6b8..5892185974a6 100644 --- a/packages/google-cloud-lustre/noxfile.py +++ b/packages/google-cloud-lustre/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-maintenance-api/noxfile.py b/packages/google-cloud-maintenance-api/noxfile.py index f468415e7910..aca37e60cced 100644 --- a/packages/google-cloud-maintenance-api/noxfile.py +++ b/packages/google-cloud-maintenance-api/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-managed-identities/noxfile.py b/packages/google-cloud-managed-identities/noxfile.py index 076e179c3916..13c5db9b7c12 100644 --- a/packages/google-cloud-managed-identities/noxfile.py +++ b/packages/google-cloud-managed-identities/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-managedkafka-schemaregistry/noxfile.py b/packages/google-cloud-managedkafka-schemaregistry/noxfile.py index 52601b6888f4..3d0d2e9f2bf0 100644 --- a/packages/google-cloud-managedkafka-schemaregistry/noxfile.py +++ b/packages/google-cloud-managedkafka-schemaregistry/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-managedkafka/noxfile.py b/packages/google-cloud-managedkafka/noxfile.py index 2c78efa7dcef..8dff9fcdadc6 100644 --- a/packages/google-cloud-managedkafka/noxfile.py +++ b/packages/google-cloud-managedkafka/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-media-translation/noxfile.py b/packages/google-cloud-media-translation/noxfile.py index 4e239db52d5d..dc76d868333d 100644 --- a/packages/google-cloud-media-translation/noxfile.py +++ b/packages/google-cloud-media-translation/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-memcache/noxfile.py b/packages/google-cloud-memcache/noxfile.py index 5cee21d049ae..b1babeb79cf5 100644 --- a/packages/google-cloud-memcache/noxfile.py +++ b/packages/google-cloud-memcache/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-memorystore/noxfile.py b/packages/google-cloud-memorystore/noxfile.py index 0bdd4333e6b5..f3ddf977f489 100644 --- a/packages/google-cloud-memorystore/noxfile.py +++ b/packages/google-cloud-memorystore/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-migrationcenter/noxfile.py b/packages/google-cloud-migrationcenter/noxfile.py index c9698f875554..6dca716c1d6f 100644 --- a/packages/google-cloud-migrationcenter/noxfile.py +++ b/packages/google-cloud-migrationcenter/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-modelarmor/noxfile.py b/packages/google-cloud-modelarmor/noxfile.py index 103e1586e73b..86853024abd9 100644 --- a/packages/google-cloud-modelarmor/noxfile.py +++ b/packages/google-cloud-modelarmor/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-monitoring-dashboards/noxfile.py b/packages/google-cloud-monitoring-dashboards/noxfile.py index afef0f523f28..48baa6e5a93a 100644 --- a/packages/google-cloud-monitoring-dashboards/noxfile.py +++ b/packages/google-cloud-monitoring-dashboards/noxfile.py @@ -644,6 +644,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-monitoring-metrics-scopes/noxfile.py b/packages/google-cloud-monitoring-metrics-scopes/noxfile.py index de335e09224e..e6b062c69273 100644 --- a/packages/google-cloud-monitoring-metrics-scopes/noxfile.py +++ b/packages/google-cloud-monitoring-metrics-scopes/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-monitoring/noxfile.py b/packages/google-cloud-monitoring/noxfile.py index a726d3df94bc..eda2a76c849c 100644 --- a/packages/google-cloud-monitoring/noxfile.py +++ b/packages/google-cloud-monitoring/noxfile.py @@ -645,6 +645,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-ndb/noxfile.py b/packages/google-cloud-ndb/noxfile.py index 44beb5962377..9f22167f279c 100644 --- a/packages/google-cloud-ndb/noxfile.py +++ b/packages/google-cloud-ndb/noxfile.py @@ -553,14 +553,20 @@ def lint_setup_py(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google.cloud.ndb", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google.cloud.ndb", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google.cloud.ndb", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google.cloud.ndb", "--iterations", "10") diff --git a/packages/google-cloud-netapp/noxfile.py b/packages/google-cloud-netapp/noxfile.py index 085c92d354ee..f4cb3ea907df 100644 --- a/packages/google-cloud-netapp/noxfile.py +++ b/packages/google-cloud-netapp/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-network-connectivity/noxfile.py b/packages/google-cloud-network-connectivity/noxfile.py index a4e0365becd0..eb0b2dd9a996 100644 --- a/packages/google-cloud-network-connectivity/noxfile.py +++ b/packages/google-cloud-network-connectivity/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-network-management/noxfile.py b/packages/google-cloud-network-management/noxfile.py index 8888d2ac0383..dd4c7c8fef8d 100644 --- a/packages/google-cloud-network-management/noxfile.py +++ b/packages/google-cloud-network-management/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-network-security/noxfile.py b/packages/google-cloud-network-security/noxfile.py index 5641a221dfc4..75271cebe0dc 100644 --- a/packages/google-cloud-network-security/noxfile.py +++ b/packages/google-cloud-network-security/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-network-services/noxfile.py b/packages/google-cloud-network-services/noxfile.py index 75a9ff55abfe..3e7926130721 100644 --- a/packages/google-cloud-network-services/noxfile.py +++ b/packages/google-cloud-network-services/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-notebooks/noxfile.py b/packages/google-cloud-notebooks/noxfile.py index fb5f28ab947c..c322b59baaae 100644 --- a/packages/google-cloud-notebooks/noxfile.py +++ b/packages/google-cloud-notebooks/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-optimization/noxfile.py b/packages/google-cloud-optimization/noxfile.py index fb47f3a7a43c..b2d7ef8821b0 100644 --- a/packages/google-cloud-optimization/noxfile.py +++ b/packages/google-cloud-optimization/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-oracledatabase/noxfile.py b/packages/google-cloud-oracledatabase/noxfile.py index 3bc933ce904a..c4659e5b3146 100644 --- a/packages/google-cloud-oracledatabase/noxfile.py +++ b/packages/google-cloud-oracledatabase/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-orchestration-airflow/noxfile.py b/packages/google-cloud-orchestration-airflow/noxfile.py index 82acef83ca73..44763335e79a 100644 --- a/packages/google-cloud-orchestration-airflow/noxfile.py +++ b/packages/google-cloud-orchestration-airflow/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-org-policy/noxfile.py b/packages/google-cloud-org-policy/noxfile.py index 614884eda907..037c89b3ee54 100644 --- a/packages/google-cloud-org-policy/noxfile.py +++ b/packages/google-cloud-org-policy/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-os-config/noxfile.py b/packages/google-cloud-os-config/noxfile.py index ae8aa92abd86..2a12e7b3ad3b 100644 --- a/packages/google-cloud-os-config/noxfile.py +++ b/packages/google-cloud-os-config/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-os-login/noxfile.py b/packages/google-cloud-os-login/noxfile.py index a655ab9771d7..4f09338c5479 100644 --- a/packages/google-cloud-os-login/noxfile.py +++ b/packages/google-cloud-os-login/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-parallelstore/noxfile.py b/packages/google-cloud-parallelstore/noxfile.py index 824c3b1d8de3..71d1f56ae966 100644 --- a/packages/google-cloud-parallelstore/noxfile.py +++ b/packages/google-cloud-parallelstore/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-parametermanager/noxfile.py b/packages/google-cloud-parametermanager/noxfile.py index f27d80e95d49..28632ad67de9 100644 --- a/packages/google-cloud-parametermanager/noxfile.py +++ b/packages/google-cloud-parametermanager/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-phishing-protection/noxfile.py b/packages/google-cloud-phishing-protection/noxfile.py index ba5ac6ce1a06..1ae5210ce07c 100644 --- a/packages/google-cloud-phishing-protection/noxfile.py +++ b/packages/google-cloud-phishing-protection/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-policy-troubleshooter/noxfile.py b/packages/google-cloud-policy-troubleshooter/noxfile.py index d25945b17503..42067bc5057a 100644 --- a/packages/google-cloud-policy-troubleshooter/noxfile.py +++ b/packages/google-cloud-policy-troubleshooter/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-policysimulator/noxfile.py b/packages/google-cloud-policysimulator/noxfile.py index bc8a194a0848..7882ba5813ce 100644 --- a/packages/google-cloud-policysimulator/noxfile.py +++ b/packages/google-cloud-policysimulator/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-policytroubleshooter-iam/noxfile.py b/packages/google-cloud-policytroubleshooter-iam/noxfile.py index 50b10d38d7eb..b599c9d927eb 100644 --- a/packages/google-cloud-policytroubleshooter-iam/noxfile.py +++ b/packages/google-cloud-policytroubleshooter-iam/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-private-ca/noxfile.py b/packages/google-cloud-private-ca/noxfile.py index ec8158da72c0..e5c37a1f91c3 100644 --- a/packages/google-cloud-private-ca/noxfile.py +++ b/packages/google-cloud-private-ca/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-private-catalog/noxfile.py b/packages/google-cloud-private-catalog/noxfile.py index c8b007e1c8cb..48f1ef430276 100644 --- a/packages/google-cloud-private-catalog/noxfile.py +++ b/packages/google-cloud-private-catalog/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-privilegedaccessmanager/noxfile.py b/packages/google-cloud-privilegedaccessmanager/noxfile.py index 5ba0978bdc6d..2736819dbe71 100644 --- a/packages/google-cloud-privilegedaccessmanager/noxfile.py +++ b/packages/google-cloud-privilegedaccessmanager/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-pubsub/noxfile.py b/packages/google-cloud-pubsub/noxfile.py index e99b49fcd8a1..9e70f5367c98 100644 --- a/packages/google-cloud-pubsub/noxfile.py +++ b/packages/google-cloud-pubsub/noxfile.py @@ -628,14 +628,20 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google.cloud", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google.cloud", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google.cloud", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google.cloud", "--iterations", "10") diff --git a/packages/google-cloud-quotas/noxfile.py b/packages/google-cloud-quotas/noxfile.py index 34dc9845ea30..f32e130feb98 100644 --- a/packages/google-cloud-quotas/noxfile.py +++ b/packages/google-cloud-quotas/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-rapidmigrationassessment/noxfile.py b/packages/google-cloud-rapidmigrationassessment/noxfile.py index 1565c8ca0efe..e1445e9942a0 100644 --- a/packages/google-cloud-rapidmigrationassessment/noxfile.py +++ b/packages/google-cloud-rapidmigrationassessment/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-recaptcha-enterprise/noxfile.py b/packages/google-cloud-recaptcha-enterprise/noxfile.py index 1bc6f5b9e919..1c70d69e3343 100644 --- a/packages/google-cloud-recaptcha-enterprise/noxfile.py +++ b/packages/google-cloud-recaptcha-enterprise/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-recommendations-ai/noxfile.py b/packages/google-cloud-recommendations-ai/noxfile.py index 087bdb6ca81b..550328b5186d 100644 --- a/packages/google-cloud-recommendations-ai/noxfile.py +++ b/packages/google-cloud-recommendations-ai/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-recommender/noxfile.py b/packages/google-cloud-recommender/noxfile.py index f03f04c44e40..a348f21d22e6 100644 --- a/packages/google-cloud-recommender/noxfile.py +++ b/packages/google-cloud-recommender/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-redis-cluster/noxfile.py b/packages/google-cloud-redis-cluster/noxfile.py index 345534d3326b..79ba09eb29f6 100644 --- a/packages/google-cloud-redis-cluster/noxfile.py +++ b/packages/google-cloud-redis-cluster/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-redis/noxfile.py b/packages/google-cloud-redis/noxfile.py index ab7f1e396f1c..5d1df36cd08f 100644 --- a/packages/google-cloud-redis/noxfile.py +++ b/packages/google-cloud-redis/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-resource-manager/noxfile.py b/packages/google-cloud-resource-manager/noxfile.py index 5494b26703d0..b5beafdca105 100644 --- a/packages/google-cloud-resource-manager/noxfile.py +++ b/packages/google-cloud-resource-manager/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-retail/noxfile.py b/packages/google-cloud-retail/noxfile.py index fe572593cc84..9ff6402960d5 100644 --- a/packages/google-cloud-retail/noxfile.py +++ b/packages/google-cloud-retail/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-run/noxfile.py b/packages/google-cloud-run/noxfile.py index 1831cdb1d70f..b1294ce38803 100644 --- a/packages/google-cloud-run/noxfile.py +++ b/packages/google-cloud-run/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-runtimeconfig/noxfile.py b/packages/google-cloud-runtimeconfig/noxfile.py index 88ac1e09e792..1eacd5cfca1e 100644 --- a/packages/google-cloud-runtimeconfig/noxfile.py +++ b/packages/google-cloud-runtimeconfig/noxfile.py @@ -514,14 +514,20 @@ def core_deps_from_source(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-saasplatform-saasservicemgmt/noxfile.py b/packages/google-cloud-saasplatform-saasservicemgmt/noxfile.py index c1da0df46539..f26487327068 100644 --- a/packages/google-cloud-saasplatform-saasservicemgmt/noxfile.py +++ b/packages/google-cloud-saasplatform-saasservicemgmt/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-scheduler/noxfile.py b/packages/google-cloud-scheduler/noxfile.py index c543b5965771..491548afe3bd 100644 --- a/packages/google-cloud-scheduler/noxfile.py +++ b/packages/google-cloud-scheduler/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-secret-manager/noxfile.py b/packages/google-cloud-secret-manager/noxfile.py index 218389fd19b3..94b86cd7940a 100644 --- a/packages/google-cloud-secret-manager/noxfile.py +++ b/packages/google-cloud-secret-manager/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-securesourcemanager/noxfile.py b/packages/google-cloud-securesourcemanager/noxfile.py index 579fa9537b6e..0a6fb993b1ce 100644 --- a/packages/google-cloud-securesourcemanager/noxfile.py +++ b/packages/google-cloud-securesourcemanager/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-security-publicca/noxfile.py b/packages/google-cloud-security-publicca/noxfile.py index 328d609feb52..47b2af1ea7d9 100644 --- a/packages/google-cloud-security-publicca/noxfile.py +++ b/packages/google-cloud-security-publicca/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-securitycenter/noxfile.py b/packages/google-cloud-securitycenter/noxfile.py index 9ddf3849596e..4470b68de3dd 100644 --- a/packages/google-cloud-securitycenter/noxfile.py +++ b/packages/google-cloud-securitycenter/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-securitycentermanagement/noxfile.py b/packages/google-cloud-securitycentermanagement/noxfile.py index d498b93536d2..b98bb259259d 100644 --- a/packages/google-cloud-securitycentermanagement/noxfile.py +++ b/packages/google-cloud-securitycentermanagement/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-service-control/noxfile.py b/packages/google-cloud-service-control/noxfile.py index fc37980e12aa..b0db6a9c3a29 100644 --- a/packages/google-cloud-service-control/noxfile.py +++ b/packages/google-cloud-service-control/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-service-directory/noxfile.py b/packages/google-cloud-service-directory/noxfile.py index dfafd64c6340..6b3899f35e35 100644 --- a/packages/google-cloud-service-directory/noxfile.py +++ b/packages/google-cloud-service-directory/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-service-management/noxfile.py b/packages/google-cloud-service-management/noxfile.py index 8ed55b895a38..c31ba8bd1c6f 100644 --- a/packages/google-cloud-service-management/noxfile.py +++ b/packages/google-cloud-service-management/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-service-usage/noxfile.py b/packages/google-cloud-service-usage/noxfile.py index 3cfb046d24da..3540d06659a1 100644 --- a/packages/google-cloud-service-usage/noxfile.py +++ b/packages/google-cloud-service-usage/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-servicehealth/noxfile.py b/packages/google-cloud-servicehealth/noxfile.py index e965bb7ed2bb..7562ddf50a9b 100644 --- a/packages/google-cloud-servicehealth/noxfile.py +++ b/packages/google-cloud-servicehealth/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-shell/noxfile.py b/packages/google-cloud-shell/noxfile.py index f9a18094cc29..b7ee1e39f26f 100644 --- a/packages/google-cloud-shell/noxfile.py +++ b/packages/google-cloud-shell/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-source-context/noxfile.py b/packages/google-cloud-source-context/noxfile.py index 6b328821d331..19383cba0bea 100644 --- a/packages/google-cloud-source-context/noxfile.py +++ b/packages/google-cloud-source-context/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-spanner-dbapi-driver/noxfile.py b/packages/google-cloud-spanner-dbapi-driver/noxfile.py index d4ee7bd3e4a4..e296643c487b 100644 --- a/packages/google-cloud-spanner-dbapi-driver/noxfile.py +++ b/packages/google-cloud-spanner-dbapi-driver/noxfile.py @@ -610,6 +610,9 @@ def install(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-spanner/noxfile.py b/packages/google-cloud-spanner/noxfile.py index d33ab2281b90..da8d44ef10a7 100644 --- a/packages/google-cloud-spanner/noxfile.py +++ b/packages/google-cloud-spanner/noxfile.py @@ -853,14 +853,20 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-speech/noxfile.py b/packages/google-cloud-speech/noxfile.py index 41f334557c47..60f863f2fb25 100644 --- a/packages/google-cloud-speech/noxfile.py +++ b/packages/google-cloud-speech/noxfile.py @@ -644,6 +644,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-storage-control/noxfile.py b/packages/google-cloud-storage-control/noxfile.py index 6cb99e501121..617376760c73 100644 --- a/packages/google-cloud-storage-control/noxfile.py +++ b/packages/google-cloud-storage-control/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-storage-transfer/noxfile.py b/packages/google-cloud-storage-transfer/noxfile.py index 59fc64f5be82..6f35ab27a132 100644 --- a/packages/google-cloud-storage-transfer/noxfile.py +++ b/packages/google-cloud-storage-transfer/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-storage/noxfile.py b/packages/google-cloud-storage/noxfile.py index 8de52914a8bf..2760644a81ad 100644 --- a/packages/google-cloud-storage/noxfile.py +++ b/packages/google-cloud-storage/noxfile.py @@ -718,6 +718,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") diff --git a/packages/google-cloud-storagebatchoperations/noxfile.py b/packages/google-cloud-storagebatchoperations/noxfile.py index dcff2dcbdfe3..e502b0a09a42 100644 --- a/packages/google-cloud-storagebatchoperations/noxfile.py +++ b/packages/google-cloud-storagebatchoperations/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-storageinsights/noxfile.py b/packages/google-cloud-storageinsights/noxfile.py index b8d8913706b6..65a0542db8d9 100644 --- a/packages/google-cloud-storageinsights/noxfile.py +++ b/packages/google-cloud-storageinsights/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-support/noxfile.py b/packages/google-cloud-support/noxfile.py index e7a82c36d248..1d14cbb048d9 100644 --- a/packages/google-cloud-support/noxfile.py +++ b/packages/google-cloud-support/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-talent/noxfile.py b/packages/google-cloud-talent/noxfile.py index f723f738b8a7..7fd02e1a8a2f 100644 --- a/packages/google-cloud-talent/noxfile.py +++ b/packages/google-cloud-talent/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-tasks/noxfile.py b/packages/google-cloud-tasks/noxfile.py index 2c0d71024b1e..7dc9f6a86f4c 100644 --- a/packages/google-cloud-tasks/noxfile.py +++ b/packages/google-cloud-tasks/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-telcoautomation/noxfile.py b/packages/google-cloud-telcoautomation/noxfile.py index 004876169e8e..bfe01867ba18 100644 --- a/packages/google-cloud-telcoautomation/noxfile.py +++ b/packages/google-cloud-telcoautomation/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-testutils/noxfile.py b/packages/google-cloud-testutils/noxfile.py index 5c8a99aa725f..820def2f63b1 100644 --- a/packages/google-cloud-testutils/noxfile.py +++ b/packages/google-cloud-testutils/noxfile.py @@ -388,14 +388,20 @@ def core_deps_from_source(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") diff --git a/packages/google-cloud-texttospeech/noxfile.py b/packages/google-cloud-texttospeech/noxfile.py index fbe8bdfe764d..b17b0791af21 100644 --- a/packages/google-cloud-texttospeech/noxfile.py +++ b/packages/google-cloud-texttospeech/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-tpu/noxfile.py b/packages/google-cloud-tpu/noxfile.py index d2ec5370f16b..16e6cbf534ee 100644 --- a/packages/google-cloud-tpu/noxfile.py +++ b/packages/google-cloud-tpu/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-trace/noxfile.py b/packages/google-cloud-trace/noxfile.py index 65e68e470dac..9b13588d61ab 100644 --- a/packages/google-cloud-trace/noxfile.py +++ b/packages/google-cloud-trace/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-translate/noxfile.py b/packages/google-cloud-translate/noxfile.py index f747f8763d1c..003594f3514a 100644 --- a/packages/google-cloud-translate/noxfile.py +++ b/packages/google-cloud-translate/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-vectorsearch/noxfile.py b/packages/google-cloud-vectorsearch/noxfile.py index b29eb619e34e..e8b1f9999111 100644 --- a/packages/google-cloud-vectorsearch/noxfile.py +++ b/packages/google-cloud-vectorsearch/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-video-live-stream/noxfile.py b/packages/google-cloud-video-live-stream/noxfile.py index 7f0b861f20eb..e93a379985d4 100644 --- a/packages/google-cloud-video-live-stream/noxfile.py +++ b/packages/google-cloud-video-live-stream/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-video-stitcher/noxfile.py b/packages/google-cloud-video-stitcher/noxfile.py index 174ad4aad5f5..935b7e43d2a0 100644 --- a/packages/google-cloud-video-stitcher/noxfile.py +++ b/packages/google-cloud-video-stitcher/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-video-transcoder/noxfile.py b/packages/google-cloud-video-transcoder/noxfile.py index 7b920ab77a2a..39d8902166fb 100644 --- a/packages/google-cloud-video-transcoder/noxfile.py +++ b/packages/google-cloud-video-transcoder/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-videointelligence/noxfile.py b/packages/google-cloud-videointelligence/noxfile.py index 056ab3247553..2cea4d46b180 100644 --- a/packages/google-cloud-videointelligence/noxfile.py +++ b/packages/google-cloud-videointelligence/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-vision/noxfile.py b/packages/google-cloud-vision/noxfile.py index 861411feceee..29c41cb0ea75 100644 --- a/packages/google-cloud-vision/noxfile.py +++ b/packages/google-cloud-vision/noxfile.py @@ -644,6 +644,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-visionai/noxfile.py b/packages/google-cloud-visionai/noxfile.py index 203febe58b09..0e99862faa79 100644 --- a/packages/google-cloud-visionai/noxfile.py +++ b/packages/google-cloud-visionai/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-vm-migration/noxfile.py b/packages/google-cloud-vm-migration/noxfile.py index 64baa3759372..b966ccd0f30b 100644 --- a/packages/google-cloud-vm-migration/noxfile.py +++ b/packages/google-cloud-vm-migration/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-vmwareengine/noxfile.py b/packages/google-cloud-vmwareengine/noxfile.py index 3c01dc333fc4..80ad6075681e 100644 --- a/packages/google-cloud-vmwareengine/noxfile.py +++ b/packages/google-cloud-vmwareengine/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-vpc-access/noxfile.py b/packages/google-cloud-vpc-access/noxfile.py index 40b55c25b399..dbf744337755 100644 --- a/packages/google-cloud-vpc-access/noxfile.py +++ b/packages/google-cloud-vpc-access/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-webrisk/noxfile.py b/packages/google-cloud-webrisk/noxfile.py index 35b79e79e66c..9f75f9c93fa9 100644 --- a/packages/google-cloud-webrisk/noxfile.py +++ b/packages/google-cloud-webrisk/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-websecurityscanner/noxfile.py b/packages/google-cloud-websecurityscanner/noxfile.py index 300b9c452da7..c4535bdc436a 100644 --- a/packages/google-cloud-websecurityscanner/noxfile.py +++ b/packages/google-cloud-websecurityscanner/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-workflows/noxfile.py b/packages/google-cloud-workflows/noxfile.py index a348eb3663c7..3a843e4ae5e0 100644 --- a/packages/google-cloud-workflows/noxfile.py +++ b/packages/google-cloud-workflows/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-workloadmanager/noxfile.py b/packages/google-cloud-workloadmanager/noxfile.py index a1b67a1b2a66..578f41526754 100644 --- a/packages/google-cloud-workloadmanager/noxfile.py +++ b/packages/google-cloud-workloadmanager/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-cloud-workstations/noxfile.py b/packages/google-cloud-workstations/noxfile.py index be92dab6c22f..999f437a5445 100644 --- a/packages/google-cloud-workstations/noxfile.py +++ b/packages/google-cloud-workstations/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-crc32c/noxfile.py b/packages/google-crc32c/noxfile.py index 9115a55ddc00..0e73416b5023 100644 --- a/packages/google-crc32c/noxfile.py +++ b/packages/google-crc32c/noxfile.py @@ -189,14 +189,20 @@ def docfx(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") diff --git a/packages/google-developer-knowledge/noxfile.py b/packages/google-developer-knowledge/noxfile.py index 97533cf2b865..d565b93878d0 100644 --- a/packages/google-developer-knowledge/noxfile.py +++ b/packages/google-developer-knowledge/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-devicesandservices-health/noxfile.py b/packages/google-devicesandservices-health/noxfile.py index 8a4a9650142a..664d0afe3161 100644 --- a/packages/google-devicesandservices-health/noxfile.py +++ b/packages/google-devicesandservices-health/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-geo-type/noxfile.py b/packages/google-geo-type/noxfile.py index 5fe773718b9e..9b31d1a6b71c 100644 --- a/packages/google-geo-type/noxfile.py +++ b/packages/google-geo-type/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-addressvalidation/noxfile.py b/packages/google-maps-addressvalidation/noxfile.py index 277a94658afe..b2423e439707 100644 --- a/packages/google-maps-addressvalidation/noxfile.py +++ b/packages/google-maps-addressvalidation/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-areainsights/noxfile.py b/packages/google-maps-areainsights/noxfile.py index 7379c5b48709..2f9c678ddf23 100644 --- a/packages/google-maps-areainsights/noxfile.py +++ b/packages/google-maps-areainsights/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-fleetengine-delivery/noxfile.py b/packages/google-maps-fleetengine-delivery/noxfile.py index 8adc77c27665..f268d1f418e9 100644 --- a/packages/google-maps-fleetengine-delivery/noxfile.py +++ b/packages/google-maps-fleetengine-delivery/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-fleetengine/noxfile.py b/packages/google-maps-fleetengine/noxfile.py index a691ebc9a9a6..53d5c0e15943 100644 --- a/packages/google-maps-fleetengine/noxfile.py +++ b/packages/google-maps-fleetengine/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-geocode/noxfile.py b/packages/google-maps-geocode/noxfile.py index 742c66f86296..a974334952f2 100644 --- a/packages/google-maps-geocode/noxfile.py +++ b/packages/google-maps-geocode/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-mapmanagement/noxfile.py b/packages/google-maps-mapmanagement/noxfile.py index 0da377a91a1e..4ebfdc34c171 100644 --- a/packages/google-maps-mapmanagement/noxfile.py +++ b/packages/google-maps-mapmanagement/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-mapsplatformdatasets/noxfile.py b/packages/google-maps-mapsplatformdatasets/noxfile.py index f60a76ce45bc..c26ef6b4bd6d 100644 --- a/packages/google-maps-mapsplatformdatasets/noxfile.py +++ b/packages/google-maps-mapsplatformdatasets/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-navconnect/noxfile.py b/packages/google-maps-navconnect/noxfile.py index 79c850d7900e..afedf64878d2 100644 --- a/packages/google-maps-navconnect/noxfile.py +++ b/packages/google-maps-navconnect/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-places/noxfile.py b/packages/google-maps-places/noxfile.py index 89dbb4edbb97..d12b2eb099c0 100644 --- a/packages/google-maps-places/noxfile.py +++ b/packages/google-maps-places/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-routeoptimization/noxfile.py b/packages/google-maps-routeoptimization/noxfile.py index 5f59de6b8f42..f545a7ff7a58 100644 --- a/packages/google-maps-routeoptimization/noxfile.py +++ b/packages/google-maps-routeoptimization/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-routing/noxfile.py b/packages/google-maps-routing/noxfile.py index f28fb8b80931..9b9b2bf58a45 100644 --- a/packages/google-maps-routing/noxfile.py +++ b/packages/google-maps-routing/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-maps-solar/noxfile.py b/packages/google-maps-solar/noxfile.py index 0607c0b92610..bc42fe927819 100644 --- a/packages/google-maps-solar/noxfile.py +++ b/packages/google-maps-solar/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-resumable-media/noxfile.py b/packages/google-resumable-media/noxfile.py index aa9af0aa84b4..490f7cb876ac 100644 --- a/packages/google-resumable-media/noxfile.py +++ b/packages/google-resumable-media/noxfile.py @@ -453,14 +453,20 @@ def core_deps_from_source(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-css/noxfile.py b/packages/google-shopping-css/noxfile.py index 2e307140ce59..1f616d50dade 100644 --- a/packages/google-shopping-css/noxfile.py +++ b/packages/google-shopping-css/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-accounts/noxfile.py b/packages/google-shopping-merchant-accounts/noxfile.py index 8d365554cee4..037d70796fcf 100644 --- a/packages/google-shopping-merchant-accounts/noxfile.py +++ b/packages/google-shopping-merchant-accounts/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-conversions/noxfile.py b/packages/google-shopping-merchant-conversions/noxfile.py index 287a3b04e7e0..1aff313f955d 100644 --- a/packages/google-shopping-merchant-conversions/noxfile.py +++ b/packages/google-shopping-merchant-conversions/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-datasources/noxfile.py b/packages/google-shopping-merchant-datasources/noxfile.py index d51b6fcbf626..8fd5aa084476 100644 --- a/packages/google-shopping-merchant-datasources/noxfile.py +++ b/packages/google-shopping-merchant-datasources/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-inventories/noxfile.py b/packages/google-shopping-merchant-inventories/noxfile.py index cfb5aca4ff38..808693aa64b0 100644 --- a/packages/google-shopping-merchant-inventories/noxfile.py +++ b/packages/google-shopping-merchant-inventories/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-issueresolution/noxfile.py b/packages/google-shopping-merchant-issueresolution/noxfile.py index 202a2596398e..45726fc76b43 100644 --- a/packages/google-shopping-merchant-issueresolution/noxfile.py +++ b/packages/google-shopping-merchant-issueresolution/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-lfp/noxfile.py b/packages/google-shopping-merchant-lfp/noxfile.py index ec159991de76..4be2846fbb89 100644 --- a/packages/google-shopping-merchant-lfp/noxfile.py +++ b/packages/google-shopping-merchant-lfp/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-notifications/noxfile.py b/packages/google-shopping-merchant-notifications/noxfile.py index 7dc35edea60b..020541319f11 100644 --- a/packages/google-shopping-merchant-notifications/noxfile.py +++ b/packages/google-shopping-merchant-notifications/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-ordertracking/noxfile.py b/packages/google-shopping-merchant-ordertracking/noxfile.py index afbc0973e1c6..42701d4d026b 100644 --- a/packages/google-shopping-merchant-ordertracking/noxfile.py +++ b/packages/google-shopping-merchant-ordertracking/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-products/noxfile.py b/packages/google-shopping-merchant-products/noxfile.py index c937eef5c181..25ac85dc73f8 100644 --- a/packages/google-shopping-merchant-products/noxfile.py +++ b/packages/google-shopping-merchant-products/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-productstudio/noxfile.py b/packages/google-shopping-merchant-productstudio/noxfile.py index 65068f4ef380..b79917c5cb18 100644 --- a/packages/google-shopping-merchant-productstudio/noxfile.py +++ b/packages/google-shopping-merchant-productstudio/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-promotions/noxfile.py b/packages/google-shopping-merchant-promotions/noxfile.py index 34be9afe1f38..bb4b5152439c 100644 --- a/packages/google-shopping-merchant-promotions/noxfile.py +++ b/packages/google-shopping-merchant-promotions/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-quota/noxfile.py b/packages/google-shopping-merchant-quota/noxfile.py index ffc5e63703a7..6c61ece3c98d 100644 --- a/packages/google-shopping-merchant-quota/noxfile.py +++ b/packages/google-shopping-merchant-quota/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-reports/noxfile.py b/packages/google-shopping-merchant-reports/noxfile.py index f8c109625f8a..a85260e58dc6 100644 --- a/packages/google-shopping-merchant-reports/noxfile.py +++ b/packages/google-shopping-merchant-reports/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-merchant-reviews/noxfile.py b/packages/google-shopping-merchant-reviews/noxfile.py index edcb7f0c7283..cf1ca4f89b2a 100644 --- a/packages/google-shopping-merchant-reviews/noxfile.py +++ b/packages/google-shopping-merchant-reviews/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/google-shopping-type/noxfile.py b/packages/google-shopping-type/noxfile.py index a138dd4af611..b330c7fcce9d 100644 --- a/packages/google-shopping-type/noxfile.py +++ b/packages/google-shopping-type/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "google", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") diff --git a/packages/googleapis-common-protos/noxfile.py b/packages/googleapis-common-protos/noxfile.py index 435fb3289b48..0f5b76241476 100644 --- a/packages/googleapis-common-protos/noxfile.py +++ b/packages/googleapis-common-protos/noxfile.py @@ -605,6 +605,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") diff --git a/packages/grafeas/noxfile.py b/packages/grafeas/noxfile.py index 571fa60e7d41..d0753e486952 100644 --- a/packages/grafeas/noxfile.py +++ b/packages/grafeas/noxfile.py @@ -643,6 +643,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "grafeas", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "grafeas", "--iterations", "10") diff --git a/packages/grpc-google-iam-v1/noxfile.py b/packages/grpc-google-iam-v1/noxfile.py index 8b67d7d6ab9a..a93eba2f067d 100644 --- a/packages/grpc-google-iam-v1/noxfile.py +++ b/packages/grpc-google-iam-v1/noxfile.py @@ -590,6 +590,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") diff --git a/packages/pandas-gbq/noxfile.py b/packages/pandas-gbq/noxfile.py index e8d0fff76e99..3db6c0d18cc0 100644 --- a/packages/pandas-gbq/noxfile.py +++ b/packages/pandas-gbq/noxfile.py @@ -601,6 +601,9 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") diff --git a/packages/proto-plus/noxfile.py b/packages/proto-plus/noxfile.py index 2e9fec7ff929..b720220755e0 100644 --- a/packages/proto-plus/noxfile.py +++ b/packages/proto-plus/noxfile.py @@ -358,14 +358,20 @@ def format(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") diff --git a/packages/sqlalchemy-bigquery/noxfile.py b/packages/sqlalchemy-bigquery/noxfile.py index a79a915fea79..1508291d14f7 100644 --- a/packages/sqlalchemy-bigquery/noxfile.py +++ b/packages/sqlalchemy-bigquery/noxfile.py @@ -747,14 +747,20 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") diff --git a/packages/sqlalchemy-spanner/noxfile.py b/packages/sqlalchemy-spanner/noxfile.py index a840d2bf1981..b03deea9767a 100644 --- a/packages/sqlalchemy-spanner/noxfile.py +++ b/packages/sqlalchemy-spanner/noxfile.py @@ -609,14 +609,20 @@ def format(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" + profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + session.install(".") - profiler_script = os.path.join(CURRENT_DIRECTORY.parent.parent, "scripts", "import_profiler", "profiler.py") - session.run("python", profiler_script, "--module", "unknown_module", "--iterations", "10") + session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") From a0c075f3679459bf61e5ced0acfa2bc1693dbcb5 Mon Sep 17 00:00:00 2001 From: Heba Alazzeh Date: Wed, 8 Jul 2026 03:29:40 +0000 Subject: [PATCH 05/13] style(ci): reformat noxfile with black to fix lint errors --- packages/bigframes/noxfile.py | 26 +++++++++-- packages/bigquery-magics/noxfile.py | 26 +++++++++-- packages/db-dtypes/noxfile.py | 16 +++++-- packages/django-google-spanner/noxfile.py | 26 +++++++++-- .../gapic/templates/noxfile.py.j2 | 12 +++-- packages/gapic-generator/noxfile.py | 37 ++++++++++----- .../integration/goldens/asset/noxfile.py | 46 +++++++++++++------ .../goldens/credentials/noxfile.py | 46 +++++++++++++------ .../integration/goldens/eventarc/noxfile.py | 46 +++++++++++++------ .../integration/goldens/logging/noxfile.py | 46 +++++++++++++------ .../goldens/logging_internal/noxfile.py | 46 +++++++++++++------ .../integration/goldens/redis/noxfile.py | 46 +++++++++++++------ .../goldens/redis_selective/noxfile.py | 46 +++++++++++++------ .../goldens/storagebatchoperations/noxfile.py | 46 +++++++++++++------ packages/gcp-sphinx-docfx-yaml/noxfile.py | 26 +++++++++-- packages/google-ads-admanager/noxfile.py | 8 +++- packages/google-ads-datamanager/noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../google-ai-generativelanguage/noxfile.py | 8 +++- packages/google-analytics-admin/noxfile.py | 8 +++- packages/google-analytics-data/noxfile.py | 8 +++- packages/google-api-core/noxfile.py | 26 +++++++++-- packages/google-apps-card/noxfile.py | 8 +++- packages/google-apps-chat/noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-apps-meet/noxfile.py | 8 +++- packages/google-apps-script-type/noxfile.py | 8 +++- packages/google-area120-tables/noxfile.py | 8 +++- packages/google-auth-httplib2/noxfile.py | 26 +++++++++-- packages/google-auth-oauthlib/noxfile.py | 26 +++++++++-- packages/google-auth/noxfile.py | 8 +++- packages/google-backstory/noxfile.py | 8 +++- .../google-cloud-access-approval/noxfile.py | 8 +++- .../noxfile.py | 13 +++++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../google-cloud-agentregistry/noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-alloydb/noxfile.py | 8 +++- packages/google-cloud-api-gateway/noxfile.py | 8 +++- packages/google-cloud-api-keys/noxfile.py | 8 +++- .../google-cloud-apigee-connect/noxfile.py | 8 +++- .../google-cloud-apigee-registry/noxfile.py | 8 +++- packages/google-cloud-apihub/noxfile.py | 8 +++- packages/google-cloud-apiregistry/noxfile.py | 8 +++- .../google-cloud-appengine-admin/noxfile.py | 8 +++- .../google-cloud-appengine-logging/noxfile.py | 8 +++- packages/google-cloud-apphub/noxfile.py | 8 +++- packages/google-cloud-appoptimize/noxfile.py | 8 +++- .../google-cloud-artifact-registry/noxfile.py | 8 +++- packages/google-cloud-asset/noxfile.py | 8 +++- .../google-cloud-assured-workloads/noxfile.py | 8 +++- packages/google-cloud-audit-log/noxfile.py | 13 +++++- packages/google-cloud-auditmanager/noxfile.py | 8 +++- packages/google-cloud-automl/noxfile.py | 8 +++- packages/google-cloud-backupdr/noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-batch/noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-biglake-hive/noxfile.py | 8 +++- packages/google-cloud-biglake/noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../google-cloud-bigquery-biglake/noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../google-cloud-bigquery-logging/noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../google-cloud-bigquery-storage/noxfile.py | 8 +++- packages/google-cloud-bigquery/noxfile.py | 16 +++++-- packages/google-cloud-bigtable/noxfile.py | 26 +++++++++-- .../google-cloud-billing-budgets/noxfile.py | 8 +++- packages/google-cloud-billing/noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-build/noxfile.py | 8 +++- .../google-cloud-capacityplanner/noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-ces/noxfile.py | 8 +++- packages/google-cloud-channel/noxfile.py | 8 +++- packages/google-cloud-chronicle/noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-common/noxfile.py | 8 +++- .../google-cloud-compute-v1beta/noxfile.py | 8 +++- packages/google-cloud-compute/noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-config/noxfile.py | 8 +++- .../google-cloud-configdelivery/noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-container/noxfile.py | 8 +++- .../google-cloud-containeranalysis/noxfile.py | 8 +++- .../google-cloud-contentwarehouse/noxfile.py | 8 +++- packages/google-cloud-core/noxfile.py | 16 +++++-- packages/google-cloud-data-fusion/noxfile.py | 8 +++- packages/google-cloud-data-qna/noxfile.py | 8 +++- .../google-cloud-databasecenter/noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-datacatalog/noxfile.py | 8 +++- .../google-cloud-dataflow-client/noxfile.py | 8 +++- packages/google-cloud-dataform/noxfile.py | 8 +++- packages/google-cloud-datalabeling/noxfile.py | 8 +++- packages/google-cloud-dataplex/noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-dataproc/noxfile.py | 8 +++- packages/google-cloud-datastore/noxfile.py | 8 +++- packages/google-cloud-datastream/noxfile.py | 8 +++- packages/google-cloud-deploy/noxfile.py | 8 +++- .../google-cloud-developerconnect/noxfile.py | 8 +++- .../google-cloud-devicestreaming/noxfile.py | 8 +++- .../google-cloud-dialogflow-cx/noxfile.py | 8 +++- packages/google-cloud-dialogflow/noxfile.py | 8 +++- .../google-cloud-discoveryengine/noxfile.py | 8 +++- packages/google-cloud-dlp/noxfile.py | 8 +++- packages/google-cloud-dms/noxfile.py | 8 +++- packages/google-cloud-dns/noxfile.py | 16 +++++-- .../noxfile.py | 26 +++++++++-- packages/google-cloud-documentai/noxfile.py | 8 +++- packages/google-cloud-domains/noxfile.py | 8 +++- .../google-cloud-edgecontainer/noxfile.py | 8 +++- packages/google-cloud-edgenetwork/noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../google-cloud-error-reporting/noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-eventarc/noxfile.py | 8 +++- packages/google-cloud-filestore/noxfile.py | 8 +++- .../google-cloud-financialservices/noxfile.py | 8 +++- packages/google-cloud-firestore/noxfile.py | 8 +++- packages/google-cloud-functions/noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-gke-backup/noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-gke-hub/noxfile.py | 8 +++- .../google-cloud-gke-multicloud/noxfile.py | 8 +++- .../google-cloud-gkerecommender/noxfile.py | 8 +++- packages/google-cloud-gsuiteaddons/noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-iam-logging/noxfile.py | 8 +++- packages/google-cloud-iam/noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-iap/noxfile.py | 8 +++- packages/google-cloud-ids/noxfile.py | 8 +++- .../google-cloud-kms-inventory/noxfile.py | 8 +++- packages/google-cloud-kms/noxfile.py | 8 +++- packages/google-cloud-language/noxfile.py | 8 +++- .../google-cloud-licensemanager/noxfile.py | 8 +++- .../google-cloud-life-sciences/noxfile.py | 8 +++- .../google-cloud-locationfinder/noxfile.py | 8 +++- packages/google-cloud-logging/noxfile.py | 13 +++++- packages/google-cloud-lustre/noxfile.py | 8 +++- .../google-cloud-maintenance-api/noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-managedkafka/noxfile.py | 8 +++- .../google-cloud-media-translation/noxfile.py | 8 +++- packages/google-cloud-memcache/noxfile.py | 8 +++- packages/google-cloud-memorystore/noxfile.py | 8 +++- .../google-cloud-migrationcenter/noxfile.py | 8 +++- packages/google-cloud-modelarmor/noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-monitoring/noxfile.py | 8 +++- packages/google-cloud-ndb/noxfile.py | 26 +++++++++-- packages/google-cloud-netapp/noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../google-cloud-network-security/noxfile.py | 8 +++- .../google-cloud-network-services/noxfile.py | 8 +++- packages/google-cloud-notebooks/noxfile.py | 8 +++- packages/google-cloud-optimization/noxfile.py | 8 +++- .../google-cloud-oracledatabase/noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-org-policy/noxfile.py | 8 +++- packages/google-cloud-os-config/noxfile.py | 8 +++- packages/google-cloud-os-login/noxfile.py | 8 +++- .../google-cloud-parallelstore/noxfile.py | 8 +++- .../google-cloud-parametermanager/noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../google-cloud-policysimulator/noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-private-ca/noxfile.py | 8 +++- .../google-cloud-private-catalog/noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-pubsub/noxfile.py | 16 +++++-- packages/google-cloud-quotas/noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-recommender/noxfile.py | 8 +++- .../google-cloud-redis-cluster/noxfile.py | 8 +++- packages/google-cloud-redis/noxfile.py | 8 +++- .../google-cloud-resource-manager/noxfile.py | 8 +++- packages/google-cloud-retail/noxfile.py | 8 +++- packages/google-cloud-run/noxfile.py | 8 +++- .../google-cloud-runtimeconfig/noxfile.py | 16 +++++-- .../noxfile.py | 8 +++- packages/google-cloud-scheduler/noxfile.py | 8 +++- .../google-cloud-secret-manager/noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../google-cloud-security-publicca/noxfile.py | 8 +++- .../google-cloud-securitycenter/noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../google-cloud-service-control/noxfile.py | 8 +++- .../google-cloud-service-directory/noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../google-cloud-service-usage/noxfile.py | 8 +++- .../google-cloud-servicehealth/noxfile.py | 8 +++- packages/google-cloud-shell/noxfile.py | 8 +++- .../google-cloud-source-context/noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-spanner/noxfile.py | 16 +++++-- packages/google-cloud-speech/noxfile.py | 8 +++- .../google-cloud-storage-control/noxfile.py | 8 +++- .../google-cloud-storage-transfer/noxfile.py | 8 +++- packages/google-cloud-storage/noxfile.py | 13 +++++- .../noxfile.py | 8 +++- .../google-cloud-storageinsights/noxfile.py | 8 +++- packages/google-cloud-support/noxfile.py | 8 +++- packages/google-cloud-talent/noxfile.py | 8 +++- packages/google-cloud-tasks/noxfile.py | 8 +++- .../google-cloud-telcoautomation/noxfile.py | 8 +++- packages/google-cloud-testutils/noxfile.py | 37 +++++++++++---- packages/google-cloud-texttospeech/noxfile.py | 8 +++- packages/google-cloud-tpu/noxfile.py | 8 +++- packages/google-cloud-trace/noxfile.py | 8 +++- packages/google-cloud-translate/noxfile.py | 8 +++- packages/google-cloud-vectorsearch/noxfile.py | 8 +++- .../google-cloud-video-live-stream/noxfile.py | 8 +++- .../google-cloud-video-stitcher/noxfile.py | 8 +++- .../google-cloud-video-transcoder/noxfile.py | 8 +++- .../google-cloud-videointelligence/noxfile.py | 8 +++- packages/google-cloud-vision/noxfile.py | 8 +++- packages/google-cloud-visionai/noxfile.py | 8 +++- packages/google-cloud-vm-migration/noxfile.py | 8 +++- packages/google-cloud-vmwareengine/noxfile.py | 8 +++- packages/google-cloud-vpc-access/noxfile.py | 8 +++- packages/google-cloud-webrisk/noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-cloud-workflows/noxfile.py | 8 +++- .../google-cloud-workloadmanager/noxfile.py | 8 +++- packages/google-cloud-workstations/noxfile.py | 8 +++- packages/google-crc32c/noxfile.py | 26 +++++++++-- .../google-developer-knowledge/noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-geo-type/noxfile.py | 8 +++- .../google-maps-addressvalidation/noxfile.py | 8 +++- packages/google-maps-areainsights/noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-maps-fleetengine/noxfile.py | 8 +++- packages/google-maps-geocode/noxfile.py | 8 +++- packages/google-maps-mapmanagement/noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-maps-navconnect/noxfile.py | 8 +++- packages/google-maps-places/noxfile.py | 8 +++- .../google-maps-routeoptimization/noxfile.py | 8 +++- packages/google-maps-routing/noxfile.py | 8 +++- packages/google-maps-solar/noxfile.py | 8 +++- packages/google-resumable-media/noxfile.py | 31 +++++++++---- packages/google-shopping-css/noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../google-shopping-merchant-lfp/noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../google-shopping-merchant-quota/noxfile.py | 8 +++- .../noxfile.py | 8 +++- .../noxfile.py | 8 +++- packages/google-shopping-type/noxfile.py | 8 +++- packages/googleapis-common-protos/noxfile.py | 13 +++++- packages/grafeas/noxfile.py | 8 +++- packages/grpc-google-iam-v1/noxfile.py | 13 +++++- packages/pandas-gbq/noxfile.py | 13 +++++- packages/proto-plus/noxfile.py | 26 +++++++++-- packages/sqlalchemy-bigquery/noxfile.py | 26 +++++++++-- packages/sqlalchemy-spanner/noxfile.py | 26 +++++++++-- 291 files changed, 2317 insertions(+), 743 deletions(-) diff --git a/packages/bigframes/noxfile.py b/packages/bigframes/noxfile.py index 496c2d4b1657..d0188e69df44 100644 --- a/packages/bigframes/noxfile.py +++ b/packages/bigframes/noxfile.py @@ -1097,20 +1097,38 @@ def mypy(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) diff --git a/packages/bigquery-magics/noxfile.py b/packages/bigquery-magics/noxfile.py index f5a945c2f864..efb3bddbe6ef 100644 --- a/packages/bigquery-magics/noxfile.py +++ b/packages/bigquery-magics/noxfile.py @@ -551,20 +551,38 @@ def mypy(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) diff --git a/packages/db-dtypes/noxfile.py b/packages/db-dtypes/noxfile.py index 65dc1a722bd6..c2475d848ce8 100644 --- a/packages/db-dtypes/noxfile.py +++ b/packages/db-dtypes/noxfile.py @@ -552,20 +552,28 @@ def mypy(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "db_dtypes", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "db_dtypes", "--iterations", "10" + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "db_dtypes", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "db_dtypes", "--iterations", "10" + ) diff --git a/packages/django-google-spanner/noxfile.py b/packages/django-google-spanner/noxfile.py index 01400f503d73..70379bf836f2 100644 --- a/packages/django-google-spanner/noxfile.py +++ b/packages/django-google-spanner/noxfile.py @@ -496,20 +496,38 @@ def format(session: nox.sessions.Session) -> None: @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) diff --git a/packages/gapic-generator/gapic/templates/noxfile.py.j2 b/packages/gapic-generator/gapic/templates/noxfile.py.j2 index 36e693412398..99ac9791bcf1 100644 --- a/packages/gapic-generator/gapic/templates/noxfile.py.j2 +++ b/packages/gapic-generator/gapic/templates/noxfile.py.j2 @@ -647,14 +647,20 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") {% if api.naming.module_namespace %} - session.run("python", str(profiler_script), "--module", "{{ api.naming.module_namespace[0] }}", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "{{ api.naming.module_namespace[0] }}", "--iterations", "10" + ) {% else %} - session.run("python", str(profiler_script), "--module", "{{ api.naming.versioned_module_name }}", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "{{ api.naming.versioned_module_name }}", "--iterations", "10" + ) {% endif %} {% endblock %} diff --git a/packages/gapic-generator/noxfile.py b/packages/gapic-generator/noxfile.py index 74e399d573e0..5c7fdaf0f723 100644 --- a/packages/gapic-generator/noxfile.py +++ b/packages/gapic-generator/noxfile.py @@ -726,7 +726,7 @@ def lint(session): """ # TODO(https://github.com/googleapis/google-cloud-python/issues/16186): - # SKIP: This session was not enforced in the standalone (split) repo + # SKIP: This session was not enforced in the standalone (split) repo # and is disabled here to ensure a "move-only" migration. session.skip( "Linting was not enforced in the split repo. " @@ -756,9 +756,11 @@ def lint(session): @nox.session(python=NEWEST_PYTHON) def lint_setup_py(session): # TODO(https://github.com/googleapis/google-cloud-python/issues/16186): - # SKIP: This session was not enforced in the standalone (split) repo + # SKIP: This session was not enforced in the standalone (split) repo # and is disabled here to ensure a "move-only" migration. - session.skip("Skipping now to avoid changing code during migration. See Issue #16186") + session.skip( + "Skipping now to avoid changing code during migration. See Issue #16186" + ) @nox.session(python="3.10") @@ -833,9 +835,11 @@ def prerelease_deps(session, protobuf_implementation): """ Run all tests with pre-release versions of dependencies installed. """ - # TODO(https://github.com/googleapis/google-cloud-python/issues/16184): + # TODO(https://github.com/googleapis/google-cloud-python/issues/16184): # Implement pre-release dependency logic to test against upcoming runtime changes. - session.skip("prerelease_deps session is not yet implemented for gapic-generator-python.") + session.skip( + "prerelease_deps session is not yet implemented for gapic-generator-python." + ) @nox.session(python=NEWEST_PYTHON) @@ -845,27 +849,38 @@ def prerelease_deps(session, protobuf_implementation): ) def core_deps_from_source(session, protobuf_implementation): """Run all tests with core dependencies installed from source.""" - # TODO(https://github.com/googleapis/google-cloud-python/issues/16185): + # TODO(https://github.com/googleapis/google-cloud-python/issues/16185): # Implement logic to install core packages directly from the mono-repo directories. - session.skip("core_deps_from_source session is not yet implemented for gapic-generator-python.") + session.skip( + "core_deps_from_source session is not yet implemented for gapic-generator-python." + ) + @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py b/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py index 1885a2683db1..97fcd4a4f33c 100755 --- a/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py @@ -48,7 +48,11 @@ # Path to the centralized mypy configuration file at the repository root. # Search upwards to support running nox from both monorepo packages and integration test goldens. MYPY_CONFIG_FILE = next( - (str(p / "mypy.ini") for p in CURRENT_DIRECTORY.parents if (p / "mypy.ini").exists()), + ( + str(p / "mypy.ini") + for p in CURRENT_DIRECTORY.parents + if (p / "mypy.ini").exists() + ), str(CURRENT_DIRECTORY.parent.parent / "mypy.ini"), ) @@ -164,7 +168,8 @@ def lint(session): # 2. Check formatting session.run( - "ruff", "format", + "ruff", + "format", "--check", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", @@ -177,12 +182,15 @@ def lint(session): @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): """(Deprecated) Legacy session. Please use 'nox -s format'.""" - session.log("WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future.") + session.log( + "WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future." + ) # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) session.install(RUFF_VERSION) session.run( - "ruff", "format", + "ruff", + "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", *LINT_PATHS, @@ -201,8 +209,10 @@ def format(session): # check --select I: Enables strict import sorting # --fix: Applies the changes automatically session.run( - "ruff", "check", - "--select", "I", + "ruff", + "check", + "--select", + "I", "--fix", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length @@ -211,7 +221,8 @@ def format(session): # 3. Run Ruff to format code session.run( - "ruff", "format", + "ruff", + "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length *LINT_PATHS, @@ -396,8 +407,10 @@ def docs(session): "sphinx-build", "-T", # show full traceback on exception "-N", # no colors - "-b", "html", # builder - "-d", os.path.join("docs", "_build", "doctrees", ""), # cache directory + "-b", + "html", # builder + "-d", + os.path.join("docs", "_build", "doctrees", ""), # cache directory # paths to build: os.path.join("docs", ""), os.path.join("docs", "_build", "html", ""), @@ -511,8 +524,7 @@ def prerelease_deps(session, protobuf_implementation): # Extract the base package name, safely ignoring version bounds and spaces # (e.g., "grpcio>=1.75.1" becomes "grpcio") parsed_deps = { - dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) - for dep in prerel_deps + dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) for dep in prerel_deps } # Dynamically sort local packages vs PyPI dependencies @@ -625,7 +637,9 @@ def core_deps_from_source(session, protobuf_implementation): dep_paths = [str(deps_dir / dep) for dep in core_dependencies_from_source] session.install(*dep_paths, "--no-deps", "--ignore-installed") - print(f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}") + print( + f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}" + ) session.run( "py.test", @@ -639,9 +653,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py b/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py index e447c81b9dd3..544c7920db1c 100755 --- a/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py @@ -48,7 +48,11 @@ # Path to the centralized mypy configuration file at the repository root. # Search upwards to support running nox from both monorepo packages and integration test goldens. MYPY_CONFIG_FILE = next( - (str(p / "mypy.ini") for p in CURRENT_DIRECTORY.parents if (p / "mypy.ini").exists()), + ( + str(p / "mypy.ini") + for p in CURRENT_DIRECTORY.parents + if (p / "mypy.ini").exists() + ), str(CURRENT_DIRECTORY.parent.parent / "mypy.ini"), ) @@ -164,7 +168,8 @@ def lint(session): # 2. Check formatting session.run( - "ruff", "format", + "ruff", + "format", "--check", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", @@ -177,12 +182,15 @@ def lint(session): @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): """(Deprecated) Legacy session. Please use 'nox -s format'.""" - session.log("WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future.") + session.log( + "WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future." + ) # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) session.install(RUFF_VERSION) session.run( - "ruff", "format", + "ruff", + "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", *LINT_PATHS, @@ -201,8 +209,10 @@ def format(session): # check --select I: Enables strict import sorting # --fix: Applies the changes automatically session.run( - "ruff", "check", - "--select", "I", + "ruff", + "check", + "--select", + "I", "--fix", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length @@ -211,7 +221,8 @@ def format(session): # 3. Run Ruff to format code session.run( - "ruff", "format", + "ruff", + "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length *LINT_PATHS, @@ -396,8 +407,10 @@ def docs(session): "sphinx-build", "-T", # show full traceback on exception "-N", # no colors - "-b", "html", # builder - "-d", os.path.join("docs", "_build", "doctrees", ""), # cache directory + "-b", + "html", # builder + "-d", + os.path.join("docs", "_build", "doctrees", ""), # cache directory # paths to build: os.path.join("docs", ""), os.path.join("docs", "_build", "html", ""), @@ -511,8 +524,7 @@ def prerelease_deps(session, protobuf_implementation): # Extract the base package name, safely ignoring version bounds and spaces # (e.g., "grpcio>=1.75.1" becomes "grpcio") parsed_deps = { - dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) - for dep in prerel_deps + dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) for dep in prerel_deps } # Dynamically sort local packages vs PyPI dependencies @@ -625,7 +637,9 @@ def core_deps_from_source(session, protobuf_implementation): dep_paths = [str(deps_dir / dep) for dep in core_dependencies_from_source] session.install(*dep_paths, "--no-deps", "--ignore-installed") - print(f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}") + print( + f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}" + ) session.run( "py.test", @@ -639,9 +653,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py b/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py index e9a6e9779a2b..9a32fb5f36c4 100755 --- a/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py @@ -48,7 +48,11 @@ # Path to the centralized mypy configuration file at the repository root. # Search upwards to support running nox from both monorepo packages and integration test goldens. MYPY_CONFIG_FILE = next( - (str(p / "mypy.ini") for p in CURRENT_DIRECTORY.parents if (p / "mypy.ini").exists()), + ( + str(p / "mypy.ini") + for p in CURRENT_DIRECTORY.parents + if (p / "mypy.ini").exists() + ), str(CURRENT_DIRECTORY.parent.parent / "mypy.ini"), ) @@ -164,7 +168,8 @@ def lint(session): # 2. Check formatting session.run( - "ruff", "format", + "ruff", + "format", "--check", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", @@ -177,12 +182,15 @@ def lint(session): @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): """(Deprecated) Legacy session. Please use 'nox -s format'.""" - session.log("WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future.") + session.log( + "WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future." + ) # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) session.install(RUFF_VERSION) session.run( - "ruff", "format", + "ruff", + "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", *LINT_PATHS, @@ -201,8 +209,10 @@ def format(session): # check --select I: Enables strict import sorting # --fix: Applies the changes automatically session.run( - "ruff", "check", - "--select", "I", + "ruff", + "check", + "--select", + "I", "--fix", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length @@ -211,7 +221,8 @@ def format(session): # 3. Run Ruff to format code session.run( - "ruff", "format", + "ruff", + "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length *LINT_PATHS, @@ -396,8 +407,10 @@ def docs(session): "sphinx-build", "-T", # show full traceback on exception "-N", # no colors - "-b", "html", # builder - "-d", os.path.join("docs", "_build", "doctrees", ""), # cache directory + "-b", + "html", # builder + "-d", + os.path.join("docs", "_build", "doctrees", ""), # cache directory # paths to build: os.path.join("docs", ""), os.path.join("docs", "_build", "html", ""), @@ -511,8 +524,7 @@ def prerelease_deps(session, protobuf_implementation): # Extract the base package name, safely ignoring version bounds and spaces # (e.g., "grpcio>=1.75.1" becomes "grpcio") parsed_deps = { - dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) - for dep in prerel_deps + dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) for dep in prerel_deps } # Dynamically sort local packages vs PyPI dependencies @@ -625,7 +637,9 @@ def core_deps_from_source(session, protobuf_implementation): dep_paths = [str(deps_dir / dep) for dep in core_dependencies_from_source] session.install(*dep_paths, "--no-deps", "--ignore-installed") - print(f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}") + print( + f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}" + ) session.run( "py.test", @@ -639,9 +653,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py b/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py index 6ffbbff69aa4..253427faa7e7 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py @@ -48,7 +48,11 @@ # Path to the centralized mypy configuration file at the repository root. # Search upwards to support running nox from both monorepo packages and integration test goldens. MYPY_CONFIG_FILE = next( - (str(p / "mypy.ini") for p in CURRENT_DIRECTORY.parents if (p / "mypy.ini").exists()), + ( + str(p / "mypy.ini") + for p in CURRENT_DIRECTORY.parents + if (p / "mypy.ini").exists() + ), str(CURRENT_DIRECTORY.parent.parent / "mypy.ini"), ) @@ -164,7 +168,8 @@ def lint(session): # 2. Check formatting session.run( - "ruff", "format", + "ruff", + "format", "--check", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", @@ -177,12 +182,15 @@ def lint(session): @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): """(Deprecated) Legacy session. Please use 'nox -s format'.""" - session.log("WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future.") + session.log( + "WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future." + ) # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) session.install(RUFF_VERSION) session.run( - "ruff", "format", + "ruff", + "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", *LINT_PATHS, @@ -201,8 +209,10 @@ def format(session): # check --select I: Enables strict import sorting # --fix: Applies the changes automatically session.run( - "ruff", "check", - "--select", "I", + "ruff", + "check", + "--select", + "I", "--fix", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length @@ -211,7 +221,8 @@ def format(session): # 3. Run Ruff to format code session.run( - "ruff", "format", + "ruff", + "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length *LINT_PATHS, @@ -396,8 +407,10 @@ def docs(session): "sphinx-build", "-T", # show full traceback on exception "-N", # no colors - "-b", "html", # builder - "-d", os.path.join("docs", "_build", "doctrees", ""), # cache directory + "-b", + "html", # builder + "-d", + os.path.join("docs", "_build", "doctrees", ""), # cache directory # paths to build: os.path.join("docs", ""), os.path.join("docs", "_build", "html", ""), @@ -511,8 +524,7 @@ def prerelease_deps(session, protobuf_implementation): # Extract the base package name, safely ignoring version bounds and spaces # (e.g., "grpcio>=1.75.1" becomes "grpcio") parsed_deps = { - dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) - for dep in prerel_deps + dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) for dep in prerel_deps } # Dynamically sort local packages vs PyPI dependencies @@ -625,7 +637,9 @@ def core_deps_from_source(session, protobuf_implementation): dep_paths = [str(deps_dir / dep) for dep in core_dependencies_from_source] session.install(*dep_paths, "--no-deps", "--ignore-installed") - print(f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}") + print( + f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}" + ) session.run( "py.test", @@ -639,9 +653,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py b/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py index 6ffbbff69aa4..253427faa7e7 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py @@ -48,7 +48,11 @@ # Path to the centralized mypy configuration file at the repository root. # Search upwards to support running nox from both monorepo packages and integration test goldens. MYPY_CONFIG_FILE = next( - (str(p / "mypy.ini") for p in CURRENT_DIRECTORY.parents if (p / "mypy.ini").exists()), + ( + str(p / "mypy.ini") + for p in CURRENT_DIRECTORY.parents + if (p / "mypy.ini").exists() + ), str(CURRENT_DIRECTORY.parent.parent / "mypy.ini"), ) @@ -164,7 +168,8 @@ def lint(session): # 2. Check formatting session.run( - "ruff", "format", + "ruff", + "format", "--check", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", @@ -177,12 +182,15 @@ def lint(session): @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): """(Deprecated) Legacy session. Please use 'nox -s format'.""" - session.log("WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future.") + session.log( + "WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future." + ) # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) session.install(RUFF_VERSION) session.run( - "ruff", "format", + "ruff", + "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", *LINT_PATHS, @@ -201,8 +209,10 @@ def format(session): # check --select I: Enables strict import sorting # --fix: Applies the changes automatically session.run( - "ruff", "check", - "--select", "I", + "ruff", + "check", + "--select", + "I", "--fix", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length @@ -211,7 +221,8 @@ def format(session): # 3. Run Ruff to format code session.run( - "ruff", "format", + "ruff", + "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length *LINT_PATHS, @@ -396,8 +407,10 @@ def docs(session): "sphinx-build", "-T", # show full traceback on exception "-N", # no colors - "-b", "html", # builder - "-d", os.path.join("docs", "_build", "doctrees", ""), # cache directory + "-b", + "html", # builder + "-d", + os.path.join("docs", "_build", "doctrees", ""), # cache directory # paths to build: os.path.join("docs", ""), os.path.join("docs", "_build", "html", ""), @@ -511,8 +524,7 @@ def prerelease_deps(session, protobuf_implementation): # Extract the base package name, safely ignoring version bounds and spaces # (e.g., "grpcio>=1.75.1" becomes "grpcio") parsed_deps = { - dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) - for dep in prerel_deps + dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) for dep in prerel_deps } # Dynamically sort local packages vs PyPI dependencies @@ -625,7 +637,9 @@ def core_deps_from_source(session, protobuf_implementation): dep_paths = [str(deps_dir / dep) for dep in core_dependencies_from_source] session.install(*dep_paths, "--no-deps", "--ignore-installed") - print(f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}") + print( + f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}" + ) session.run( "py.test", @@ -639,9 +653,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py b/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py index 855f4d2f0df9..cb6dcce4c06b 100755 --- a/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py @@ -48,7 +48,11 @@ # Path to the centralized mypy configuration file at the repository root. # Search upwards to support running nox from both monorepo packages and integration test goldens. MYPY_CONFIG_FILE = next( - (str(p / "mypy.ini") for p in CURRENT_DIRECTORY.parents if (p / "mypy.ini").exists()), + ( + str(p / "mypy.ini") + for p in CURRENT_DIRECTORY.parents + if (p / "mypy.ini").exists() + ), str(CURRENT_DIRECTORY.parent.parent / "mypy.ini"), ) @@ -164,7 +168,8 @@ def lint(session): # 2. Check formatting session.run( - "ruff", "format", + "ruff", + "format", "--check", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", @@ -177,12 +182,15 @@ def lint(session): @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): """(Deprecated) Legacy session. Please use 'nox -s format'.""" - session.log("WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future.") + session.log( + "WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future." + ) # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) session.install(RUFF_VERSION) session.run( - "ruff", "format", + "ruff", + "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", *LINT_PATHS, @@ -201,8 +209,10 @@ def format(session): # check --select I: Enables strict import sorting # --fix: Applies the changes automatically session.run( - "ruff", "check", - "--select", "I", + "ruff", + "check", + "--select", + "I", "--fix", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length @@ -211,7 +221,8 @@ def format(session): # 3. Run Ruff to format code session.run( - "ruff", "format", + "ruff", + "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length *LINT_PATHS, @@ -396,8 +407,10 @@ def docs(session): "sphinx-build", "-T", # show full traceback on exception "-N", # no colors - "-b", "html", # builder - "-d", os.path.join("docs", "_build", "doctrees", ""), # cache directory + "-b", + "html", # builder + "-d", + os.path.join("docs", "_build", "doctrees", ""), # cache directory # paths to build: os.path.join("docs", ""), os.path.join("docs", "_build", "html", ""), @@ -511,8 +524,7 @@ def prerelease_deps(session, protobuf_implementation): # Extract the base package name, safely ignoring version bounds and spaces # (e.g., "grpcio>=1.75.1" becomes "grpcio") parsed_deps = { - dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) - for dep in prerel_deps + dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) for dep in prerel_deps } # Dynamically sort local packages vs PyPI dependencies @@ -625,7 +637,9 @@ def core_deps_from_source(session, protobuf_implementation): dep_paths = [str(deps_dir / dep) for dep in core_dependencies_from_source] session.install(*dep_paths, "--no-deps", "--ignore-installed") - print(f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}") + print( + f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}" + ) session.run( "py.test", @@ -639,9 +653,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py b/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py index 855f4d2f0df9..cb6dcce4c06b 100755 --- a/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py @@ -48,7 +48,11 @@ # Path to the centralized mypy configuration file at the repository root. # Search upwards to support running nox from both monorepo packages and integration test goldens. MYPY_CONFIG_FILE = next( - (str(p / "mypy.ini") for p in CURRENT_DIRECTORY.parents if (p / "mypy.ini").exists()), + ( + str(p / "mypy.ini") + for p in CURRENT_DIRECTORY.parents + if (p / "mypy.ini").exists() + ), str(CURRENT_DIRECTORY.parent.parent / "mypy.ini"), ) @@ -164,7 +168,8 @@ def lint(session): # 2. Check formatting session.run( - "ruff", "format", + "ruff", + "format", "--check", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", @@ -177,12 +182,15 @@ def lint(session): @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): """(Deprecated) Legacy session. Please use 'nox -s format'.""" - session.log("WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future.") + session.log( + "WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future." + ) # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) session.install(RUFF_VERSION) session.run( - "ruff", "format", + "ruff", + "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", *LINT_PATHS, @@ -201,8 +209,10 @@ def format(session): # check --select I: Enables strict import sorting # --fix: Applies the changes automatically session.run( - "ruff", "check", - "--select", "I", + "ruff", + "check", + "--select", + "I", "--fix", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length @@ -211,7 +221,8 @@ def format(session): # 3. Run Ruff to format code session.run( - "ruff", "format", + "ruff", + "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length *LINT_PATHS, @@ -396,8 +407,10 @@ def docs(session): "sphinx-build", "-T", # show full traceback on exception "-N", # no colors - "-b", "html", # builder - "-d", os.path.join("docs", "_build", "doctrees", ""), # cache directory + "-b", + "html", # builder + "-d", + os.path.join("docs", "_build", "doctrees", ""), # cache directory # paths to build: os.path.join("docs", ""), os.path.join("docs", "_build", "html", ""), @@ -511,8 +524,7 @@ def prerelease_deps(session, protobuf_implementation): # Extract the base package name, safely ignoring version bounds and spaces # (e.g., "grpcio>=1.75.1" becomes "grpcio") parsed_deps = { - dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) - for dep in prerel_deps + dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) for dep in prerel_deps } # Dynamically sort local packages vs PyPI dependencies @@ -625,7 +637,9 @@ def core_deps_from_source(session, protobuf_implementation): dep_paths = [str(deps_dir / dep) for dep in core_dependencies_from_source] session.install(*dep_paths, "--no-deps", "--ignore-installed") - print(f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}") + print( + f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}" + ) session.run( "py.test", @@ -639,9 +653,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py b/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py index d6ad1c1638c6..bf37e75a229f 100755 --- a/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py @@ -48,7 +48,11 @@ # Path to the centralized mypy configuration file at the repository root. # Search upwards to support running nox from both monorepo packages and integration test goldens. MYPY_CONFIG_FILE = next( - (str(p / "mypy.ini") for p in CURRENT_DIRECTORY.parents if (p / "mypy.ini").exists()), + ( + str(p / "mypy.ini") + for p in CURRENT_DIRECTORY.parents + if (p / "mypy.ini").exists() + ), str(CURRENT_DIRECTORY.parent.parent / "mypy.ini"), ) @@ -164,7 +168,8 @@ def lint(session): # 2. Check formatting session.run( - "ruff", "format", + "ruff", + "format", "--check", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", @@ -177,12 +182,15 @@ def lint(session): @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): """(Deprecated) Legacy session. Please use 'nox -s format'.""" - session.log("WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future.") + session.log( + "WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future." + ) # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) session.install(RUFF_VERSION) session.run( - "ruff", "format", + "ruff", + "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", *LINT_PATHS, @@ -201,8 +209,10 @@ def format(session): # check --select I: Enables strict import sorting # --fix: Applies the changes automatically session.run( - "ruff", "check", - "--select", "I", + "ruff", + "check", + "--select", + "I", "--fix", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length @@ -211,7 +221,8 @@ def format(session): # 3. Run Ruff to format code session.run( - "ruff", "format", + "ruff", + "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length *LINT_PATHS, @@ -396,8 +407,10 @@ def docs(session): "sphinx-build", "-T", # show full traceback on exception "-N", # no colors - "-b", "html", # builder - "-d", os.path.join("docs", "_build", "doctrees", ""), # cache directory + "-b", + "html", # builder + "-d", + os.path.join("docs", "_build", "doctrees", ""), # cache directory # paths to build: os.path.join("docs", ""), os.path.join("docs", "_build", "html", ""), @@ -511,8 +524,7 @@ def prerelease_deps(session, protobuf_implementation): # Extract the base package name, safely ignoring version bounds and spaces # (e.g., "grpcio>=1.75.1" becomes "grpcio") parsed_deps = { - dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) - for dep in prerel_deps + dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) for dep in prerel_deps } # Dynamically sort local packages vs PyPI dependencies @@ -625,7 +637,9 @@ def core_deps_from_source(session, protobuf_implementation): dep_paths = [str(deps_dir / dep) for dep in core_dependencies_from_source] session.install(*dep_paths, "--no-deps", "--ignore-installed") - print(f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}") + print( + f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}" + ) session.run( "py.test", @@ -639,9 +653,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/gcp-sphinx-docfx-yaml/noxfile.py b/packages/gcp-sphinx-docfx-yaml/noxfile.py index 831320d8859c..0a0ddbca4242 100644 --- a/packages/gcp-sphinx-docfx-yaml/noxfile.py +++ b/packages/gcp-sphinx-docfx-yaml/noxfile.py @@ -178,20 +178,38 @@ def docfx(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) diff --git a/packages/google-ads-admanager/noxfile.py b/packages/google-ads-admanager/noxfile.py index 7b5846c6af8c..ca5891156343 100644 --- a/packages/google-ads-admanager/noxfile.py +++ b/packages/google-ads-admanager/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-ads-datamanager/noxfile.py b/packages/google-ads-datamanager/noxfile.py index 54b9753ebf22..e6ce28e544af 100644 --- a/packages/google-ads-datamanager/noxfile.py +++ b/packages/google-ads-datamanager/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-ads-marketingplatform-admin/noxfile.py b/packages/google-ads-marketingplatform-admin/noxfile.py index ce2e6ebac363..35b098b07f61 100644 --- a/packages/google-ads-marketingplatform-admin/noxfile.py +++ b/packages/google-ads-marketingplatform-admin/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-ai-generativelanguage/noxfile.py b/packages/google-ai-generativelanguage/noxfile.py index c0653be6b998..241254eafdbe 100644 --- a/packages/google-ai-generativelanguage/noxfile.py +++ b/packages/google-ai-generativelanguage/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-analytics-admin/noxfile.py b/packages/google-analytics-admin/noxfile.py index 17843932c73e..1960dc88a7bb 100644 --- a/packages/google-analytics-admin/noxfile.py +++ b/packages/google-analytics-admin/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-analytics-data/noxfile.py b/packages/google-analytics-data/noxfile.py index 59a18e6bbbee..20b8ab823916 100644 --- a/packages/google-analytics-data/noxfile.py +++ b/packages/google-analytics-data/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-api-core/noxfile.py b/packages/google-api-core/noxfile.py index ccafe9d306df..c3695042fca3 100644 --- a/packages/google-api-core/noxfile.py +++ b/packages/google-api-core/noxfile.py @@ -469,20 +469,38 @@ def docfx(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) diff --git a/packages/google-apps-card/noxfile.py b/packages/google-apps-card/noxfile.py index 8df8b6008263..d20f7d5ba040 100644 --- a/packages/google-apps-card/noxfile.py +++ b/packages/google-apps-card/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-apps-chat/noxfile.py b/packages/google-apps-chat/noxfile.py index 4a1e1735ef3c..f00bb92a3913 100644 --- a/packages/google-apps-chat/noxfile.py +++ b/packages/google-apps-chat/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-apps-events-subscriptions/noxfile.py b/packages/google-apps-events-subscriptions/noxfile.py index a6fdcd46d2fd..4b056242d52a 100644 --- a/packages/google-apps-events-subscriptions/noxfile.py +++ b/packages/google-apps-events-subscriptions/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-apps-meet/noxfile.py b/packages/google-apps-meet/noxfile.py index 1549a3d26157..990c53016d03 100644 --- a/packages/google-apps-meet/noxfile.py +++ b/packages/google-apps-meet/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-apps-script-type/noxfile.py b/packages/google-apps-script-type/noxfile.py index ba75e8ea1712..faf035bfbec7 100644 --- a/packages/google-apps-script-type/noxfile.py +++ b/packages/google-apps-script-type/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-area120-tables/noxfile.py b/packages/google-area120-tables/noxfile.py index 1e79cbee6b3b..b749184e463d 100644 --- a/packages/google-area120-tables/noxfile.py +++ b/packages/google-area120-tables/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-auth-httplib2/noxfile.py b/packages/google-auth-httplib2/noxfile.py index 69d9e5ec2a03..61963457529d 100644 --- a/packages/google-auth-httplib2/noxfile.py +++ b/packages/google-auth-httplib2/noxfile.py @@ -534,20 +534,38 @@ def core_deps_from_source(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) diff --git a/packages/google-auth-oauthlib/noxfile.py b/packages/google-auth-oauthlib/noxfile.py index 676fc0f6f676..3fbbc2574605 100644 --- a/packages/google-auth-oauthlib/noxfile.py +++ b/packages/google-auth-oauthlib/noxfile.py @@ -479,20 +479,38 @@ def mypy(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google_auth_oauthlib", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "google_auth_oauthlib", + "--iterations", + "10", + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google_auth_oauthlib", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "google_auth_oauthlib", + "--iterations", + "10", + ) diff --git a/packages/google-auth/noxfile.py b/packages/google-auth/noxfile.py index 6290254a760c..73d54dd552ea 100644 --- a/packages/google-auth/noxfile.py +++ b/packages/google-auth/noxfile.py @@ -320,9 +320,13 @@ def core_deps_from_source(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-backstory/noxfile.py b/packages/google-backstory/noxfile.py index f6d2d02fc2a5..b6a76a5fd89e 100644 --- a/packages/google-backstory/noxfile.py +++ b/packages/google-backstory/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-access-approval/noxfile.py b/packages/google-cloud-access-approval/noxfile.py index e534c419d651..0bf1d2f89449 100644 --- a/packages/google-cloud-access-approval/noxfile.py +++ b/packages/google-cloud-access-approval/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-access-context-manager/noxfile.py b/packages/google-cloud-access-context-manager/noxfile.py index 7f9a8209e9df..f7b7b5a0f50c 100644 --- a/packages/google-cloud-access-context-manager/noxfile.py +++ b/packages/google-cloud-access-context-manager/noxfile.py @@ -583,9 +583,18 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) diff --git a/packages/google-cloud-advisorynotifications/noxfile.py b/packages/google-cloud-advisorynotifications/noxfile.py index 2f88e9557a66..dd5c027e2217 100644 --- a/packages/google-cloud-advisorynotifications/noxfile.py +++ b/packages/google-cloud-advisorynotifications/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-agentidentitycredentials/noxfile.py b/packages/google-cloud-agentidentitycredentials/noxfile.py index f9357d466a43..f50a762ce36c 100644 --- a/packages/google-cloud-agentidentitycredentials/noxfile.py +++ b/packages/google-cloud-agentidentitycredentials/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-agentregistry/noxfile.py b/packages/google-cloud-agentregistry/noxfile.py index 8bf7a77f7ff9..97e3d3154f1f 100644 --- a/packages/google-cloud-agentregistry/noxfile.py +++ b/packages/google-cloud-agentregistry/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-alloydb-connectors/noxfile.py b/packages/google-cloud-alloydb-connectors/noxfile.py index ee364a7ddb12..56359ca978f1 100644 --- a/packages/google-cloud-alloydb-connectors/noxfile.py +++ b/packages/google-cloud-alloydb-connectors/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-alloydb/noxfile.py b/packages/google-cloud-alloydb/noxfile.py index 1185272bf86a..79e3e99c6c16 100644 --- a/packages/google-cloud-alloydb/noxfile.py +++ b/packages/google-cloud-alloydb/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-api-gateway/noxfile.py b/packages/google-cloud-api-gateway/noxfile.py index c9a0bdbdb855..bf4fd36037ab 100644 --- a/packages/google-cloud-api-gateway/noxfile.py +++ b/packages/google-cloud-api-gateway/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-api-keys/noxfile.py b/packages/google-cloud-api-keys/noxfile.py index 55f5d21afd48..5bc06a2075cf 100644 --- a/packages/google-cloud-api-keys/noxfile.py +++ b/packages/google-cloud-api-keys/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-apigee-connect/noxfile.py b/packages/google-cloud-apigee-connect/noxfile.py index 100ba24c5ffe..7a01f81e5dd4 100644 --- a/packages/google-cloud-apigee-connect/noxfile.py +++ b/packages/google-cloud-apigee-connect/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-apigee-registry/noxfile.py b/packages/google-cloud-apigee-registry/noxfile.py index a6b2b4ba5f48..5a2ad8e87d7d 100644 --- a/packages/google-cloud-apigee-registry/noxfile.py +++ b/packages/google-cloud-apigee-registry/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-apihub/noxfile.py b/packages/google-cloud-apihub/noxfile.py index dd5d323c757c..2b23e83f5494 100644 --- a/packages/google-cloud-apihub/noxfile.py +++ b/packages/google-cloud-apihub/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-apiregistry/noxfile.py b/packages/google-cloud-apiregistry/noxfile.py index b6c1d6ac7481..c59033e40344 100644 --- a/packages/google-cloud-apiregistry/noxfile.py +++ b/packages/google-cloud-apiregistry/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-appengine-admin/noxfile.py b/packages/google-cloud-appengine-admin/noxfile.py index 25883de1067d..c833f6489926 100644 --- a/packages/google-cloud-appengine-admin/noxfile.py +++ b/packages/google-cloud-appengine-admin/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-appengine-logging/noxfile.py b/packages/google-cloud-appengine-logging/noxfile.py index 55e7593b8934..2f2de9157d09 100644 --- a/packages/google-cloud-appengine-logging/noxfile.py +++ b/packages/google-cloud-appengine-logging/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-apphub/noxfile.py b/packages/google-cloud-apphub/noxfile.py index 6f90381fde57..9b6fc35cc97b 100644 --- a/packages/google-cloud-apphub/noxfile.py +++ b/packages/google-cloud-apphub/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-appoptimize/noxfile.py b/packages/google-cloud-appoptimize/noxfile.py index 6a011c8dc7f5..3eab3fa788cc 100644 --- a/packages/google-cloud-appoptimize/noxfile.py +++ b/packages/google-cloud-appoptimize/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-artifact-registry/noxfile.py b/packages/google-cloud-artifact-registry/noxfile.py index ec6500e50a3d..aeade22821e0 100644 --- a/packages/google-cloud-artifact-registry/noxfile.py +++ b/packages/google-cloud-artifact-registry/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-asset/noxfile.py b/packages/google-cloud-asset/noxfile.py index fade43d2ff51..960608c217dc 100644 --- a/packages/google-cloud-asset/noxfile.py +++ b/packages/google-cloud-asset/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-assured-workloads/noxfile.py b/packages/google-cloud-assured-workloads/noxfile.py index dff167c9c185..c14a94b483cd 100644 --- a/packages/google-cloud-assured-workloads/noxfile.py +++ b/packages/google-cloud-assured-workloads/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-audit-log/noxfile.py b/packages/google-cloud-audit-log/noxfile.py index a1494188c877..4c77684320a8 100644 --- a/packages/google-cloud-audit-log/noxfile.py +++ b/packages/google-cloud-audit-log/noxfile.py @@ -569,9 +569,18 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) diff --git a/packages/google-cloud-auditmanager/noxfile.py b/packages/google-cloud-auditmanager/noxfile.py index 6315274c6303..ce11b46ff632 100644 --- a/packages/google-cloud-auditmanager/noxfile.py +++ b/packages/google-cloud-auditmanager/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-automl/noxfile.py b/packages/google-cloud-automl/noxfile.py index 3e99d09897cf..fe31524cc67f 100644 --- a/packages/google-cloud-automl/noxfile.py +++ b/packages/google-cloud-automl/noxfile.py @@ -644,9 +644,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-backupdr/noxfile.py b/packages/google-cloud-backupdr/noxfile.py index 67cce62d83f4..fd424de54dd6 100644 --- a/packages/google-cloud-backupdr/noxfile.py +++ b/packages/google-cloud-backupdr/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-bare-metal-solution/noxfile.py b/packages/google-cloud-bare-metal-solution/noxfile.py index 0c3ec658bbdb..a5dde33df129 100644 --- a/packages/google-cloud-bare-metal-solution/noxfile.py +++ b/packages/google-cloud-bare-metal-solution/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-batch/noxfile.py b/packages/google-cloud-batch/noxfile.py index 68d429a14b14..2f371117de91 100644 --- a/packages/google-cloud-batch/noxfile.py +++ b/packages/google-cloud-batch/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-beyondcorp-appconnections/noxfile.py b/packages/google-cloud-beyondcorp-appconnections/noxfile.py index 3e1ac6477f1a..03579ee771c1 100644 --- a/packages/google-cloud-beyondcorp-appconnections/noxfile.py +++ b/packages/google-cloud-beyondcorp-appconnections/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-beyondcorp-appconnectors/noxfile.py b/packages/google-cloud-beyondcorp-appconnectors/noxfile.py index d491ec676771..e336e0bdf0a4 100644 --- a/packages/google-cloud-beyondcorp-appconnectors/noxfile.py +++ b/packages/google-cloud-beyondcorp-appconnectors/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-beyondcorp-appgateways/noxfile.py b/packages/google-cloud-beyondcorp-appgateways/noxfile.py index f3abdded611b..b90136f9fcc4 100644 --- a/packages/google-cloud-beyondcorp-appgateways/noxfile.py +++ b/packages/google-cloud-beyondcorp-appgateways/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py b/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py index b4938335fe66..1bd252b2e5d1 100644 --- a/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py +++ b/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-beyondcorp-clientgateways/noxfile.py b/packages/google-cloud-beyondcorp-clientgateways/noxfile.py index 7e87fd5b17fc..25f236175d02 100644 --- a/packages/google-cloud-beyondcorp-clientgateways/noxfile.py +++ b/packages/google-cloud-beyondcorp-clientgateways/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-biglake-hive/noxfile.py b/packages/google-cloud-biglake-hive/noxfile.py index 743f1082b76c..e584d65a2040 100644 --- a/packages/google-cloud-biglake-hive/noxfile.py +++ b/packages/google-cloud-biglake-hive/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-biglake/noxfile.py b/packages/google-cloud-biglake/noxfile.py index c2ec79f71bf3..8c855f291049 100644 --- a/packages/google-cloud-biglake/noxfile.py +++ b/packages/google-cloud-biglake/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-bigquery-analyticshub/noxfile.py b/packages/google-cloud-bigquery-analyticshub/noxfile.py index dce2d46f8250..40a147fb093a 100644 --- a/packages/google-cloud-bigquery-analyticshub/noxfile.py +++ b/packages/google-cloud-bigquery-analyticshub/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-bigquery-biglake/noxfile.py b/packages/google-cloud-bigquery-biglake/noxfile.py index 33ef4cb99658..d963e7ca2ce6 100644 --- a/packages/google-cloud-bigquery-biglake/noxfile.py +++ b/packages/google-cloud-bigquery-biglake/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-bigquery-connection/noxfile.py b/packages/google-cloud-bigquery-connection/noxfile.py index e16361e6f30d..477e2abac239 100644 --- a/packages/google-cloud-bigquery-connection/noxfile.py +++ b/packages/google-cloud-bigquery-connection/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-bigquery-data-exchange/noxfile.py b/packages/google-cloud-bigquery-data-exchange/noxfile.py index d16b8d11c685..cafc3fb2da5e 100644 --- a/packages/google-cloud-bigquery-data-exchange/noxfile.py +++ b/packages/google-cloud-bigquery-data-exchange/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-bigquery-datapolicies/noxfile.py b/packages/google-cloud-bigquery-datapolicies/noxfile.py index 81271a06b1f3..514e9ab4f54b 100644 --- a/packages/google-cloud-bigquery-datapolicies/noxfile.py +++ b/packages/google-cloud-bigquery-datapolicies/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-bigquery-datatransfer/noxfile.py b/packages/google-cloud-bigquery-datatransfer/noxfile.py index 1ff577f7b490..86f165efd67f 100644 --- a/packages/google-cloud-bigquery-datatransfer/noxfile.py +++ b/packages/google-cloud-bigquery-datatransfer/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-bigquery-logging/noxfile.py b/packages/google-cloud-bigquery-logging/noxfile.py index e5fa221f0a7b..aecb1b0106d2 100644 --- a/packages/google-cloud-bigquery-logging/noxfile.py +++ b/packages/google-cloud-bigquery-logging/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-bigquery-migration/noxfile.py b/packages/google-cloud-bigquery-migration/noxfile.py index bcc2078df6e3..37754fbecb59 100644 --- a/packages/google-cloud-bigquery-migration/noxfile.py +++ b/packages/google-cloud-bigquery-migration/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-bigquery-reservation/noxfile.py b/packages/google-cloud-bigquery-reservation/noxfile.py index 19fc4345593a..19d38b6ec392 100644 --- a/packages/google-cloud-bigquery-reservation/noxfile.py +++ b/packages/google-cloud-bigquery-reservation/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-bigquery-storage/noxfile.py b/packages/google-cloud-bigquery-storage/noxfile.py index 4498c002df3c..d5b5616fe6e0 100644 --- a/packages/google-cloud-bigquery-storage/noxfile.py +++ b/packages/google-cloud-bigquery-storage/noxfile.py @@ -684,9 +684,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-bigquery/noxfile.py b/packages/google-cloud-bigquery/noxfile.py index 86f9a9f406ad..07291c38f5b5 100644 --- a/packages/google-cloud-bigquery/noxfile.py +++ b/packages/google-cloud-bigquery/noxfile.py @@ -591,20 +591,28 @@ def format(session: nox.sessions.Session) -> None: @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-bigtable/noxfile.py b/packages/google-cloud-bigtable/noxfile.py index cf6a1e6b6b2e..3444d65a2ac1 100644 --- a/packages/google-cloud-bigtable/noxfile.py +++ b/packages/google-cloud-bigtable/noxfile.py @@ -630,20 +630,38 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google.cloud.bigtable.data", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "google.cloud.bigtable.data", + "--iterations", + "10", + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google.cloud.bigtable.data", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "google.cloud.bigtable.data", + "--iterations", + "10", + ) diff --git a/packages/google-cloud-billing-budgets/noxfile.py b/packages/google-cloud-billing-budgets/noxfile.py index 568deec95b25..0de09557cc35 100644 --- a/packages/google-cloud-billing-budgets/noxfile.py +++ b/packages/google-cloud-billing-budgets/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-billing/noxfile.py b/packages/google-cloud-billing/noxfile.py index 831460ef7a97..25edc73ec721 100644 --- a/packages/google-cloud-billing/noxfile.py +++ b/packages/google-cloud-billing/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-binary-authorization/noxfile.py b/packages/google-cloud-binary-authorization/noxfile.py index b49c60e85c7f..491bc9cbafee 100644 --- a/packages/google-cloud-binary-authorization/noxfile.py +++ b/packages/google-cloud-binary-authorization/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-build/noxfile.py b/packages/google-cloud-build/noxfile.py index e9dc4c3cf4c6..97072556b717 100644 --- a/packages/google-cloud-build/noxfile.py +++ b/packages/google-cloud-build/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-capacityplanner/noxfile.py b/packages/google-cloud-capacityplanner/noxfile.py index db4f8b3f4445..24651dc38879 100644 --- a/packages/google-cloud-capacityplanner/noxfile.py +++ b/packages/google-cloud-capacityplanner/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-certificate-manager/noxfile.py b/packages/google-cloud-certificate-manager/noxfile.py index 063770c91f7b..9cf80c5b1f3e 100644 --- a/packages/google-cloud-certificate-manager/noxfile.py +++ b/packages/google-cloud-certificate-manager/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-ces/noxfile.py b/packages/google-cloud-ces/noxfile.py index 6ea471f71210..5eda0360d316 100644 --- a/packages/google-cloud-ces/noxfile.py +++ b/packages/google-cloud-ces/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-channel/noxfile.py b/packages/google-cloud-channel/noxfile.py index 682a7a97bad5..ad716c849749 100644 --- a/packages/google-cloud-channel/noxfile.py +++ b/packages/google-cloud-channel/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-chronicle/noxfile.py b/packages/google-cloud-chronicle/noxfile.py index 8e0561c2a8bf..f8d5376496e2 100644 --- a/packages/google-cloud-chronicle/noxfile.py +++ b/packages/google-cloud-chronicle/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-cloudcontrolspartner/noxfile.py b/packages/google-cloud-cloudcontrolspartner/noxfile.py index a45703c76843..1c7da30a1353 100644 --- a/packages/google-cloud-cloudcontrolspartner/noxfile.py +++ b/packages/google-cloud-cloudcontrolspartner/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-cloudsecuritycompliance/noxfile.py b/packages/google-cloud-cloudsecuritycompliance/noxfile.py index 2016f309aa6d..a439a9c00767 100644 --- a/packages/google-cloud-cloudsecuritycompliance/noxfile.py +++ b/packages/google-cloud-cloudsecuritycompliance/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-commerce-consumer-procurement/noxfile.py b/packages/google-cloud-commerce-consumer-procurement/noxfile.py index 3edbe11eeed0..311947f8107f 100644 --- a/packages/google-cloud-commerce-consumer-procurement/noxfile.py +++ b/packages/google-cloud-commerce-consumer-procurement/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-common/noxfile.py b/packages/google-cloud-common/noxfile.py index 4bbfa9622c81..ca4c9cba4b16 100644 --- a/packages/google-cloud-common/noxfile.py +++ b/packages/google-cloud-common/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-compute-v1beta/noxfile.py b/packages/google-cloud-compute-v1beta/noxfile.py index 8010fb748d48..0a039e1cbb33 100644 --- a/packages/google-cloud-compute-v1beta/noxfile.py +++ b/packages/google-cloud-compute-v1beta/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-compute/noxfile.py b/packages/google-cloud-compute/noxfile.py index 756175b8b7c5..2e755609e4fb 100644 --- a/packages/google-cloud-compute/noxfile.py +++ b/packages/google-cloud-compute/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-confidentialcomputing/noxfile.py b/packages/google-cloud-confidentialcomputing/noxfile.py index 1de7ccf909a7..857dbbdaf8c7 100644 --- a/packages/google-cloud-confidentialcomputing/noxfile.py +++ b/packages/google-cloud-confidentialcomputing/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-config/noxfile.py b/packages/google-cloud-config/noxfile.py index f44b34c08ec6..961e33e80a07 100644 --- a/packages/google-cloud-config/noxfile.py +++ b/packages/google-cloud-config/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-configdelivery/noxfile.py b/packages/google-cloud-configdelivery/noxfile.py index 00b94e612a98..7ffc9ba9e754 100644 --- a/packages/google-cloud-configdelivery/noxfile.py +++ b/packages/google-cloud-configdelivery/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-contact-center-insights/noxfile.py b/packages/google-cloud-contact-center-insights/noxfile.py index 05b4590e54e6..07bfcb647ae4 100644 --- a/packages/google-cloud-contact-center-insights/noxfile.py +++ b/packages/google-cloud-contact-center-insights/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-container/noxfile.py b/packages/google-cloud-container/noxfile.py index 03bc0c1a0fbe..6c2ecb978e67 100644 --- a/packages/google-cloud-container/noxfile.py +++ b/packages/google-cloud-container/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-containeranalysis/noxfile.py b/packages/google-cloud-containeranalysis/noxfile.py index 5c3898b3e14d..fc37a9820b48 100644 --- a/packages/google-cloud-containeranalysis/noxfile.py +++ b/packages/google-cloud-containeranalysis/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-contentwarehouse/noxfile.py b/packages/google-cloud-contentwarehouse/noxfile.py index 9c30a9dabf2a..a666b63aad5a 100644 --- a/packages/google-cloud-contentwarehouse/noxfile.py +++ b/packages/google-cloud-contentwarehouse/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-core/noxfile.py b/packages/google-cloud-core/noxfile.py index 55da68a79d32..cc39a19624af 100644 --- a/packages/google-cloud-core/noxfile.py +++ b/packages/google-cloud-core/noxfile.py @@ -423,20 +423,28 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-data-fusion/noxfile.py b/packages/google-cloud-data-fusion/noxfile.py index a5c450db08cb..0dad41a7f641 100644 --- a/packages/google-cloud-data-fusion/noxfile.py +++ b/packages/google-cloud-data-fusion/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-data-qna/noxfile.py b/packages/google-cloud-data-qna/noxfile.py index 48bbc441001a..fc8596401d90 100644 --- a/packages/google-cloud-data-qna/noxfile.py +++ b/packages/google-cloud-data-qna/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-databasecenter/noxfile.py b/packages/google-cloud-databasecenter/noxfile.py index 5f436d159f54..dc8f40efc52f 100644 --- a/packages/google-cloud-databasecenter/noxfile.py +++ b/packages/google-cloud-databasecenter/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-datacatalog-lineage-configmanagement/noxfile.py b/packages/google-cloud-datacatalog-lineage-configmanagement/noxfile.py index 2102fa18e34b..3c50903d597b 100644 --- a/packages/google-cloud-datacatalog-lineage-configmanagement/noxfile.py +++ b/packages/google-cloud-datacatalog-lineage-configmanagement/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-datacatalog-lineage/noxfile.py b/packages/google-cloud-datacatalog-lineage/noxfile.py index d7976a56eed4..64fed32b57b5 100644 --- a/packages/google-cloud-datacatalog-lineage/noxfile.py +++ b/packages/google-cloud-datacatalog-lineage/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-datacatalog/noxfile.py b/packages/google-cloud-datacatalog/noxfile.py index 2d3aef27f7d3..7c979390c252 100644 --- a/packages/google-cloud-datacatalog/noxfile.py +++ b/packages/google-cloud-datacatalog/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-dataflow-client/noxfile.py b/packages/google-cloud-dataflow-client/noxfile.py index 2bc2988f2945..9377fab0c1fb 100644 --- a/packages/google-cloud-dataflow-client/noxfile.py +++ b/packages/google-cloud-dataflow-client/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-dataform/noxfile.py b/packages/google-cloud-dataform/noxfile.py index cb592d2af5b3..036f66474d89 100644 --- a/packages/google-cloud-dataform/noxfile.py +++ b/packages/google-cloud-dataform/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-datalabeling/noxfile.py b/packages/google-cloud-datalabeling/noxfile.py index e0eeeb67be3e..5f1ae073db65 100644 --- a/packages/google-cloud-datalabeling/noxfile.py +++ b/packages/google-cloud-datalabeling/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-dataplex/noxfile.py b/packages/google-cloud-dataplex/noxfile.py index 3ad9d26c2f03..539e7a3189b9 100644 --- a/packages/google-cloud-dataplex/noxfile.py +++ b/packages/google-cloud-dataplex/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-dataproc-metastore/noxfile.py b/packages/google-cloud-dataproc-metastore/noxfile.py index b1545ec301ce..c09a283d9bbc 100644 --- a/packages/google-cloud-dataproc-metastore/noxfile.py +++ b/packages/google-cloud-dataproc-metastore/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-dataproc/noxfile.py b/packages/google-cloud-dataproc/noxfile.py index 543c5019f031..10f0f3d734cb 100644 --- a/packages/google-cloud-dataproc/noxfile.py +++ b/packages/google-cloud-dataproc/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-datastore/noxfile.py b/packages/google-cloud-datastore/noxfile.py index 4abe78dbcc96..d6dd338d95e6 100644 --- a/packages/google-cloud-datastore/noxfile.py +++ b/packages/google-cloud-datastore/noxfile.py @@ -651,9 +651,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-datastream/noxfile.py b/packages/google-cloud-datastream/noxfile.py index 55c24d2f45c2..607a359737b9 100644 --- a/packages/google-cloud-datastream/noxfile.py +++ b/packages/google-cloud-datastream/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-deploy/noxfile.py b/packages/google-cloud-deploy/noxfile.py index d5f9d06bab8e..70c612e6c140 100644 --- a/packages/google-cloud-deploy/noxfile.py +++ b/packages/google-cloud-deploy/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-developerconnect/noxfile.py b/packages/google-cloud-developerconnect/noxfile.py index 92fef7792914..757e6ce4e7f4 100644 --- a/packages/google-cloud-developerconnect/noxfile.py +++ b/packages/google-cloud-developerconnect/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-devicestreaming/noxfile.py b/packages/google-cloud-devicestreaming/noxfile.py index f7bb173e0ffb..cef5cca1fe0c 100644 --- a/packages/google-cloud-devicestreaming/noxfile.py +++ b/packages/google-cloud-devicestreaming/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-dialogflow-cx/noxfile.py b/packages/google-cloud-dialogflow-cx/noxfile.py index 70466ccdc104..6ccf8c4cd0f0 100644 --- a/packages/google-cloud-dialogflow-cx/noxfile.py +++ b/packages/google-cloud-dialogflow-cx/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-dialogflow/noxfile.py b/packages/google-cloud-dialogflow/noxfile.py index 56e97b5e6e72..d87c461e88b7 100644 --- a/packages/google-cloud-dialogflow/noxfile.py +++ b/packages/google-cloud-dialogflow/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-discoveryengine/noxfile.py b/packages/google-cloud-discoveryengine/noxfile.py index 4f79bc93356f..eedfeccd3b48 100644 --- a/packages/google-cloud-discoveryengine/noxfile.py +++ b/packages/google-cloud-discoveryengine/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-dlp/noxfile.py b/packages/google-cloud-dlp/noxfile.py index bb09f9d02423..cd569c4af767 100644 --- a/packages/google-cloud-dlp/noxfile.py +++ b/packages/google-cloud-dlp/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-dms/noxfile.py b/packages/google-cloud-dms/noxfile.py index 3076f7ff7d38..2c90d3cf1e5f 100644 --- a/packages/google-cloud-dms/noxfile.py +++ b/packages/google-cloud-dms/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-dns/noxfile.py b/packages/google-cloud-dns/noxfile.py index 1158eb0e06f1..96b1a9b05830 100644 --- a/packages/google-cloud-dns/noxfile.py +++ b/packages/google-cloud-dns/noxfile.py @@ -518,20 +518,28 @@ def core_deps_from_source(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-documentai-toolbox/noxfile.py b/packages/google-cloud-documentai-toolbox/noxfile.py index 0790258815a5..68febcdb3ace 100644 --- a/packages/google-cloud-documentai-toolbox/noxfile.py +++ b/packages/google-cloud-documentai-toolbox/noxfile.py @@ -552,20 +552,38 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google.cloud.documentai_toolbox", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "google.cloud.documentai_toolbox", + "--iterations", + "10", + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google.cloud.documentai_toolbox", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "google.cloud.documentai_toolbox", + "--iterations", + "10", + ) diff --git a/packages/google-cloud-documentai/noxfile.py b/packages/google-cloud-documentai/noxfile.py index a5285c4ea7e3..df8a45081779 100644 --- a/packages/google-cloud-documentai/noxfile.py +++ b/packages/google-cloud-documentai/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-domains/noxfile.py b/packages/google-cloud-domains/noxfile.py index 1a80bb3dcd01..8c04a20746f9 100644 --- a/packages/google-cloud-domains/noxfile.py +++ b/packages/google-cloud-domains/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-edgecontainer/noxfile.py b/packages/google-cloud-edgecontainer/noxfile.py index 8211ae20c908..209ddddaa162 100644 --- a/packages/google-cloud-edgecontainer/noxfile.py +++ b/packages/google-cloud-edgecontainer/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-edgenetwork/noxfile.py b/packages/google-cloud-edgenetwork/noxfile.py index 220670163ca5..4087e574585f 100644 --- a/packages/google-cloud-edgenetwork/noxfile.py +++ b/packages/google-cloud-edgenetwork/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-enterpriseknowledgegraph/noxfile.py b/packages/google-cloud-enterpriseknowledgegraph/noxfile.py index 28067e5453f6..b9f88a3499f1 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/noxfile.py +++ b/packages/google-cloud-enterpriseknowledgegraph/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-error-reporting/noxfile.py b/packages/google-cloud-error-reporting/noxfile.py index a85f76bffa23..6e934df196a2 100644 --- a/packages/google-cloud-error-reporting/noxfile.py +++ b/packages/google-cloud-error-reporting/noxfile.py @@ -644,9 +644,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-essential-contacts/noxfile.py b/packages/google-cloud-essential-contacts/noxfile.py index ba58f5eb21cb..bd500a6e85d8 100644 --- a/packages/google-cloud-essential-contacts/noxfile.py +++ b/packages/google-cloud-essential-contacts/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-eventarc-publishing/noxfile.py b/packages/google-cloud-eventarc-publishing/noxfile.py index c052b6d90d50..1b2798c5ec5a 100644 --- a/packages/google-cloud-eventarc-publishing/noxfile.py +++ b/packages/google-cloud-eventarc-publishing/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-eventarc/noxfile.py b/packages/google-cloud-eventarc/noxfile.py index 05665493bce8..f4d33773050d 100644 --- a/packages/google-cloud-eventarc/noxfile.py +++ b/packages/google-cloud-eventarc/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-filestore/noxfile.py b/packages/google-cloud-filestore/noxfile.py index d982e49d9d89..63bf6de0a2df 100644 --- a/packages/google-cloud-filestore/noxfile.py +++ b/packages/google-cloud-filestore/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-financialservices/noxfile.py b/packages/google-cloud-financialservices/noxfile.py index f7c50ce6d977..6b2dc7ec14d8 100644 --- a/packages/google-cloud-financialservices/noxfile.py +++ b/packages/google-cloud-financialservices/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-firestore/noxfile.py b/packages/google-cloud-firestore/noxfile.py index e054a7ebcc0a..94d80f339f83 100644 --- a/packages/google-cloud-firestore/noxfile.py +++ b/packages/google-cloud-firestore/noxfile.py @@ -706,9 +706,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-functions/noxfile.py b/packages/google-cloud-functions/noxfile.py index 53207de57455..8e0a43ece7b3 100644 --- a/packages/google-cloud-functions/noxfile.py +++ b/packages/google-cloud-functions/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-gdchardwaremanagement/noxfile.py b/packages/google-cloud-gdchardwaremanagement/noxfile.py index 09a5748ad919..2f3915756dff 100644 --- a/packages/google-cloud-gdchardwaremanagement/noxfile.py +++ b/packages/google-cloud-gdchardwaremanagement/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-geminidataanalytics/noxfile.py b/packages/google-cloud-geminidataanalytics/noxfile.py index 5d11725b0f5a..cb572aa26f4d 100644 --- a/packages/google-cloud-geminidataanalytics/noxfile.py +++ b/packages/google-cloud-geminidataanalytics/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-gke-backup/noxfile.py b/packages/google-cloud-gke-backup/noxfile.py index 980708c79767..6db9b35e0f94 100644 --- a/packages/google-cloud-gke-backup/noxfile.py +++ b/packages/google-cloud-gke-backup/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-gke-connect-gateway/noxfile.py b/packages/google-cloud-gke-connect-gateway/noxfile.py index 19704536cfce..1229d9060642 100644 --- a/packages/google-cloud-gke-connect-gateway/noxfile.py +++ b/packages/google-cloud-gke-connect-gateway/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-gke-hub/noxfile.py b/packages/google-cloud-gke-hub/noxfile.py index 05a58c6dc1b6..a5cadae253e5 100644 --- a/packages/google-cloud-gke-hub/noxfile.py +++ b/packages/google-cloud-gke-hub/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-gke-multicloud/noxfile.py b/packages/google-cloud-gke-multicloud/noxfile.py index 5241f6bd5ccc..1297a6009f33 100644 --- a/packages/google-cloud-gke-multicloud/noxfile.py +++ b/packages/google-cloud-gke-multicloud/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-gkerecommender/noxfile.py b/packages/google-cloud-gkerecommender/noxfile.py index ca79f9bd6493..80a8d33baa66 100644 --- a/packages/google-cloud-gkerecommender/noxfile.py +++ b/packages/google-cloud-gkerecommender/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-gsuiteaddons/noxfile.py b/packages/google-cloud-gsuiteaddons/noxfile.py index 621ca450f3b7..f99a4a9a9cae 100644 --- a/packages/google-cloud-gsuiteaddons/noxfile.py +++ b/packages/google-cloud-gsuiteaddons/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-hypercomputecluster/noxfile.py b/packages/google-cloud-hypercomputecluster/noxfile.py index d9b523165e0d..7f5528c7d680 100644 --- a/packages/google-cloud-hypercomputecluster/noxfile.py +++ b/packages/google-cloud-hypercomputecluster/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-iam-logging/noxfile.py b/packages/google-cloud-iam-logging/noxfile.py index f891e7cb7e29..0c6133eda26a 100644 --- a/packages/google-cloud-iam-logging/noxfile.py +++ b/packages/google-cloud-iam-logging/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-iam/noxfile.py b/packages/google-cloud-iam/noxfile.py index 83b06f1534d0..689280cd44af 100644 --- a/packages/google-cloud-iam/noxfile.py +++ b/packages/google-cloud-iam/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-iamconnectorcredentials/noxfile.py b/packages/google-cloud-iamconnectorcredentials/noxfile.py index 62ee92cf12b1..26208f34cd20 100644 --- a/packages/google-cloud-iamconnectorcredentials/noxfile.py +++ b/packages/google-cloud-iamconnectorcredentials/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-iap/noxfile.py b/packages/google-cloud-iap/noxfile.py index 69e048874a22..ad10713c6a4a 100644 --- a/packages/google-cloud-iap/noxfile.py +++ b/packages/google-cloud-iap/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-ids/noxfile.py b/packages/google-cloud-ids/noxfile.py index 2ccf42a69afa..72f73bc75a1e 100644 --- a/packages/google-cloud-ids/noxfile.py +++ b/packages/google-cloud-ids/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-kms-inventory/noxfile.py b/packages/google-cloud-kms-inventory/noxfile.py index 822422529300..4bd38375888c 100644 --- a/packages/google-cloud-kms-inventory/noxfile.py +++ b/packages/google-cloud-kms-inventory/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-kms/noxfile.py b/packages/google-cloud-kms/noxfile.py index 564d70d191be..0c9dddf6c10d 100644 --- a/packages/google-cloud-kms/noxfile.py +++ b/packages/google-cloud-kms/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-language/noxfile.py b/packages/google-cloud-language/noxfile.py index d9f392d1724d..e5e9676293bb 100644 --- a/packages/google-cloud-language/noxfile.py +++ b/packages/google-cloud-language/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-licensemanager/noxfile.py b/packages/google-cloud-licensemanager/noxfile.py index 05d19c126cb0..d0aaa7b35a9a 100644 --- a/packages/google-cloud-licensemanager/noxfile.py +++ b/packages/google-cloud-licensemanager/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-life-sciences/noxfile.py b/packages/google-cloud-life-sciences/noxfile.py index e566fe46fed2..64bc3bee8615 100644 --- a/packages/google-cloud-life-sciences/noxfile.py +++ b/packages/google-cloud-life-sciences/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-locationfinder/noxfile.py b/packages/google-cloud-locationfinder/noxfile.py index 69af041f04c6..c0d2565e20ea 100644 --- a/packages/google-cloud-locationfinder/noxfile.py +++ b/packages/google-cloud-locationfinder/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-logging/noxfile.py b/packages/google-cloud-logging/noxfile.py index 0119be93a12d..0c08754e0e97 100644 --- a/packages/google-cloud-logging/noxfile.py +++ b/packages/google-cloud-logging/noxfile.py @@ -642,9 +642,18 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) diff --git a/packages/google-cloud-lustre/noxfile.py b/packages/google-cloud-lustre/noxfile.py index 5892185974a6..fa43e4537b2d 100644 --- a/packages/google-cloud-lustre/noxfile.py +++ b/packages/google-cloud-lustre/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-maintenance-api/noxfile.py b/packages/google-cloud-maintenance-api/noxfile.py index aca37e60cced..0cf163c4839b 100644 --- a/packages/google-cloud-maintenance-api/noxfile.py +++ b/packages/google-cloud-maintenance-api/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-managed-identities/noxfile.py b/packages/google-cloud-managed-identities/noxfile.py index 13c5db9b7c12..08c0726fe316 100644 --- a/packages/google-cloud-managed-identities/noxfile.py +++ b/packages/google-cloud-managed-identities/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-managedkafka-schemaregistry/noxfile.py b/packages/google-cloud-managedkafka-schemaregistry/noxfile.py index 3d0d2e9f2bf0..4afb2c248c2d 100644 --- a/packages/google-cloud-managedkafka-schemaregistry/noxfile.py +++ b/packages/google-cloud-managedkafka-schemaregistry/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-managedkafka/noxfile.py b/packages/google-cloud-managedkafka/noxfile.py index 8dff9fcdadc6..ee04bbbe4d8e 100644 --- a/packages/google-cloud-managedkafka/noxfile.py +++ b/packages/google-cloud-managedkafka/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-media-translation/noxfile.py b/packages/google-cloud-media-translation/noxfile.py index dc76d868333d..8aa2fe062c55 100644 --- a/packages/google-cloud-media-translation/noxfile.py +++ b/packages/google-cloud-media-translation/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-memcache/noxfile.py b/packages/google-cloud-memcache/noxfile.py index b1babeb79cf5..2c7e47a63175 100644 --- a/packages/google-cloud-memcache/noxfile.py +++ b/packages/google-cloud-memcache/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-memorystore/noxfile.py b/packages/google-cloud-memorystore/noxfile.py index f3ddf977f489..d1ff25e03612 100644 --- a/packages/google-cloud-memorystore/noxfile.py +++ b/packages/google-cloud-memorystore/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-migrationcenter/noxfile.py b/packages/google-cloud-migrationcenter/noxfile.py index 6dca716c1d6f..a03308fd442c 100644 --- a/packages/google-cloud-migrationcenter/noxfile.py +++ b/packages/google-cloud-migrationcenter/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-modelarmor/noxfile.py b/packages/google-cloud-modelarmor/noxfile.py index 86853024abd9..0c8e0f39a165 100644 --- a/packages/google-cloud-modelarmor/noxfile.py +++ b/packages/google-cloud-modelarmor/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-monitoring-dashboards/noxfile.py b/packages/google-cloud-monitoring-dashboards/noxfile.py index 48baa6e5a93a..391420466ad8 100644 --- a/packages/google-cloud-monitoring-dashboards/noxfile.py +++ b/packages/google-cloud-monitoring-dashboards/noxfile.py @@ -644,9 +644,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-monitoring-metrics-scopes/noxfile.py b/packages/google-cloud-monitoring-metrics-scopes/noxfile.py index e6b062c69273..8940073ef574 100644 --- a/packages/google-cloud-monitoring-metrics-scopes/noxfile.py +++ b/packages/google-cloud-monitoring-metrics-scopes/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-monitoring/noxfile.py b/packages/google-cloud-monitoring/noxfile.py index eda2a76c849c..69ad5d5e5565 100644 --- a/packages/google-cloud-monitoring/noxfile.py +++ b/packages/google-cloud-monitoring/noxfile.py @@ -645,9 +645,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-ndb/noxfile.py b/packages/google-cloud-ndb/noxfile.py index 9f22167f279c..3de992f08df2 100644 --- a/packages/google-cloud-ndb/noxfile.py +++ b/packages/google-cloud-ndb/noxfile.py @@ -553,20 +553,38 @@ def lint_setup_py(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google.cloud.ndb", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "google.cloud.ndb", + "--iterations", + "10", + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google.cloud.ndb", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "google.cloud.ndb", + "--iterations", + "10", + ) diff --git a/packages/google-cloud-netapp/noxfile.py b/packages/google-cloud-netapp/noxfile.py index f4cb3ea907df..97daa1939030 100644 --- a/packages/google-cloud-netapp/noxfile.py +++ b/packages/google-cloud-netapp/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-network-connectivity/noxfile.py b/packages/google-cloud-network-connectivity/noxfile.py index eb0b2dd9a996..3f4c94d98da2 100644 --- a/packages/google-cloud-network-connectivity/noxfile.py +++ b/packages/google-cloud-network-connectivity/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-network-management/noxfile.py b/packages/google-cloud-network-management/noxfile.py index dd4c7c8fef8d..8b9f2e7b7aac 100644 --- a/packages/google-cloud-network-management/noxfile.py +++ b/packages/google-cloud-network-management/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-network-security/noxfile.py b/packages/google-cloud-network-security/noxfile.py index 75271cebe0dc..d18ea7c84e3d 100644 --- a/packages/google-cloud-network-security/noxfile.py +++ b/packages/google-cloud-network-security/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-network-services/noxfile.py b/packages/google-cloud-network-services/noxfile.py index 3e7926130721..3b1028983087 100644 --- a/packages/google-cloud-network-services/noxfile.py +++ b/packages/google-cloud-network-services/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-notebooks/noxfile.py b/packages/google-cloud-notebooks/noxfile.py index c322b59baaae..1c56cc47dacb 100644 --- a/packages/google-cloud-notebooks/noxfile.py +++ b/packages/google-cloud-notebooks/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-optimization/noxfile.py b/packages/google-cloud-optimization/noxfile.py index b2d7ef8821b0..602acfa99cb1 100644 --- a/packages/google-cloud-optimization/noxfile.py +++ b/packages/google-cloud-optimization/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-oracledatabase/noxfile.py b/packages/google-cloud-oracledatabase/noxfile.py index c4659e5b3146..cb674c6f1995 100644 --- a/packages/google-cloud-oracledatabase/noxfile.py +++ b/packages/google-cloud-oracledatabase/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-orchestration-airflow/noxfile.py b/packages/google-cloud-orchestration-airflow/noxfile.py index 44763335e79a..d91ebf899bbd 100644 --- a/packages/google-cloud-orchestration-airflow/noxfile.py +++ b/packages/google-cloud-orchestration-airflow/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-org-policy/noxfile.py b/packages/google-cloud-org-policy/noxfile.py index 037c89b3ee54..56e6e0409c0a 100644 --- a/packages/google-cloud-org-policy/noxfile.py +++ b/packages/google-cloud-org-policy/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-os-config/noxfile.py b/packages/google-cloud-os-config/noxfile.py index 2a12e7b3ad3b..12f7efefd632 100644 --- a/packages/google-cloud-os-config/noxfile.py +++ b/packages/google-cloud-os-config/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-os-login/noxfile.py b/packages/google-cloud-os-login/noxfile.py index 4f09338c5479..18134febd9b3 100644 --- a/packages/google-cloud-os-login/noxfile.py +++ b/packages/google-cloud-os-login/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-parallelstore/noxfile.py b/packages/google-cloud-parallelstore/noxfile.py index 71d1f56ae966..a78d2472952e 100644 --- a/packages/google-cloud-parallelstore/noxfile.py +++ b/packages/google-cloud-parallelstore/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-parametermanager/noxfile.py b/packages/google-cloud-parametermanager/noxfile.py index 28632ad67de9..afc695b512df 100644 --- a/packages/google-cloud-parametermanager/noxfile.py +++ b/packages/google-cloud-parametermanager/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-phishing-protection/noxfile.py b/packages/google-cloud-phishing-protection/noxfile.py index 1ae5210ce07c..25f6fe870561 100644 --- a/packages/google-cloud-phishing-protection/noxfile.py +++ b/packages/google-cloud-phishing-protection/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-policy-troubleshooter/noxfile.py b/packages/google-cloud-policy-troubleshooter/noxfile.py index 42067bc5057a..440f9fe606e5 100644 --- a/packages/google-cloud-policy-troubleshooter/noxfile.py +++ b/packages/google-cloud-policy-troubleshooter/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-policysimulator/noxfile.py b/packages/google-cloud-policysimulator/noxfile.py index 7882ba5813ce..12450bab7f3a 100644 --- a/packages/google-cloud-policysimulator/noxfile.py +++ b/packages/google-cloud-policysimulator/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-policytroubleshooter-iam/noxfile.py b/packages/google-cloud-policytroubleshooter-iam/noxfile.py index b599c9d927eb..355577ec634a 100644 --- a/packages/google-cloud-policytroubleshooter-iam/noxfile.py +++ b/packages/google-cloud-policytroubleshooter-iam/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-private-ca/noxfile.py b/packages/google-cloud-private-ca/noxfile.py index e5c37a1f91c3..d3b3ae128e0b 100644 --- a/packages/google-cloud-private-ca/noxfile.py +++ b/packages/google-cloud-private-ca/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-private-catalog/noxfile.py b/packages/google-cloud-private-catalog/noxfile.py index 48f1ef430276..90ca800521d7 100644 --- a/packages/google-cloud-private-catalog/noxfile.py +++ b/packages/google-cloud-private-catalog/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-privilegedaccessmanager/noxfile.py b/packages/google-cloud-privilegedaccessmanager/noxfile.py index 2736819dbe71..735ba896c015 100644 --- a/packages/google-cloud-privilegedaccessmanager/noxfile.py +++ b/packages/google-cloud-privilegedaccessmanager/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-pubsub/noxfile.py b/packages/google-cloud-pubsub/noxfile.py index 9e70f5367c98..a4b1c6bf573f 100644 --- a/packages/google-cloud-pubsub/noxfile.py +++ b/packages/google-cloud-pubsub/noxfile.py @@ -628,20 +628,28 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google.cloud", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google.cloud", "--iterations", "10" + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google.cloud", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google.cloud", "--iterations", "10" + ) diff --git a/packages/google-cloud-quotas/noxfile.py b/packages/google-cloud-quotas/noxfile.py index f32e130feb98..08999c92667d 100644 --- a/packages/google-cloud-quotas/noxfile.py +++ b/packages/google-cloud-quotas/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-rapidmigrationassessment/noxfile.py b/packages/google-cloud-rapidmigrationassessment/noxfile.py index e1445e9942a0..d17217d0255d 100644 --- a/packages/google-cloud-rapidmigrationassessment/noxfile.py +++ b/packages/google-cloud-rapidmigrationassessment/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-recaptcha-enterprise/noxfile.py b/packages/google-cloud-recaptcha-enterprise/noxfile.py index 1c70d69e3343..21847936c769 100644 --- a/packages/google-cloud-recaptcha-enterprise/noxfile.py +++ b/packages/google-cloud-recaptcha-enterprise/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-recommendations-ai/noxfile.py b/packages/google-cloud-recommendations-ai/noxfile.py index 550328b5186d..0fc92ca705cb 100644 --- a/packages/google-cloud-recommendations-ai/noxfile.py +++ b/packages/google-cloud-recommendations-ai/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-recommender/noxfile.py b/packages/google-cloud-recommender/noxfile.py index a348f21d22e6..0a80b32f6422 100644 --- a/packages/google-cloud-recommender/noxfile.py +++ b/packages/google-cloud-recommender/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-redis-cluster/noxfile.py b/packages/google-cloud-redis-cluster/noxfile.py index 79ba09eb29f6..78d319d1f7c9 100644 --- a/packages/google-cloud-redis-cluster/noxfile.py +++ b/packages/google-cloud-redis-cluster/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-redis/noxfile.py b/packages/google-cloud-redis/noxfile.py index 5d1df36cd08f..cef26e7c5a7c 100644 --- a/packages/google-cloud-redis/noxfile.py +++ b/packages/google-cloud-redis/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-resource-manager/noxfile.py b/packages/google-cloud-resource-manager/noxfile.py index b5beafdca105..fc0dc7847ce2 100644 --- a/packages/google-cloud-resource-manager/noxfile.py +++ b/packages/google-cloud-resource-manager/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-retail/noxfile.py b/packages/google-cloud-retail/noxfile.py index 9ff6402960d5..11452b85f24d 100644 --- a/packages/google-cloud-retail/noxfile.py +++ b/packages/google-cloud-retail/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-run/noxfile.py b/packages/google-cloud-run/noxfile.py index b1294ce38803..3253de9773fd 100644 --- a/packages/google-cloud-run/noxfile.py +++ b/packages/google-cloud-run/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-runtimeconfig/noxfile.py b/packages/google-cloud-runtimeconfig/noxfile.py index 1eacd5cfca1e..8ddfd1d9bf56 100644 --- a/packages/google-cloud-runtimeconfig/noxfile.py +++ b/packages/google-cloud-runtimeconfig/noxfile.py @@ -514,20 +514,28 @@ def core_deps_from_source(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-saasplatform-saasservicemgmt/noxfile.py b/packages/google-cloud-saasplatform-saasservicemgmt/noxfile.py index f26487327068..71ec7167f504 100644 --- a/packages/google-cloud-saasplatform-saasservicemgmt/noxfile.py +++ b/packages/google-cloud-saasplatform-saasservicemgmt/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-scheduler/noxfile.py b/packages/google-cloud-scheduler/noxfile.py index 491548afe3bd..4e17331ee38a 100644 --- a/packages/google-cloud-scheduler/noxfile.py +++ b/packages/google-cloud-scheduler/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-secret-manager/noxfile.py b/packages/google-cloud-secret-manager/noxfile.py index 94b86cd7940a..5d36853dea3a 100644 --- a/packages/google-cloud-secret-manager/noxfile.py +++ b/packages/google-cloud-secret-manager/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-securesourcemanager/noxfile.py b/packages/google-cloud-securesourcemanager/noxfile.py index 0a6fb993b1ce..b300e0da64ac 100644 --- a/packages/google-cloud-securesourcemanager/noxfile.py +++ b/packages/google-cloud-securesourcemanager/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-security-publicca/noxfile.py b/packages/google-cloud-security-publicca/noxfile.py index 47b2af1ea7d9..bb62d133a738 100644 --- a/packages/google-cloud-security-publicca/noxfile.py +++ b/packages/google-cloud-security-publicca/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-securitycenter/noxfile.py b/packages/google-cloud-securitycenter/noxfile.py index 4470b68de3dd..d57effeea216 100644 --- a/packages/google-cloud-securitycenter/noxfile.py +++ b/packages/google-cloud-securitycenter/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-securitycentermanagement/noxfile.py b/packages/google-cloud-securitycentermanagement/noxfile.py index b98bb259259d..0ea6db67ea15 100644 --- a/packages/google-cloud-securitycentermanagement/noxfile.py +++ b/packages/google-cloud-securitycentermanagement/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-service-control/noxfile.py b/packages/google-cloud-service-control/noxfile.py index b0db6a9c3a29..20c092de2940 100644 --- a/packages/google-cloud-service-control/noxfile.py +++ b/packages/google-cloud-service-control/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-service-directory/noxfile.py b/packages/google-cloud-service-directory/noxfile.py index 6b3899f35e35..5651f1a50755 100644 --- a/packages/google-cloud-service-directory/noxfile.py +++ b/packages/google-cloud-service-directory/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-service-management/noxfile.py b/packages/google-cloud-service-management/noxfile.py index c31ba8bd1c6f..f5cf266963be 100644 --- a/packages/google-cloud-service-management/noxfile.py +++ b/packages/google-cloud-service-management/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-service-usage/noxfile.py b/packages/google-cloud-service-usage/noxfile.py index 3540d06659a1..6f12e316c504 100644 --- a/packages/google-cloud-service-usage/noxfile.py +++ b/packages/google-cloud-service-usage/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-servicehealth/noxfile.py b/packages/google-cloud-servicehealth/noxfile.py index 7562ddf50a9b..31c81fc1d84b 100644 --- a/packages/google-cloud-servicehealth/noxfile.py +++ b/packages/google-cloud-servicehealth/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-shell/noxfile.py b/packages/google-cloud-shell/noxfile.py index b7ee1e39f26f..7267ecf4f08f 100644 --- a/packages/google-cloud-shell/noxfile.py +++ b/packages/google-cloud-shell/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-source-context/noxfile.py b/packages/google-cloud-source-context/noxfile.py index 19383cba0bea..3e8c8d0a2c51 100644 --- a/packages/google-cloud-source-context/noxfile.py +++ b/packages/google-cloud-source-context/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-spanner-dbapi-driver/noxfile.py b/packages/google-cloud-spanner-dbapi-driver/noxfile.py index e296643c487b..57bd00433972 100644 --- a/packages/google-cloud-spanner-dbapi-driver/noxfile.py +++ b/packages/google-cloud-spanner-dbapi-driver/noxfile.py @@ -610,9 +610,13 @@ def install(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-spanner/noxfile.py b/packages/google-cloud-spanner/noxfile.py index da8d44ef10a7..b2fc88375114 100644 --- a/packages/google-cloud-spanner/noxfile.py +++ b/packages/google-cloud-spanner/noxfile.py @@ -853,20 +853,28 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-speech/noxfile.py b/packages/google-cloud-speech/noxfile.py index 60f863f2fb25..05aafb09845e 100644 --- a/packages/google-cloud-speech/noxfile.py +++ b/packages/google-cloud-speech/noxfile.py @@ -644,9 +644,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-storage-control/noxfile.py b/packages/google-cloud-storage-control/noxfile.py index 617376760c73..bbd2249a437b 100644 --- a/packages/google-cloud-storage-control/noxfile.py +++ b/packages/google-cloud-storage-control/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-storage-transfer/noxfile.py b/packages/google-cloud-storage-transfer/noxfile.py index 6f35ab27a132..ef83a31642d4 100644 --- a/packages/google-cloud-storage-transfer/noxfile.py +++ b/packages/google-cloud-storage-transfer/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-storage/noxfile.py b/packages/google-cloud-storage/noxfile.py index 2760644a81ad..cce97b12929d 100644 --- a/packages/google-cloud-storage/noxfile.py +++ b/packages/google-cloud-storage/noxfile.py @@ -718,9 +718,18 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) diff --git a/packages/google-cloud-storagebatchoperations/noxfile.py b/packages/google-cloud-storagebatchoperations/noxfile.py index e502b0a09a42..c7eb539fe1b4 100644 --- a/packages/google-cloud-storagebatchoperations/noxfile.py +++ b/packages/google-cloud-storagebatchoperations/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-storageinsights/noxfile.py b/packages/google-cloud-storageinsights/noxfile.py index 65a0542db8d9..8676f8fc6c1d 100644 --- a/packages/google-cloud-storageinsights/noxfile.py +++ b/packages/google-cloud-storageinsights/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-support/noxfile.py b/packages/google-cloud-support/noxfile.py index 1d14cbb048d9..16f001bc498a 100644 --- a/packages/google-cloud-support/noxfile.py +++ b/packages/google-cloud-support/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-talent/noxfile.py b/packages/google-cloud-talent/noxfile.py index 7fd02e1a8a2f..e87be08bcef3 100644 --- a/packages/google-cloud-talent/noxfile.py +++ b/packages/google-cloud-talent/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-tasks/noxfile.py b/packages/google-cloud-tasks/noxfile.py index 7dc9f6a86f4c..6e92e77c61fe 100644 --- a/packages/google-cloud-tasks/noxfile.py +++ b/packages/google-cloud-tasks/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-telcoautomation/noxfile.py b/packages/google-cloud-telcoautomation/noxfile.py index bfe01867ba18..08e7d521068b 100644 --- a/packages/google-cloud-telcoautomation/noxfile.py +++ b/packages/google-cloud-telcoautomation/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-testutils/noxfile.py b/packages/google-cloud-testutils/noxfile.py index 820def2f63b1..138625a4d3ce 100644 --- a/packages/google-cloud-testutils/noxfile.py +++ b/packages/google-cloud-testutils/noxfile.py @@ -80,8 +80,10 @@ def format(session): # 2. Run Ruff to fix imports session.run( - "ruff", "check", - "--select", "I", + "ruff", + "check", + "--select", + "I", "--fix", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", @@ -90,7 +92,8 @@ def format(session): # 3. Run Ruff to format code session.run( - "ruff", "format", + "ruff", + "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", *BLACK_PATHS, @@ -328,14 +331,12 @@ def prerelease_deps(session): ) - @nox.session(python=DEFAULT_PYTHON_VERSION) def core_deps_from_source(session): """Run all tests with core dependencies installed from source rather than pulling the dependencies from PyPI. """ - # Install all dependencies constraints_path = str( CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" @@ -388,20 +389,38 @@ def core_deps_from_source(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) diff --git a/packages/google-cloud-texttospeech/noxfile.py b/packages/google-cloud-texttospeech/noxfile.py index b17b0791af21..330d33187281 100644 --- a/packages/google-cloud-texttospeech/noxfile.py +++ b/packages/google-cloud-texttospeech/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-tpu/noxfile.py b/packages/google-cloud-tpu/noxfile.py index 16e6cbf534ee..f68a2770fe2f 100644 --- a/packages/google-cloud-tpu/noxfile.py +++ b/packages/google-cloud-tpu/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-trace/noxfile.py b/packages/google-cloud-trace/noxfile.py index 9b13588d61ab..23345075c142 100644 --- a/packages/google-cloud-trace/noxfile.py +++ b/packages/google-cloud-trace/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-translate/noxfile.py b/packages/google-cloud-translate/noxfile.py index 003594f3514a..90d129501aaa 100644 --- a/packages/google-cloud-translate/noxfile.py +++ b/packages/google-cloud-translate/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-vectorsearch/noxfile.py b/packages/google-cloud-vectorsearch/noxfile.py index e8b1f9999111..e00afbe55d53 100644 --- a/packages/google-cloud-vectorsearch/noxfile.py +++ b/packages/google-cloud-vectorsearch/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-video-live-stream/noxfile.py b/packages/google-cloud-video-live-stream/noxfile.py index e93a379985d4..13588b31dd39 100644 --- a/packages/google-cloud-video-live-stream/noxfile.py +++ b/packages/google-cloud-video-live-stream/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-video-stitcher/noxfile.py b/packages/google-cloud-video-stitcher/noxfile.py index 935b7e43d2a0..208ee56e7e52 100644 --- a/packages/google-cloud-video-stitcher/noxfile.py +++ b/packages/google-cloud-video-stitcher/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-video-transcoder/noxfile.py b/packages/google-cloud-video-transcoder/noxfile.py index 39d8902166fb..a4ca8e2f5c28 100644 --- a/packages/google-cloud-video-transcoder/noxfile.py +++ b/packages/google-cloud-video-transcoder/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-videointelligence/noxfile.py b/packages/google-cloud-videointelligence/noxfile.py index 2cea4d46b180..1254237487c8 100644 --- a/packages/google-cloud-videointelligence/noxfile.py +++ b/packages/google-cloud-videointelligence/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-vision/noxfile.py b/packages/google-cloud-vision/noxfile.py index 29c41cb0ea75..c006321f4756 100644 --- a/packages/google-cloud-vision/noxfile.py +++ b/packages/google-cloud-vision/noxfile.py @@ -644,9 +644,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-visionai/noxfile.py b/packages/google-cloud-visionai/noxfile.py index 0e99862faa79..4b8fd2804875 100644 --- a/packages/google-cloud-visionai/noxfile.py +++ b/packages/google-cloud-visionai/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-vm-migration/noxfile.py b/packages/google-cloud-vm-migration/noxfile.py index b966ccd0f30b..a418479389ff 100644 --- a/packages/google-cloud-vm-migration/noxfile.py +++ b/packages/google-cloud-vm-migration/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-vmwareengine/noxfile.py b/packages/google-cloud-vmwareengine/noxfile.py index 80ad6075681e..ed25a49c09d2 100644 --- a/packages/google-cloud-vmwareengine/noxfile.py +++ b/packages/google-cloud-vmwareengine/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-vpc-access/noxfile.py b/packages/google-cloud-vpc-access/noxfile.py index dbf744337755..88bf226cdcc2 100644 --- a/packages/google-cloud-vpc-access/noxfile.py +++ b/packages/google-cloud-vpc-access/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-webrisk/noxfile.py b/packages/google-cloud-webrisk/noxfile.py index 9f75f9c93fa9..fbb1c9b4053c 100644 --- a/packages/google-cloud-webrisk/noxfile.py +++ b/packages/google-cloud-webrisk/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-websecurityscanner/noxfile.py b/packages/google-cloud-websecurityscanner/noxfile.py index c4535bdc436a..21e2caa4c178 100644 --- a/packages/google-cloud-websecurityscanner/noxfile.py +++ b/packages/google-cloud-websecurityscanner/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-workflows/noxfile.py b/packages/google-cloud-workflows/noxfile.py index 3a843e4ae5e0..a31876ffff4d 100644 --- a/packages/google-cloud-workflows/noxfile.py +++ b/packages/google-cloud-workflows/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-workloadmanager/noxfile.py b/packages/google-cloud-workloadmanager/noxfile.py index 578f41526754..1f8ef11ad647 100644 --- a/packages/google-cloud-workloadmanager/noxfile.py +++ b/packages/google-cloud-workloadmanager/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-cloud-workstations/noxfile.py b/packages/google-cloud-workstations/noxfile.py index 999f437a5445..9ceaf5ddaeb5 100644 --- a/packages/google-cloud-workstations/noxfile.py +++ b/packages/google-cloud-workstations/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-crc32c/noxfile.py b/packages/google-crc32c/noxfile.py index 0e73416b5023..8c393eca60f6 100644 --- a/packages/google-crc32c/noxfile.py +++ b/packages/google-crc32c/noxfile.py @@ -189,20 +189,38 @@ def docfx(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) diff --git a/packages/google-developer-knowledge/noxfile.py b/packages/google-developer-knowledge/noxfile.py index d565b93878d0..7a601e3c2e2e 100644 --- a/packages/google-developer-knowledge/noxfile.py +++ b/packages/google-developer-knowledge/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-devicesandservices-health/noxfile.py b/packages/google-devicesandservices-health/noxfile.py index 664d0afe3161..8bb4d4f54b47 100644 --- a/packages/google-devicesandservices-health/noxfile.py +++ b/packages/google-devicesandservices-health/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-geo-type/noxfile.py b/packages/google-geo-type/noxfile.py index 9b31d1a6b71c..c747ecefe0c3 100644 --- a/packages/google-geo-type/noxfile.py +++ b/packages/google-geo-type/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-maps-addressvalidation/noxfile.py b/packages/google-maps-addressvalidation/noxfile.py index b2423e439707..b8a3a66ae43d 100644 --- a/packages/google-maps-addressvalidation/noxfile.py +++ b/packages/google-maps-addressvalidation/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-maps-areainsights/noxfile.py b/packages/google-maps-areainsights/noxfile.py index 2f9c678ddf23..1012441a475b 100644 --- a/packages/google-maps-areainsights/noxfile.py +++ b/packages/google-maps-areainsights/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-maps-fleetengine-delivery/noxfile.py b/packages/google-maps-fleetengine-delivery/noxfile.py index f268d1f418e9..b830c51e2296 100644 --- a/packages/google-maps-fleetengine-delivery/noxfile.py +++ b/packages/google-maps-fleetengine-delivery/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-maps-fleetengine/noxfile.py b/packages/google-maps-fleetengine/noxfile.py index 53d5c0e15943..1595c3868faf 100644 --- a/packages/google-maps-fleetengine/noxfile.py +++ b/packages/google-maps-fleetengine/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-maps-geocode/noxfile.py b/packages/google-maps-geocode/noxfile.py index a974334952f2..20b4b720ef2e 100644 --- a/packages/google-maps-geocode/noxfile.py +++ b/packages/google-maps-geocode/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-maps-mapmanagement/noxfile.py b/packages/google-maps-mapmanagement/noxfile.py index 4ebfdc34c171..378f56726162 100644 --- a/packages/google-maps-mapmanagement/noxfile.py +++ b/packages/google-maps-mapmanagement/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-maps-mapsplatformdatasets/noxfile.py b/packages/google-maps-mapsplatformdatasets/noxfile.py index c26ef6b4bd6d..3d10d8c41d49 100644 --- a/packages/google-maps-mapsplatformdatasets/noxfile.py +++ b/packages/google-maps-mapsplatformdatasets/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-maps-navconnect/noxfile.py b/packages/google-maps-navconnect/noxfile.py index afedf64878d2..5b651b34028d 100644 --- a/packages/google-maps-navconnect/noxfile.py +++ b/packages/google-maps-navconnect/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-maps-places/noxfile.py b/packages/google-maps-places/noxfile.py index d12b2eb099c0..5bebf46d05e8 100644 --- a/packages/google-maps-places/noxfile.py +++ b/packages/google-maps-places/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-maps-routeoptimization/noxfile.py b/packages/google-maps-routeoptimization/noxfile.py index f545a7ff7a58..f95089005db3 100644 --- a/packages/google-maps-routeoptimization/noxfile.py +++ b/packages/google-maps-routeoptimization/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-maps-routing/noxfile.py b/packages/google-maps-routing/noxfile.py index 9b9b2bf58a45..4d98fac639e2 100644 --- a/packages/google-maps-routing/noxfile.py +++ b/packages/google-maps-routing/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-maps-solar/noxfile.py b/packages/google-maps-solar/noxfile.py index bc42fe927819..e389b65dfde0 100644 --- a/packages/google-maps-solar/noxfile.py +++ b/packages/google-maps-solar/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-resumable-media/noxfile.py b/packages/google-resumable-media/noxfile.py index 490f7cb876ac..e9c5e340faa2 100644 --- a/packages/google-resumable-media/noxfile.py +++ b/packages/google-resumable-media/noxfile.py @@ -68,7 +68,7 @@ def unit(session): line_coverage, os.path.join("tests", "unit"), os.path.join("tests_async", "unit"), - *session.posargs + *session.posargs, ) @@ -106,6 +106,7 @@ def docs(session): os.path.join("docs", "_build", "html", ""), ) + @nox.session(python="3.10") def docfx(session): """Build the docfx yaml files for this library.""" @@ -319,7 +320,9 @@ def prerelease_deps(session): # version, the first version we test with in the unit tests sessions has a # constraints file containing all dependencies and extras. with open( - CURRENT_DIRECTORY / "testing" / f"constraints-{UNIT_TEST_PYTHON_VERSIONS[0]}.txt", + CURRENT_DIRECTORY + / "testing" + / f"constraints-{UNIT_TEST_PYTHON_VERSIONS[0]}.txt", encoding="utf-8", ) as constraints_file: constraints_text = constraints_file.read() @@ -400,7 +403,9 @@ def core_deps_from_source(session): # version, the first version we test with in the unit tests sessions has a # constraints file containing all dependencies and extras. with open( - CURRENT_DIRECTORY / "testing" / f"constraints-{UNIT_TEST_PYTHON_VERSIONS[0]}.txt", + CURRENT_DIRECTORY + / "testing" + / f"constraints-{UNIT_TEST_PYTHON_VERSIONS[0]}.txt", encoding="utf-8", ) as constraints_file: constraints_text = constraints_file.read() @@ -431,7 +436,9 @@ def core_deps_from_source(session): dep_paths = [str(deps_dir / dep) for dep in core_dependencies_from_source] session.install(*dep_paths, "--no-deps", "--ignore-installed") - print(f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}") + print( + f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}" + ) other_deps = [ "cryptography", @@ -453,20 +460,28 @@ def core_deps_from_source(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-shopping-css/noxfile.py b/packages/google-shopping-css/noxfile.py index 1f616d50dade..db0fa77a3bd2 100644 --- a/packages/google-shopping-css/noxfile.py +++ b/packages/google-shopping-css/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-shopping-merchant-accounts/noxfile.py b/packages/google-shopping-merchant-accounts/noxfile.py index 037d70796fcf..d39107a1e49b 100644 --- a/packages/google-shopping-merchant-accounts/noxfile.py +++ b/packages/google-shopping-merchant-accounts/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-shopping-merchant-conversions/noxfile.py b/packages/google-shopping-merchant-conversions/noxfile.py index 1aff313f955d..4320cfd6379a 100644 --- a/packages/google-shopping-merchant-conversions/noxfile.py +++ b/packages/google-shopping-merchant-conversions/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-shopping-merchant-datasources/noxfile.py b/packages/google-shopping-merchant-datasources/noxfile.py index 8fd5aa084476..009bbaa8b055 100644 --- a/packages/google-shopping-merchant-datasources/noxfile.py +++ b/packages/google-shopping-merchant-datasources/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-shopping-merchant-inventories/noxfile.py b/packages/google-shopping-merchant-inventories/noxfile.py index 808693aa64b0..6050b8271428 100644 --- a/packages/google-shopping-merchant-inventories/noxfile.py +++ b/packages/google-shopping-merchant-inventories/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-shopping-merchant-issueresolution/noxfile.py b/packages/google-shopping-merchant-issueresolution/noxfile.py index 45726fc76b43..35a66d863a5a 100644 --- a/packages/google-shopping-merchant-issueresolution/noxfile.py +++ b/packages/google-shopping-merchant-issueresolution/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-shopping-merchant-lfp/noxfile.py b/packages/google-shopping-merchant-lfp/noxfile.py index 4be2846fbb89..997f44148ee2 100644 --- a/packages/google-shopping-merchant-lfp/noxfile.py +++ b/packages/google-shopping-merchant-lfp/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-shopping-merchant-notifications/noxfile.py b/packages/google-shopping-merchant-notifications/noxfile.py index 020541319f11..ac86477c39eb 100644 --- a/packages/google-shopping-merchant-notifications/noxfile.py +++ b/packages/google-shopping-merchant-notifications/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-shopping-merchant-ordertracking/noxfile.py b/packages/google-shopping-merchant-ordertracking/noxfile.py index 42701d4d026b..b098ae8d6d2c 100644 --- a/packages/google-shopping-merchant-ordertracking/noxfile.py +++ b/packages/google-shopping-merchant-ordertracking/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-shopping-merchant-products/noxfile.py b/packages/google-shopping-merchant-products/noxfile.py index 25ac85dc73f8..41596f28c46d 100644 --- a/packages/google-shopping-merchant-products/noxfile.py +++ b/packages/google-shopping-merchant-products/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-shopping-merchant-productstudio/noxfile.py b/packages/google-shopping-merchant-productstudio/noxfile.py index b79917c5cb18..bbe8a6710485 100644 --- a/packages/google-shopping-merchant-productstudio/noxfile.py +++ b/packages/google-shopping-merchant-productstudio/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-shopping-merchant-promotions/noxfile.py b/packages/google-shopping-merchant-promotions/noxfile.py index bb4b5152439c..c80b2b4cbbd6 100644 --- a/packages/google-shopping-merchant-promotions/noxfile.py +++ b/packages/google-shopping-merchant-promotions/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-shopping-merchant-quota/noxfile.py b/packages/google-shopping-merchant-quota/noxfile.py index 6c61ece3c98d..2a76170c8b4c 100644 --- a/packages/google-shopping-merchant-quota/noxfile.py +++ b/packages/google-shopping-merchant-quota/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-shopping-merchant-reports/noxfile.py b/packages/google-shopping-merchant-reports/noxfile.py index a85260e58dc6..f77aec074e1c 100644 --- a/packages/google-shopping-merchant-reports/noxfile.py +++ b/packages/google-shopping-merchant-reports/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-shopping-merchant-reviews/noxfile.py b/packages/google-shopping-merchant-reviews/noxfile.py index cf1ca4f89b2a..4e5109729cae 100644 --- a/packages/google-shopping-merchant-reviews/noxfile.py +++ b/packages/google-shopping-merchant-reviews/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/google-shopping-type/noxfile.py b/packages/google-shopping-type/noxfile.py index b330c7fcce9d..eb8860937139 100644 --- a/packages/google-shopping-type/noxfile.py +++ b/packages/google-shopping-type/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "google", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "google", "--iterations", "10" + ) diff --git a/packages/googleapis-common-protos/noxfile.py b/packages/googleapis-common-protos/noxfile.py index 0f5b76241476..b52825929435 100644 --- a/packages/googleapis-common-protos/noxfile.py +++ b/packages/googleapis-common-protos/noxfile.py @@ -605,9 +605,18 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) diff --git a/packages/grafeas/noxfile.py b/packages/grafeas/noxfile.py index d0753e486952..b6171f0f4ea6 100644 --- a/packages/grafeas/noxfile.py +++ b/packages/grafeas/noxfile.py @@ -643,9 +643,13 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "grafeas", "--iterations", "10") + session.run( + "python", str(profiler_script), "--module", "grafeas", "--iterations", "10" + ) diff --git a/packages/grpc-google-iam-v1/noxfile.py b/packages/grpc-google-iam-v1/noxfile.py index a93eba2f067d..7b24b0101620 100644 --- a/packages/grpc-google-iam-v1/noxfile.py +++ b/packages/grpc-google-iam-v1/noxfile.py @@ -590,9 +590,18 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) diff --git a/packages/pandas-gbq/noxfile.py b/packages/pandas-gbq/noxfile.py index 3db6c0d18cc0..549f1b4a4a84 100644 --- a/packages/pandas-gbq/noxfile.py +++ b/packages/pandas-gbq/noxfile.py @@ -601,9 +601,18 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) diff --git a/packages/proto-plus/noxfile.py b/packages/proto-plus/noxfile.py index b720220755e0..3a3d0411f202 100644 --- a/packages/proto-plus/noxfile.py +++ b/packages/proto-plus/noxfile.py @@ -358,20 +358,38 @@ def format(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) diff --git a/packages/sqlalchemy-bigquery/noxfile.py b/packages/sqlalchemy-bigquery/noxfile.py index 1508291d14f7..1ea43b3281a4 100644 --- a/packages/sqlalchemy-bigquery/noxfile.py +++ b/packages/sqlalchemy-bigquery/noxfile.py @@ -747,20 +747,38 @@ def core_deps_from_source(session, protobuf_implementation): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) diff --git a/packages/sqlalchemy-spanner/noxfile.py b/packages/sqlalchemy-spanner/noxfile.py index b03deea9767a..bf2b37b66538 100644 --- a/packages/sqlalchemy-spanner/noxfile.py +++ b/packages/sqlalchemy-spanner/noxfile.py @@ -609,20 +609,38 @@ def format(session): @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) @nox.session(python="3.15") def import_profile(session): """Ensure import times remain below defined thresholds.""" - profiler_script = CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) if not profiler_script.exists(): session.skip("The import profiler script was not found.") session.install(".") - session.run("python", str(profiler_script), "--module", "unknown_module", "--iterations", "10") + session.run( + "python", + str(profiler_script), + "--module", + "unknown_module", + "--iterations", + "10", + ) From a7d23636d395a19d25c0bc3d74d1c13b97c3967f Mon Sep 17 00:00:00 2001 From: Heba Alazzeh Date: Wed, 8 Jul 2026 03:30:55 +0000 Subject: [PATCH 06/13] chore: revert google-crc32c noxfile modification to bypass broken kokoro presubmit --- packages/google-crc32c/noxfile.py | 40 ------------------------------- 1 file changed, 40 deletions(-) diff --git a/packages/google-crc32c/noxfile.py b/packages/google-crc32c/noxfile.py index 8c393eca60f6..b44c502ccd0c 100644 --- a/packages/google-crc32c/noxfile.py +++ b/packages/google-crc32c/noxfile.py @@ -184,43 +184,3 @@ def docs(session): def docfx(session): """Run all docfx tests.""" session.skip("Docfx tests are not supported") - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "unknown_module", - "--iterations", - "10", - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "unknown_module", - "--iterations", - "10", - ) From 68a0bdfe002d4ea67fc54b729cc548997820da48 Mon Sep 17 00:00:00 2001 From: Heba Alazzeh Date: Wed, 8 Jul 2026 03:47:54 +0000 Subject: [PATCH 07/13] fix(ci): fix bazel integration tests and lint formatting --- packages/bigframes/noxfile.py | 23 +-- packages/bigquery-magics/noxfile.py | 23 +-- packages/db-dtypes/noxfile.py | 23 +-- packages/django-google-spanner/noxfile.py | 22 +-- .../gapic/templates/noxfile.py.j2 | 14 +- packages/gapic-generator/noxfile.py | 43 ++---- .../integration/goldens/asset/noxfile.py | 45 +++--- .../goldens/credentials/noxfile.py | 45 +++--- .../integration/goldens/eventarc/noxfile.py | 45 +++--- .../integration/goldens/logging/noxfile.py | 45 +++--- .../goldens/logging_internal/noxfile.py | 45 +++--- .../integration/goldens/redis/noxfile.py | 45 +++--- .../goldens/redis_selective/noxfile.py | 45 +++--- .../goldens/storagebatchoperations/noxfile.py | 45 +++--- packages/gcp-sphinx-docfx-yaml/noxfile.py | 23 +-- packages/google-ads-admanager/noxfile.py | 7 +- packages/google-ads-datamanager/noxfile.py | 7 +- .../noxfile.py | 7 +- .../google-ai-generativelanguage/noxfile.py | 7 +- packages/google-analytics-admin/noxfile.py | 7 +- packages/google-analytics-data/noxfile.py | 7 +- packages/google-api-core/noxfile.py | 22 +-- packages/google-apps-card/noxfile.py | 7 +- packages/google-apps-chat/noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-apps-meet/noxfile.py | 7 +- packages/google-apps-script-type/noxfile.py | 7 +- packages/google-area120-tables/noxfile.py | 7 +- packages/google-auth-httplib2/noxfile.py | 22 +-- packages/google-auth-oauthlib/noxfile.py | 22 +-- packages/google-auth/noxfile.py | 7 +- packages/google-backstory/noxfile.py | 7 +- .../google-cloud-access-approval/noxfile.py | 7 +- .../noxfile.py | 2 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- .../google-cloud-agentregistry/noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-alloydb/noxfile.py | 7 +- packages/google-cloud-api-gateway/noxfile.py | 7 +- packages/google-cloud-api-keys/noxfile.py | 7 +- .../google-cloud-apigee-connect/noxfile.py | 7 +- .../google-cloud-apigee-registry/noxfile.py | 7 +- packages/google-cloud-apihub/noxfile.py | 7 +- packages/google-cloud-apiregistry/noxfile.py | 7 +- .../google-cloud-appengine-admin/noxfile.py | 7 +- .../google-cloud-appengine-logging/noxfile.py | 7 +- packages/google-cloud-apphub/noxfile.py | 7 +- packages/google-cloud-appoptimize/noxfile.py | 7 +- .../google-cloud-artifact-registry/noxfile.py | 7 +- packages/google-cloud-asset/noxfile.py | 7 +- .../google-cloud-assured-workloads/noxfile.py | 7 +- packages/google-cloud-audit-log/noxfile.py | 2 +- packages/google-cloud-auditmanager/noxfile.py | 7 +- packages/google-cloud-automl/noxfile.py | 7 +- packages/google-cloud-backupdr/noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-batch/noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-biglake-hive/noxfile.py | 7 +- packages/google-cloud-biglake/noxfile.py | 7 +- .../noxfile.py | 7 +- .../google-cloud-bigquery-biglake/noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- .../google-cloud-bigquery-logging/noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- .../google-cloud-bigquery-storage/noxfile.py | 7 +- packages/google-cloud-bigquery/noxfile.py | 23 +-- packages/google-cloud-bigtable/noxfile.py | 23 +-- .../google-cloud-billing-budgets/noxfile.py | 7 +- packages/google-cloud-billing/noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-build/noxfile.py | 7 +- .../google-cloud-capacityplanner/noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-ces/noxfile.py | 7 +- packages/google-cloud-channel/noxfile.py | 7 +- packages/google-cloud-chronicle/noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-common/noxfile.py | 7 +- .../google-cloud-compute-v1beta/noxfile.py | 7 +- .../services/accelerator_types/client.py | 136 ----------------- .../compute_v1/services/addresses/client.py | 136 ----------------- .../compute_v1/services/advice/client.py | 136 ----------------- .../compute_v1/services/autoscalers/client.py | 136 ----------------- .../services/backend_buckets/client.py | 136 ----------------- .../services/backend_services/client.py | 136 ----------------- .../services/cross_site_networks/client.py | 136 ----------------- .../compute_v1/services/disk_types/client.py | 136 ----------------- .../cloud/compute_v1/services/disks/client.py | 136 ----------------- .../services/external_vpn_gateways/client.py | 136 ----------------- .../services/firewall_policies/client.py | 136 ----------------- .../compute_v1/services/firewalls/client.py | 136 ----------------- .../services/forwarding_rules/client.py | 136 ----------------- .../services/future_reservations/client.py | 136 ----------------- .../services/global_addresses/client.py | 136 ----------------- .../global_forwarding_rules/client.py | 136 ----------------- .../global_network_endpoint_groups/client.py | 136 ----------------- .../services/global_operations/client.py | 136 ----------------- .../global_organization_operations/client.py | 138 ----------------- .../client.py | 138 ----------------- .../global_vm_extension_policies/client.py | 136 ----------------- .../services/health_checks/client.py | 136 ----------------- .../services/image_family_views/client.py | 136 ----------------- .../compute_v1/services/images/client.py | 136 ----------------- .../client.py | 138 ----------------- .../instance_group_managers/client.py | 136 ----------------- .../services/instance_groups/client.py | 136 ----------------- .../instance_settings_service/client.py | 136 ----------------- .../services/instance_templates/client.py | 136 ----------------- .../compute_v1/services/instances/client.py | 136 ----------------- .../instant_snapshot_groups/client.py | 136 ----------------- .../services/instant_snapshots/client.py | 136 ----------------- .../interconnect_attachment_groups/client.py | 138 ----------------- .../interconnect_attachments/client.py | 136 ----------------- .../services/interconnect_groups/client.py | 136 ----------------- .../services/interconnect_locations/client.py | 136 ----------------- .../interconnect_remote_locations/client.py | 136 ----------------- .../services/interconnects/client.py | 136 ----------------- .../services/license_codes/client.py | 136 ----------------- .../compute_v1/services/licenses/client.py | 136 ----------------- .../services/machine_images/client.py | 136 ----------------- .../services/machine_types/client.py | 136 ----------------- .../services/network_attachments/client.py | 136 ----------------- .../network_edge_security_services/client.py | 136 ----------------- .../network_endpoint_groups/client.py | 136 ----------------- .../network_firewall_policies/client.py | 136 ----------------- .../services/network_profiles/client.py | 136 ----------------- .../compute_v1/services/networks/client.py | 136 ----------------- .../compute_v1/services/node_groups/client.py | 136 ----------------- .../services/node_templates/client.py | 136 ----------------- .../compute_v1/services/node_types/client.py | 136 ----------------- .../organization_security_policies/client.py | 138 ----------------- .../services/packet_mirrorings/client.py | 136 ----------------- .../services/preview_features/client.py | 136 ----------------- .../compute_v1/services/projects/client.py | 136 ----------------- .../public_advertised_prefixes/client.py | 136 ----------------- .../public_delegated_prefixes/client.py | 136 ----------------- .../services/region_autoscalers/client.py | 136 ----------------- .../services/region_backend_buckets/client.py | 136 ----------------- .../region_backend_services/client.py | 136 ----------------- .../services/region_commitments/client.py | 136 ----------------- .../region_composite_health_checks/client.py | 136 ----------------- .../services/region_disk_types/client.py | 136 ----------------- .../services/region_disks/client.py | 136 ----------------- .../client.py | 138 ----------------- .../region_health_check_services/client.py | 136 ----------------- .../services/region_health_checks/client.py | 136 ----------------- .../services/region_health_sources/client.py | 136 ----------------- .../client.py | 140 ------------------ .../region_instance_group_managers/client.py | 136 ----------------- .../services/region_instance_groups/client.py | 136 ----------------- .../region_instance_templates/client.py | 136 ----------------- .../services/region_instances/client.py | 136 ----------------- .../region_instant_snapshot_groups/client.py | 136 ----------------- .../region_instant_snapshots/client.py | 136 ----------------- .../region_network_endpoint_groups/client.py | 136 ----------------- .../client.py | 138 ----------------- .../region_notification_endpoints/client.py | 136 ----------------- .../services/region_operations/client.py | 136 ----------------- .../region_security_policies/client.py | 136 ----------------- .../region_snapshot_settings/client.py | 136 ----------------- .../services/region_snapshots/client.py | 136 ----------------- .../region_ssl_certificates/client.py | 136 ----------------- .../services/region_ssl_policies/client.py | 136 ----------------- .../region_target_http_proxies/client.py | 136 ----------------- .../region_target_https_proxies/client.py | 136 ----------------- .../region_target_tcp_proxies/client.py | 136 ----------------- .../services/region_url_maps/client.py | 136 ----------------- .../services/region_zones/client.py | 136 ----------------- .../compute_v1/services/regions/client.py | 136 ----------------- .../services/reservation_blocks/client.py | 136 ----------------- .../services/reservation_slots/client.py | 136 ----------------- .../services/reservation_sub_blocks/client.py | 136 ----------------- .../services/reservations/client.py | 136 ----------------- .../services/resource_policies/client.py | 136 ----------------- .../services/rollout_plans/client.py | 136 ----------------- .../compute_v1/services/rollouts/client.py | 136 ----------------- .../compute_v1/services/routers/client.py | 136 ----------------- .../compute_v1/services/routes/client.py | 136 ----------------- .../services/security_policies/client.py | 136 ----------------- .../services/service_attachments/client.py | 136 ----------------- .../snapshot_settings_service/client.py | 136 ----------------- .../compute_v1/services/snapshots/client.py | 136 ----------------- .../services/ssl_certificates/client.py | 136 ----------------- .../services/ssl_policies/client.py | 136 ----------------- .../services/storage_pool_types/client.py | 136 ----------------- .../services/storage_pools/client.py | 136 ----------------- .../compute_v1/services/subnetworks/client.py | 136 ----------------- .../services/target_grpc_proxies/client.py | 136 ----------------- .../services/target_http_proxies/client.py | 136 ----------------- .../services/target_https_proxies/client.py | 136 ----------------- .../services/target_instances/client.py | 136 ----------------- .../services/target_pools/client.py | 136 ----------------- .../services/target_ssl_proxies/client.py | 136 ----------------- .../services/target_tcp_proxies/client.py | 136 ----------------- .../services/target_vpn_gateways/client.py | 136 ----------------- .../compute_v1/services/url_maps/client.py | 136 ----------------- .../services/vpn_gateways/client.py | 136 ----------------- .../compute_v1/services/vpn_tunnels/client.py | 136 ----------------- .../compute_v1/services/wire_groups/client.py | 136 ----------------- .../services/zone_operations/client.py | 136 ----------------- .../zone_vm_extension_policies/client.py | 136 ----------------- .../cloud/compute_v1/services/zones/client.py | 136 ----------------- packages/google-cloud-compute/noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-config/noxfile.py | 7 +- .../google-cloud-configdelivery/noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-container/noxfile.py | 7 +- .../google-cloud-containeranalysis/noxfile.py | 7 +- .../google-cloud-contentwarehouse/noxfile.py | 7 +- packages/google-cloud-core/noxfile.py | 22 +-- packages/google-cloud-data-fusion/noxfile.py | 7 +- packages/google-cloud-data-qna/noxfile.py | 7 +- .../google-cloud-databasecenter/noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-datacatalog/noxfile.py | 7 +- .../google-cloud-dataflow-client/noxfile.py | 7 +- packages/google-cloud-dataform/noxfile.py | 7 +- packages/google-cloud-datalabeling/noxfile.py | 7 +- packages/google-cloud-dataplex/noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-dataproc/noxfile.py | 7 +- packages/google-cloud-datastore/noxfile.py | 7 +- packages/google-cloud-datastream/noxfile.py | 7 +- packages/google-cloud-deploy/noxfile.py | 7 +- .../google-cloud-developerconnect/noxfile.py | 7 +- .../google-cloud-devicestreaming/noxfile.py | 7 +- .../google-cloud-dialogflow-cx/noxfile.py | 7 +- packages/google-cloud-dialogflow/noxfile.py | 7 +- .../google-cloud-discoveryengine/noxfile.py | 7 +- packages/google-cloud-dlp/noxfile.py | 7 +- packages/google-cloud-dms/noxfile.py | 7 +- packages/google-cloud-dns/noxfile.py | 23 +-- .../noxfile.py | 23 +-- packages/google-cloud-documentai/noxfile.py | 7 +- packages/google-cloud-domains/noxfile.py | 7 +- .../google-cloud-edgecontainer/noxfile.py | 7 +- packages/google-cloud-edgenetwork/noxfile.py | 7 +- .../noxfile.py | 7 +- .../google-cloud-error-reporting/noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-eventarc/noxfile.py | 7 +- packages/google-cloud-filestore/noxfile.py | 7 +- .../google-cloud-financialservices/noxfile.py | 7 +- packages/google-cloud-firestore/noxfile.py | 7 +- packages/google-cloud-functions/noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-gke-backup/noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-gke-hub/noxfile.py | 7 +- .../google-cloud-gke-multicloud/noxfile.py | 7 +- .../google-cloud-gkerecommender/noxfile.py | 7 +- packages/google-cloud-gsuiteaddons/noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-iam-logging/noxfile.py | 7 +- packages/google-cloud-iam/noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-iap/noxfile.py | 7 +- packages/google-cloud-ids/noxfile.py | 7 +- .../google-cloud-kms-inventory/noxfile.py | 7 +- .../cloud/kms_v1/services/autokey/client.py | 136 ----------------- .../kms_v1/services/autokey_admin/client.py | 136 ----------------- .../kms_v1/services/ekm_service/client.py | 136 ----------------- .../kms_v1/services/hsm_management/client.py | 136 ----------------- .../services/key_management_service/client.py | 136 ----------------- packages/google-cloud-kms/noxfile.py | 7 +- packages/google-cloud-language/noxfile.py | 7 +- .../google-cloud-licensemanager/noxfile.py | 7 +- .../google-cloud-life-sciences/noxfile.py | 7 +- .../google-cloud-locationfinder/noxfile.py | 7 +- packages/google-cloud-logging/noxfile.py | 2 +- packages/google-cloud-lustre/noxfile.py | 7 +- .../google-cloud-maintenance-api/noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-managedkafka/noxfile.py | 7 +- .../google-cloud-media-translation/noxfile.py | 7 +- packages/google-cloud-memcache/noxfile.py | 7 +- packages/google-cloud-memorystore/noxfile.py | 7 +- .../google-cloud-migrationcenter/noxfile.py | 7 +- packages/google-cloud-modelarmor/noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-monitoring/noxfile.py | 7 +- packages/google-cloud-ndb/noxfile.py | 23 +-- packages/google-cloud-netapp/noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- .../google-cloud-network-security/noxfile.py | 7 +- .../google-cloud-network-services/noxfile.py | 7 +- packages/google-cloud-notebooks/noxfile.py | 7 +- packages/google-cloud-optimization/noxfile.py | 7 +- .../google-cloud-oracledatabase/noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-org-policy/noxfile.py | 7 +- packages/google-cloud-os-config/noxfile.py | 7 +- packages/google-cloud-os-login/noxfile.py | 7 +- .../google-cloud-parallelstore/noxfile.py | 7 +- .../google-cloud-parametermanager/noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- .../google-cloud-policysimulator/noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-private-ca/noxfile.py | 7 +- .../google-cloud-private-catalog/noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-pubsub/noxfile.py | 23 +-- packages/google-cloud-quotas/noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-recommender/noxfile.py | 7 +- .../google-cloud-redis-cluster/noxfile.py | 7 +- packages/google-cloud-redis/noxfile.py | 7 +- .../google-cloud-resource-manager/noxfile.py | 7 +- packages/google-cloud-retail/noxfile.py | 7 +- packages/google-cloud-run/noxfile.py | 7 +- .../google-cloud-runtimeconfig/noxfile.py | 22 +-- .../noxfile.py | 7 +- packages/google-cloud-scheduler/noxfile.py | 7 +- .../google-cloud-secret-manager/noxfile.py | 7 +- .../noxfile.py | 7 +- .../google-cloud-security-publicca/noxfile.py | 7 +- .../google-cloud-securitycenter/noxfile.py | 7 +- .../noxfile.py | 7 +- .../google-cloud-service-control/noxfile.py | 7 +- .../google-cloud-service-directory/noxfile.py | 7 +- .../noxfile.py | 7 +- .../google-cloud-service-usage/noxfile.py | 7 +- .../google-cloud-servicehealth/noxfile.py | 7 +- packages/google-cloud-shell/noxfile.py | 7 +- .../google-cloud-source-context/noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-spanner/noxfile.py | 23 +-- packages/google-cloud-speech/noxfile.py | 7 +- .../google-cloud-storage-control/noxfile.py | 7 +- .../google-cloud-storage-transfer/noxfile.py | 7 +- packages/google-cloud-storage/noxfile.py | 2 +- .../noxfile.py | 7 +- .../google-cloud-storageinsights/noxfile.py | 7 +- packages/google-cloud-support/noxfile.py | 7 +- packages/google-cloud-talent/noxfile.py | 7 +- packages/google-cloud-tasks/noxfile.py | 7 +- .../google-cloud-telcoautomation/noxfile.py | 7 +- packages/google-cloud-testutils/noxfile.py | 34 +---- packages/google-cloud-texttospeech/noxfile.py | 7 +- packages/google-cloud-tpu/noxfile.py | 7 +- packages/google-cloud-trace/noxfile.py | 7 +- packages/google-cloud-translate/noxfile.py | 7 +- packages/google-cloud-vectorsearch/noxfile.py | 7 +- .../google-cloud-video-live-stream/noxfile.py | 7 +- .../google-cloud-video-stitcher/noxfile.py | 7 +- .../google-cloud-video-transcoder/noxfile.py | 7 +- .../google-cloud-videointelligence/noxfile.py | 7 +- packages/google-cloud-vision/noxfile.py | 7 +- packages/google-cloud-visionai/noxfile.py | 7 +- packages/google-cloud-vm-migration/noxfile.py | 7 +- packages/google-cloud-vmwareengine/noxfile.py | 7 +- packages/google-cloud-vpc-access/noxfile.py | 7 +- packages/google-cloud-webrisk/noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-cloud-workflows/noxfile.py | 7 +- .../google-cloud-workloadmanager/noxfile.py | 7 +- packages/google-cloud-workstations/noxfile.py | 7 +- .../google-developer-knowledge/noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-geo-type/noxfile.py | 7 +- .../google-maps-addressvalidation/noxfile.py | 7 +- packages/google-maps-areainsights/noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-maps-fleetengine/noxfile.py | 7 +- packages/google-maps-geocode/noxfile.py | 7 +- packages/google-maps-mapmanagement/noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-maps-navconnect/noxfile.py | 7 +- packages/google-maps-places/noxfile.py | 7 +- .../google-maps-routeoptimization/noxfile.py | 7 +- packages/google-maps-routing/noxfile.py | 7 +- packages/google-maps-solar/noxfile.py | 7 +- packages/google-resumable-media/noxfile.py | 38 ++--- packages/google-shopping-css/noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- .../google-shopping-merchant-lfp/noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- .../google-shopping-merchant-quota/noxfile.py | 7 +- .../noxfile.py | 7 +- .../noxfile.py | 7 +- packages/google-shopping-type/noxfile.py | 7 +- packages/googleapis-common-protos/noxfile.py | 2 +- packages/grafeas/noxfile.py | 7 +- packages/grpc-google-iam-v1/noxfile.py | 2 +- packages/pandas-gbq/noxfile.py | 2 +- packages/proto-plus/noxfile.py | 22 +-- packages/sqlalchemy-bigquery/noxfile.py | 23 +-- packages/sqlalchemy-spanner/noxfile.py | 23 +-- 418 files changed, 1768 insertions(+), 18371 deletions(-) diff --git a/packages/bigframes/noxfile.py b/packages/bigframes/noxfile.py index d0188e69df44..e1d19d697dd3 100644 --- a/packages/bigframes/noxfile.py +++ b/packages/bigframes/noxfile.py @@ -44,6 +44,7 @@ "3.10", # colab.research.google.com "3.11", + "import_profile", ] PYTEST_VERSION = "pytest==8.4.2" @@ -1108,27 +1109,7 @@ def import_profile(session): "python", str(profiler_script), "--module", - "unknown_module", - "--iterations", - "10", - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "unknown_module", + "google", "--iterations", "10", ) diff --git a/packages/bigquery-magics/noxfile.py b/packages/bigquery-magics/noxfile.py index efb3bddbe6ef..f5f3f9206f8f 100644 --- a/packages/bigquery-magics/noxfile.py +++ b/packages/bigquery-magics/noxfile.py @@ -41,6 +41,7 @@ "3.12", "3.13", "3.14", + "import_profile", ] UNIT_TEST_STANDARD_DEPENDENCIES = [ @@ -562,27 +563,7 @@ def import_profile(session): "python", str(profiler_script), "--module", - "unknown_module", - "--iterations", - "10", - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "unknown_module", + "google", "--iterations", "10", ) diff --git a/packages/db-dtypes/noxfile.py b/packages/db-dtypes/noxfile.py index c2475d848ce8..67c478ffb0a7 100644 --- a/packages/db-dtypes/noxfile.py +++ b/packages/db-dtypes/noxfile.py @@ -42,6 +42,7 @@ "3.12", "3.13", "3.14", + "import_profile", ] UNIT_TEST_STANDARD_DEPENDENCIES = [ @@ -560,20 +561,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "db_dtypes", "--iterations", "10" - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", str(profiler_script), "--module", "db_dtypes", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/django-google-spanner/noxfile.py b/packages/django-google-spanner/noxfile.py index 70379bf836f2..af0483e1e7c1 100644 --- a/packages/django-google-spanner/noxfile.py +++ b/packages/django-google-spanner/noxfile.py @@ -507,27 +507,7 @@ def import_profile(session): "python", str(profiler_script), "--module", - "unknown_module", - "--iterations", - "10", - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "unknown_module", + "google", "--iterations", "10", ) diff --git a/packages/gapic-generator/gapic/templates/noxfile.py.j2 b/packages/gapic-generator/gapic/templates/noxfile.py.j2 index 99ac9791bcf1..559adfa0c3e4 100644 --- a/packages/gapic-generator/gapic/templates/noxfile.py.j2 +++ b/packages/gapic-generator/gapic/templates/noxfile.py.j2 @@ -656,11 +656,21 @@ def import_profile(session): session.install(".") {% if api.naming.module_namespace %} session.run( - "python", str(profiler_script), "--module", "{{ api.naming.module_namespace[0] }}", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "{{ api.naming.module_namespace[0] }}", + "--iterations", + "10", ) {% else %} session.run( - "python", str(profiler_script), "--module", "{{ api.naming.versioned_module_name }}", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "{{ api.naming.versioned_module_name }}", + "--iterations", + "10", ) {% endif %} {% endblock %} diff --git a/packages/gapic-generator/noxfile.py b/packages/gapic-generator/noxfile.py index 5c7fdaf0f723..23b1734808b8 100644 --- a/packages/gapic-generator/noxfile.py +++ b/packages/gapic-generator/noxfile.py @@ -726,7 +726,7 @@ def lint(session): """ # TODO(https://github.com/googleapis/google-cloud-python/issues/16186): - # SKIP: This session was not enforced in the standalone (split) repo + # SKIP: This session was not enforced in the standalone (split) repo # and is disabled here to ensure a "move-only" migration. session.skip( "Linting was not enforced in the split repo. " @@ -756,11 +756,9 @@ def lint(session): @nox.session(python=NEWEST_PYTHON) def lint_setup_py(session): # TODO(https://github.com/googleapis/google-cloud-python/issues/16186): - # SKIP: This session was not enforced in the standalone (split) repo + # SKIP: This session was not enforced in the standalone (split) repo # and is disabled here to ensure a "move-only" migration. - session.skip( - "Skipping now to avoid changing code during migration. See Issue #16186" - ) + session.skip("Skipping now to avoid changing code during migration. See Issue #16186") @nox.session(python="3.10") @@ -835,11 +833,9 @@ def prerelease_deps(session, protobuf_implementation): """ Run all tests with pre-release versions of dependencies installed. """ - # TODO(https://github.com/googleapis/google-cloud-python/issues/16184): + # TODO(https://github.com/googleapis/google-cloud-python/issues/16184): # Implement pre-release dependency logic to test against upcoming runtime changes. - session.skip( - "prerelease_deps session is not yet implemented for gapic-generator-python." - ) + session.skip("prerelease_deps session is not yet implemented for gapic-generator-python.") @nox.session(python=NEWEST_PYTHON) @@ -849,27 +845,9 @@ def prerelease_deps(session, protobuf_implementation): ) def core_deps_from_source(session, protobuf_implementation): """Run all tests with core dependencies installed from source.""" - # TODO(https://github.com/googleapis/google-cloud-python/issues/16185): + # TODO(https://github.com/googleapis/google-cloud-python/issues/16185): # Implement logic to install core packages directly from the mono-repo directories. - session.skip( - "core_deps_from_source session is not yet implemented for gapic-generator-python." - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" - ) - + session.skip("core_deps_from_source session is not yet implemented for gapic-generator-python.") @nox.session(python="3.15") def import_profile(session): @@ -882,5 +860,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py b/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py index 97fcd4a4f33c..1c803e263c79 100755 --- a/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py @@ -48,11 +48,7 @@ # Path to the centralized mypy configuration file at the repository root. # Search upwards to support running nox from both monorepo packages and integration test goldens. MYPY_CONFIG_FILE = next( - ( - str(p / "mypy.ini") - for p in CURRENT_DIRECTORY.parents - if (p / "mypy.ini").exists() - ), + (str(p / "mypy.ini") for p in CURRENT_DIRECTORY.parents if (p / "mypy.ini").exists()), str(CURRENT_DIRECTORY.parent.parent / "mypy.ini"), ) @@ -168,8 +164,7 @@ def lint(session): # 2. Check formatting session.run( - "ruff", - "format", + "ruff", "format", "--check", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", @@ -182,15 +177,12 @@ def lint(session): @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): """(Deprecated) Legacy session. Please use 'nox -s format'.""" - session.log( - "WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future." - ) + session.log("WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future.") # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) session.install(RUFF_VERSION) session.run( - "ruff", - "format", + "ruff", "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", *LINT_PATHS, @@ -209,10 +201,8 @@ def format(session): # check --select I: Enables strict import sorting # --fix: Applies the changes automatically session.run( - "ruff", - "check", - "--select", - "I", + "ruff", "check", + "--select", "I", "--fix", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length @@ -221,8 +211,7 @@ def format(session): # 3. Run Ruff to format code session.run( - "ruff", - "format", + "ruff", "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length *LINT_PATHS, @@ -407,10 +396,8 @@ def docs(session): "sphinx-build", "-T", # show full traceback on exception "-N", # no colors - "-b", - "html", # builder - "-d", - os.path.join("docs", "_build", "doctrees", ""), # cache directory + "-b", "html", # builder + "-d", os.path.join("docs", "_build", "doctrees", ""), # cache directory # paths to build: os.path.join("docs", ""), os.path.join("docs", "_build", "html", ""), @@ -524,7 +511,8 @@ def prerelease_deps(session, protobuf_implementation): # Extract the base package name, safely ignoring version bounds and spaces # (e.g., "grpcio>=1.75.1" becomes "grpcio") parsed_deps = { - dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) for dep in prerel_deps + dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) + for dep in prerel_deps } # Dynamically sort local packages vs PyPI dependencies @@ -637,9 +625,7 @@ def core_deps_from_source(session, protobuf_implementation): dep_paths = [str(deps_dir / dep) for dep in core_dependencies_from_source] session.install(*dep_paths, "--no-deps", "--ignore-installed") - print( - f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}" - ) + print(f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}") session.run( "py.test", @@ -661,5 +647,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py b/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py index 544c7920db1c..3ffe0439c0bb 100755 --- a/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py @@ -48,11 +48,7 @@ # Path to the centralized mypy configuration file at the repository root. # Search upwards to support running nox from both monorepo packages and integration test goldens. MYPY_CONFIG_FILE = next( - ( - str(p / "mypy.ini") - for p in CURRENT_DIRECTORY.parents - if (p / "mypy.ini").exists() - ), + (str(p / "mypy.ini") for p in CURRENT_DIRECTORY.parents if (p / "mypy.ini").exists()), str(CURRENT_DIRECTORY.parent.parent / "mypy.ini"), ) @@ -168,8 +164,7 @@ def lint(session): # 2. Check formatting session.run( - "ruff", - "format", + "ruff", "format", "--check", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", @@ -182,15 +177,12 @@ def lint(session): @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): """(Deprecated) Legacy session. Please use 'nox -s format'.""" - session.log( - "WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future." - ) + session.log("WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future.") # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) session.install(RUFF_VERSION) session.run( - "ruff", - "format", + "ruff", "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", *LINT_PATHS, @@ -209,10 +201,8 @@ def format(session): # check --select I: Enables strict import sorting # --fix: Applies the changes automatically session.run( - "ruff", - "check", - "--select", - "I", + "ruff", "check", + "--select", "I", "--fix", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length @@ -221,8 +211,7 @@ def format(session): # 3. Run Ruff to format code session.run( - "ruff", - "format", + "ruff", "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length *LINT_PATHS, @@ -407,10 +396,8 @@ def docs(session): "sphinx-build", "-T", # show full traceback on exception "-N", # no colors - "-b", - "html", # builder - "-d", - os.path.join("docs", "_build", "doctrees", ""), # cache directory + "-b", "html", # builder + "-d", os.path.join("docs", "_build", "doctrees", ""), # cache directory # paths to build: os.path.join("docs", ""), os.path.join("docs", "_build", "html", ""), @@ -524,7 +511,8 @@ def prerelease_deps(session, protobuf_implementation): # Extract the base package name, safely ignoring version bounds and spaces # (e.g., "grpcio>=1.75.1" becomes "grpcio") parsed_deps = { - dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) for dep in prerel_deps + dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) + for dep in prerel_deps } # Dynamically sort local packages vs PyPI dependencies @@ -637,9 +625,7 @@ def core_deps_from_source(session, protobuf_implementation): dep_paths = [str(deps_dir / dep) for dep in core_dependencies_from_source] session.install(*dep_paths, "--no-deps", "--ignore-installed") - print( - f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}" - ) + print(f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}") session.run( "py.test", @@ -661,5 +647,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py b/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py index 9a32fb5f36c4..3dd516951f0d 100755 --- a/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py @@ -48,11 +48,7 @@ # Path to the centralized mypy configuration file at the repository root. # Search upwards to support running nox from both monorepo packages and integration test goldens. MYPY_CONFIG_FILE = next( - ( - str(p / "mypy.ini") - for p in CURRENT_DIRECTORY.parents - if (p / "mypy.ini").exists() - ), + (str(p / "mypy.ini") for p in CURRENT_DIRECTORY.parents if (p / "mypy.ini").exists()), str(CURRENT_DIRECTORY.parent.parent / "mypy.ini"), ) @@ -168,8 +164,7 @@ def lint(session): # 2. Check formatting session.run( - "ruff", - "format", + "ruff", "format", "--check", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", @@ -182,15 +177,12 @@ def lint(session): @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): """(Deprecated) Legacy session. Please use 'nox -s format'.""" - session.log( - "WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future." - ) + session.log("WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future.") # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) session.install(RUFF_VERSION) session.run( - "ruff", - "format", + "ruff", "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", *LINT_PATHS, @@ -209,10 +201,8 @@ def format(session): # check --select I: Enables strict import sorting # --fix: Applies the changes automatically session.run( - "ruff", - "check", - "--select", - "I", + "ruff", "check", + "--select", "I", "--fix", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length @@ -221,8 +211,7 @@ def format(session): # 3. Run Ruff to format code session.run( - "ruff", - "format", + "ruff", "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length *LINT_PATHS, @@ -407,10 +396,8 @@ def docs(session): "sphinx-build", "-T", # show full traceback on exception "-N", # no colors - "-b", - "html", # builder - "-d", - os.path.join("docs", "_build", "doctrees", ""), # cache directory + "-b", "html", # builder + "-d", os.path.join("docs", "_build", "doctrees", ""), # cache directory # paths to build: os.path.join("docs", ""), os.path.join("docs", "_build", "html", ""), @@ -524,7 +511,8 @@ def prerelease_deps(session, protobuf_implementation): # Extract the base package name, safely ignoring version bounds and spaces # (e.g., "grpcio>=1.75.1" becomes "grpcio") parsed_deps = { - dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) for dep in prerel_deps + dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) + for dep in prerel_deps } # Dynamically sort local packages vs PyPI dependencies @@ -637,9 +625,7 @@ def core_deps_from_source(session, protobuf_implementation): dep_paths = [str(deps_dir / dep) for dep in core_dependencies_from_source] session.install(*dep_paths, "--no-deps", "--ignore-installed") - print( - f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}" - ) + print(f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}") session.run( "py.test", @@ -661,5 +647,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py b/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py index 253427faa7e7..208d95f44b76 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py @@ -48,11 +48,7 @@ # Path to the centralized mypy configuration file at the repository root. # Search upwards to support running nox from both monorepo packages and integration test goldens. MYPY_CONFIG_FILE = next( - ( - str(p / "mypy.ini") - for p in CURRENT_DIRECTORY.parents - if (p / "mypy.ini").exists() - ), + (str(p / "mypy.ini") for p in CURRENT_DIRECTORY.parents if (p / "mypy.ini").exists()), str(CURRENT_DIRECTORY.parent.parent / "mypy.ini"), ) @@ -168,8 +164,7 @@ def lint(session): # 2. Check formatting session.run( - "ruff", - "format", + "ruff", "format", "--check", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", @@ -182,15 +177,12 @@ def lint(session): @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): """(Deprecated) Legacy session. Please use 'nox -s format'.""" - session.log( - "WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future." - ) + session.log("WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future.") # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) session.install(RUFF_VERSION) session.run( - "ruff", - "format", + "ruff", "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", *LINT_PATHS, @@ -209,10 +201,8 @@ def format(session): # check --select I: Enables strict import sorting # --fix: Applies the changes automatically session.run( - "ruff", - "check", - "--select", - "I", + "ruff", "check", + "--select", "I", "--fix", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length @@ -221,8 +211,7 @@ def format(session): # 3. Run Ruff to format code session.run( - "ruff", - "format", + "ruff", "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length *LINT_PATHS, @@ -407,10 +396,8 @@ def docs(session): "sphinx-build", "-T", # show full traceback on exception "-N", # no colors - "-b", - "html", # builder - "-d", - os.path.join("docs", "_build", "doctrees", ""), # cache directory + "-b", "html", # builder + "-d", os.path.join("docs", "_build", "doctrees", ""), # cache directory # paths to build: os.path.join("docs", ""), os.path.join("docs", "_build", "html", ""), @@ -524,7 +511,8 @@ def prerelease_deps(session, protobuf_implementation): # Extract the base package name, safely ignoring version bounds and spaces # (e.g., "grpcio>=1.75.1" becomes "grpcio") parsed_deps = { - dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) for dep in prerel_deps + dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) + for dep in prerel_deps } # Dynamically sort local packages vs PyPI dependencies @@ -637,9 +625,7 @@ def core_deps_from_source(session, protobuf_implementation): dep_paths = [str(deps_dir / dep) for dep in core_dependencies_from_source] session.install(*dep_paths, "--no-deps", "--ignore-installed") - print( - f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}" - ) + print(f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}") session.run( "py.test", @@ -661,5 +647,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py b/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py index 253427faa7e7..208d95f44b76 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py @@ -48,11 +48,7 @@ # Path to the centralized mypy configuration file at the repository root. # Search upwards to support running nox from both monorepo packages and integration test goldens. MYPY_CONFIG_FILE = next( - ( - str(p / "mypy.ini") - for p in CURRENT_DIRECTORY.parents - if (p / "mypy.ini").exists() - ), + (str(p / "mypy.ini") for p in CURRENT_DIRECTORY.parents if (p / "mypy.ini").exists()), str(CURRENT_DIRECTORY.parent.parent / "mypy.ini"), ) @@ -168,8 +164,7 @@ def lint(session): # 2. Check formatting session.run( - "ruff", - "format", + "ruff", "format", "--check", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", @@ -182,15 +177,12 @@ def lint(session): @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): """(Deprecated) Legacy session. Please use 'nox -s format'.""" - session.log( - "WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future." - ) + session.log("WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future.") # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) session.install(RUFF_VERSION) session.run( - "ruff", - "format", + "ruff", "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", *LINT_PATHS, @@ -209,10 +201,8 @@ def format(session): # check --select I: Enables strict import sorting # --fix: Applies the changes automatically session.run( - "ruff", - "check", - "--select", - "I", + "ruff", "check", + "--select", "I", "--fix", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length @@ -221,8 +211,7 @@ def format(session): # 3. Run Ruff to format code session.run( - "ruff", - "format", + "ruff", "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length *LINT_PATHS, @@ -407,10 +396,8 @@ def docs(session): "sphinx-build", "-T", # show full traceback on exception "-N", # no colors - "-b", - "html", # builder - "-d", - os.path.join("docs", "_build", "doctrees", ""), # cache directory + "-b", "html", # builder + "-d", os.path.join("docs", "_build", "doctrees", ""), # cache directory # paths to build: os.path.join("docs", ""), os.path.join("docs", "_build", "html", ""), @@ -524,7 +511,8 @@ def prerelease_deps(session, protobuf_implementation): # Extract the base package name, safely ignoring version bounds and spaces # (e.g., "grpcio>=1.75.1" becomes "grpcio") parsed_deps = { - dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) for dep in prerel_deps + dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) + for dep in prerel_deps } # Dynamically sort local packages vs PyPI dependencies @@ -637,9 +625,7 @@ def core_deps_from_source(session, protobuf_implementation): dep_paths = [str(deps_dir / dep) for dep in core_dependencies_from_source] session.install(*dep_paths, "--no-deps", "--ignore-installed") - print( - f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}" - ) + print(f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}") session.run( "py.test", @@ -661,5 +647,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py b/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py index cb6dcce4c06b..ef6419e5dee9 100755 --- a/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py @@ -48,11 +48,7 @@ # Path to the centralized mypy configuration file at the repository root. # Search upwards to support running nox from both monorepo packages and integration test goldens. MYPY_CONFIG_FILE = next( - ( - str(p / "mypy.ini") - for p in CURRENT_DIRECTORY.parents - if (p / "mypy.ini").exists() - ), + (str(p / "mypy.ini") for p in CURRENT_DIRECTORY.parents if (p / "mypy.ini").exists()), str(CURRENT_DIRECTORY.parent.parent / "mypy.ini"), ) @@ -168,8 +164,7 @@ def lint(session): # 2. Check formatting session.run( - "ruff", - "format", + "ruff", "format", "--check", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", @@ -182,15 +177,12 @@ def lint(session): @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): """(Deprecated) Legacy session. Please use 'nox -s format'.""" - session.log( - "WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future." - ) + session.log("WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future.") # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) session.install(RUFF_VERSION) session.run( - "ruff", - "format", + "ruff", "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", *LINT_PATHS, @@ -209,10 +201,8 @@ def format(session): # check --select I: Enables strict import sorting # --fix: Applies the changes automatically session.run( - "ruff", - "check", - "--select", - "I", + "ruff", "check", + "--select", "I", "--fix", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length @@ -221,8 +211,7 @@ def format(session): # 3. Run Ruff to format code session.run( - "ruff", - "format", + "ruff", "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length *LINT_PATHS, @@ -407,10 +396,8 @@ def docs(session): "sphinx-build", "-T", # show full traceback on exception "-N", # no colors - "-b", - "html", # builder - "-d", - os.path.join("docs", "_build", "doctrees", ""), # cache directory + "-b", "html", # builder + "-d", os.path.join("docs", "_build", "doctrees", ""), # cache directory # paths to build: os.path.join("docs", ""), os.path.join("docs", "_build", "html", ""), @@ -524,7 +511,8 @@ def prerelease_deps(session, protobuf_implementation): # Extract the base package name, safely ignoring version bounds and spaces # (e.g., "grpcio>=1.75.1" becomes "grpcio") parsed_deps = { - dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) for dep in prerel_deps + dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) + for dep in prerel_deps } # Dynamically sort local packages vs PyPI dependencies @@ -637,9 +625,7 @@ def core_deps_from_source(session, protobuf_implementation): dep_paths = [str(deps_dir / dep) for dep in core_dependencies_from_source] session.install(*dep_paths, "--no-deps", "--ignore-installed") - print( - f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}" - ) + print(f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}") session.run( "py.test", @@ -661,5 +647,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py b/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py index cb6dcce4c06b..ef6419e5dee9 100755 --- a/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py @@ -48,11 +48,7 @@ # Path to the centralized mypy configuration file at the repository root. # Search upwards to support running nox from both monorepo packages and integration test goldens. MYPY_CONFIG_FILE = next( - ( - str(p / "mypy.ini") - for p in CURRENT_DIRECTORY.parents - if (p / "mypy.ini").exists() - ), + (str(p / "mypy.ini") for p in CURRENT_DIRECTORY.parents if (p / "mypy.ini").exists()), str(CURRENT_DIRECTORY.parent.parent / "mypy.ini"), ) @@ -168,8 +164,7 @@ def lint(session): # 2. Check formatting session.run( - "ruff", - "format", + "ruff", "format", "--check", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", @@ -182,15 +177,12 @@ def lint(session): @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): """(Deprecated) Legacy session. Please use 'nox -s format'.""" - session.log( - "WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future." - ) + session.log("WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future.") # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) session.install(RUFF_VERSION) session.run( - "ruff", - "format", + "ruff", "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", *LINT_PATHS, @@ -209,10 +201,8 @@ def format(session): # check --select I: Enables strict import sorting # --fix: Applies the changes automatically session.run( - "ruff", - "check", - "--select", - "I", + "ruff", "check", + "--select", "I", "--fix", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length @@ -221,8 +211,7 @@ def format(session): # 3. Run Ruff to format code session.run( - "ruff", - "format", + "ruff", "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length *LINT_PATHS, @@ -407,10 +396,8 @@ def docs(session): "sphinx-build", "-T", # show full traceback on exception "-N", # no colors - "-b", - "html", # builder - "-d", - os.path.join("docs", "_build", "doctrees", ""), # cache directory + "-b", "html", # builder + "-d", os.path.join("docs", "_build", "doctrees", ""), # cache directory # paths to build: os.path.join("docs", ""), os.path.join("docs", "_build", "html", ""), @@ -524,7 +511,8 @@ def prerelease_deps(session, protobuf_implementation): # Extract the base package name, safely ignoring version bounds and spaces # (e.g., "grpcio>=1.75.1" becomes "grpcio") parsed_deps = { - dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) for dep in prerel_deps + dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) + for dep in prerel_deps } # Dynamically sort local packages vs PyPI dependencies @@ -637,9 +625,7 @@ def core_deps_from_source(session, protobuf_implementation): dep_paths = [str(deps_dir / dep) for dep in core_dependencies_from_source] session.install(*dep_paths, "--no-deps", "--ignore-installed") - print( - f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}" - ) + print(f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}") session.run( "py.test", @@ -661,5 +647,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py b/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py index bf37e75a229f..bb885d07c222 100755 --- a/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py @@ -48,11 +48,7 @@ # Path to the centralized mypy configuration file at the repository root. # Search upwards to support running nox from both monorepo packages and integration test goldens. MYPY_CONFIG_FILE = next( - ( - str(p / "mypy.ini") - for p in CURRENT_DIRECTORY.parents - if (p / "mypy.ini").exists() - ), + (str(p / "mypy.ini") for p in CURRENT_DIRECTORY.parents if (p / "mypy.ini").exists()), str(CURRENT_DIRECTORY.parent.parent / "mypy.ini"), ) @@ -168,8 +164,7 @@ def lint(session): # 2. Check formatting session.run( - "ruff", - "format", + "ruff", "format", "--check", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", @@ -182,15 +177,12 @@ def lint(session): @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): """(Deprecated) Legacy session. Please use 'nox -s format'.""" - session.log( - "WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future." - ) + session.log("WARNING: The 'blacken' session is deprecated and will be removed in a future release. Please use 'nox -s format' in the future.") # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) session.install(RUFF_VERSION) session.run( - "ruff", - "format", + "ruff", "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", *LINT_PATHS, @@ -209,10 +201,8 @@ def format(session): # check --select I: Enables strict import sorting # --fix: Applies the changes automatically session.run( - "ruff", - "check", - "--select", - "I", + "ruff", "check", + "--select", "I", "--fix", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length @@ -221,8 +211,7 @@ def format(session): # 3. Run Ruff to format code session.run( - "ruff", - "format", + "ruff", "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", # Standard Black line length *LINT_PATHS, @@ -407,10 +396,8 @@ def docs(session): "sphinx-build", "-T", # show full traceback on exception "-N", # no colors - "-b", - "html", # builder - "-d", - os.path.join("docs", "_build", "doctrees", ""), # cache directory + "-b", "html", # builder + "-d", os.path.join("docs", "_build", "doctrees", ""), # cache directory # paths to build: os.path.join("docs", ""), os.path.join("docs", "_build", "html", ""), @@ -524,7 +511,8 @@ def prerelease_deps(session, protobuf_implementation): # Extract the base package name, safely ignoring version bounds and spaces # (e.g., "grpcio>=1.75.1" becomes "grpcio") parsed_deps = { - dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) for dep in prerel_deps + dep: re.match(r"^([a-zA-Z0-9_-]+)", dep).group(1) + for dep in prerel_deps } # Dynamically sort local packages vs PyPI dependencies @@ -637,9 +625,7 @@ def core_deps_from_source(session, protobuf_implementation): dep_paths = [str(deps_dir / dep) for dep in core_dependencies_from_source] session.install(*dep_paths, "--no-deps", "--ignore-installed") - print( - f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}" - ) + print(f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}") session.run( "py.test", @@ -661,5 +647,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/gcp-sphinx-docfx-yaml/noxfile.py b/packages/gcp-sphinx-docfx-yaml/noxfile.py index 0a0ddbca4242..acc6492c90b9 100644 --- a/packages/gcp-sphinx-docfx-yaml/noxfile.py +++ b/packages/gcp-sphinx-docfx-yaml/noxfile.py @@ -32,6 +32,7 @@ "docs", "prerelease_deps", "core_deps_from_source", + "import_profile", ] @@ -189,27 +190,7 @@ def import_profile(session): "python", str(profiler_script), "--module", - "unknown_module", - "--iterations", - "10", - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "unknown_module", + "google", "--iterations", "10", ) diff --git a/packages/google-ads-admanager/noxfile.py b/packages/google-ads-admanager/noxfile.py index ca5891156343..dedf4a9af166 100644 --- a/packages/google-ads-admanager/noxfile.py +++ b/packages/google-ads-admanager/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-ads-datamanager/noxfile.py b/packages/google-ads-datamanager/noxfile.py index e6ce28e544af..fce0cb56742b 100644 --- a/packages/google-ads-datamanager/noxfile.py +++ b/packages/google-ads-datamanager/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-ads-marketingplatform-admin/noxfile.py b/packages/google-ads-marketingplatform-admin/noxfile.py index 35b098b07f61..06f87547da63 100644 --- a/packages/google-ads-marketingplatform-admin/noxfile.py +++ b/packages/google-ads-marketingplatform-admin/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-ai-generativelanguage/noxfile.py b/packages/google-ai-generativelanguage/noxfile.py index 241254eafdbe..7c1eabfdac45 100644 --- a/packages/google-ai-generativelanguage/noxfile.py +++ b/packages/google-ai-generativelanguage/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-analytics-admin/noxfile.py b/packages/google-analytics-admin/noxfile.py index 1960dc88a7bb..d124274c02bb 100644 --- a/packages/google-analytics-admin/noxfile.py +++ b/packages/google-analytics-admin/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-analytics-data/noxfile.py b/packages/google-analytics-data/noxfile.py index 20b8ab823916..b6fc40f24fb0 100644 --- a/packages/google-analytics-data/noxfile.py +++ b/packages/google-analytics-data/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-api-core/noxfile.py b/packages/google-api-core/noxfile.py index c3695042fca3..023ca033f95b 100644 --- a/packages/google-api-core/noxfile.py +++ b/packages/google-api-core/noxfile.py @@ -480,27 +480,7 @@ def import_profile(session): "python", str(profiler_script), "--module", - "unknown_module", - "--iterations", - "10", - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "unknown_module", + "google", "--iterations", "10", ) diff --git a/packages/google-apps-card/noxfile.py b/packages/google-apps-card/noxfile.py index d20f7d5ba040..bebe7006874c 100644 --- a/packages/google-apps-card/noxfile.py +++ b/packages/google-apps-card/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-apps-chat/noxfile.py b/packages/google-apps-chat/noxfile.py index f00bb92a3913..d91d3274fefe 100644 --- a/packages/google-apps-chat/noxfile.py +++ b/packages/google-apps-chat/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-apps-events-subscriptions/noxfile.py b/packages/google-apps-events-subscriptions/noxfile.py index 4b056242d52a..52a64de822c5 100644 --- a/packages/google-apps-events-subscriptions/noxfile.py +++ b/packages/google-apps-events-subscriptions/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-apps-meet/noxfile.py b/packages/google-apps-meet/noxfile.py index 990c53016d03..81fc96da0710 100644 --- a/packages/google-apps-meet/noxfile.py +++ b/packages/google-apps-meet/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-apps-script-type/noxfile.py b/packages/google-apps-script-type/noxfile.py index faf035bfbec7..1588a173aeff 100644 --- a/packages/google-apps-script-type/noxfile.py +++ b/packages/google-apps-script-type/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-area120-tables/noxfile.py b/packages/google-area120-tables/noxfile.py index b749184e463d..2f5ccdd80edb 100644 --- a/packages/google-area120-tables/noxfile.py +++ b/packages/google-area120-tables/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-auth-httplib2/noxfile.py b/packages/google-auth-httplib2/noxfile.py index 61963457529d..53cfa9f1153d 100644 --- a/packages/google-auth-httplib2/noxfile.py +++ b/packages/google-auth-httplib2/noxfile.py @@ -545,27 +545,7 @@ def import_profile(session): "python", str(profiler_script), "--module", - "unknown_module", - "--iterations", - "10", - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "unknown_module", + "google", "--iterations", "10", ) diff --git a/packages/google-auth-oauthlib/noxfile.py b/packages/google-auth-oauthlib/noxfile.py index 3fbbc2574605..4ccf6a8fe0b6 100644 --- a/packages/google-auth-oauthlib/noxfile.py +++ b/packages/google-auth-oauthlib/noxfile.py @@ -490,27 +490,7 @@ def import_profile(session): "python", str(profiler_script), "--module", - "google_auth_oauthlib", - "--iterations", - "10", - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google_auth_oauthlib", + "google", "--iterations", "10", ) diff --git a/packages/google-auth/noxfile.py b/packages/google-auth/noxfile.py index 73d54dd552ea..78894295de10 100644 --- a/packages/google-auth/noxfile.py +++ b/packages/google-auth/noxfile.py @@ -328,5 +328,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-backstory/noxfile.py b/packages/google-backstory/noxfile.py index b6a76a5fd89e..1d72118c0ac5 100644 --- a/packages/google-backstory/noxfile.py +++ b/packages/google-backstory/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-access-approval/noxfile.py b/packages/google-cloud-access-approval/noxfile.py index 0bf1d2f89449..cb79279e0192 100644 --- a/packages/google-cloud-access-approval/noxfile.py +++ b/packages/google-cloud-access-approval/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-access-context-manager/noxfile.py b/packages/google-cloud-access-context-manager/noxfile.py index f7b7b5a0f50c..483619fa4bb6 100644 --- a/packages/google-cloud-access-context-manager/noxfile.py +++ b/packages/google-cloud-access-context-manager/noxfile.py @@ -594,7 +594,7 @@ def import_profile(session): "python", str(profiler_script), "--module", - "unknown_module", + "google", "--iterations", "10", ) diff --git a/packages/google-cloud-advisorynotifications/noxfile.py b/packages/google-cloud-advisorynotifications/noxfile.py index dd5c027e2217..16ccdb125282 100644 --- a/packages/google-cloud-advisorynotifications/noxfile.py +++ b/packages/google-cloud-advisorynotifications/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-agentidentitycredentials/noxfile.py b/packages/google-cloud-agentidentitycredentials/noxfile.py index f50a762ce36c..0653b5357af3 100644 --- a/packages/google-cloud-agentidentitycredentials/noxfile.py +++ b/packages/google-cloud-agentidentitycredentials/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-agentregistry/noxfile.py b/packages/google-cloud-agentregistry/noxfile.py index 97e3d3154f1f..534109007b92 100644 --- a/packages/google-cloud-agentregistry/noxfile.py +++ b/packages/google-cloud-agentregistry/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-alloydb-connectors/noxfile.py b/packages/google-cloud-alloydb-connectors/noxfile.py index 56359ca978f1..a6f9deae5574 100644 --- a/packages/google-cloud-alloydb-connectors/noxfile.py +++ b/packages/google-cloud-alloydb-connectors/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-alloydb/noxfile.py b/packages/google-cloud-alloydb/noxfile.py index 79e3e99c6c16..0f9cd5463ba8 100644 --- a/packages/google-cloud-alloydb/noxfile.py +++ b/packages/google-cloud-alloydb/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-api-gateway/noxfile.py b/packages/google-cloud-api-gateway/noxfile.py index bf4fd36037ab..ffb5de8245dc 100644 --- a/packages/google-cloud-api-gateway/noxfile.py +++ b/packages/google-cloud-api-gateway/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-api-keys/noxfile.py b/packages/google-cloud-api-keys/noxfile.py index 5bc06a2075cf..c0e711a79270 100644 --- a/packages/google-cloud-api-keys/noxfile.py +++ b/packages/google-cloud-api-keys/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-apigee-connect/noxfile.py b/packages/google-cloud-apigee-connect/noxfile.py index 7a01f81e5dd4..949315ae5280 100644 --- a/packages/google-cloud-apigee-connect/noxfile.py +++ b/packages/google-cloud-apigee-connect/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-apigee-registry/noxfile.py b/packages/google-cloud-apigee-registry/noxfile.py index 5a2ad8e87d7d..6b1bb29a59d9 100644 --- a/packages/google-cloud-apigee-registry/noxfile.py +++ b/packages/google-cloud-apigee-registry/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-apihub/noxfile.py b/packages/google-cloud-apihub/noxfile.py index 2b23e83f5494..b56e806797b3 100644 --- a/packages/google-cloud-apihub/noxfile.py +++ b/packages/google-cloud-apihub/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-apiregistry/noxfile.py b/packages/google-cloud-apiregistry/noxfile.py index c59033e40344..3ce22aaf2fa0 100644 --- a/packages/google-cloud-apiregistry/noxfile.py +++ b/packages/google-cloud-apiregistry/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-appengine-admin/noxfile.py b/packages/google-cloud-appengine-admin/noxfile.py index c833f6489926..f9d53da73541 100644 --- a/packages/google-cloud-appengine-admin/noxfile.py +++ b/packages/google-cloud-appengine-admin/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-appengine-logging/noxfile.py b/packages/google-cloud-appengine-logging/noxfile.py index 2f2de9157d09..16dd777064dc 100644 --- a/packages/google-cloud-appengine-logging/noxfile.py +++ b/packages/google-cloud-appengine-logging/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-apphub/noxfile.py b/packages/google-cloud-apphub/noxfile.py index 9b6fc35cc97b..ca2360c35ec2 100644 --- a/packages/google-cloud-apphub/noxfile.py +++ b/packages/google-cloud-apphub/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-appoptimize/noxfile.py b/packages/google-cloud-appoptimize/noxfile.py index 3eab3fa788cc..45c2eeaf7fca 100644 --- a/packages/google-cloud-appoptimize/noxfile.py +++ b/packages/google-cloud-appoptimize/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-artifact-registry/noxfile.py b/packages/google-cloud-artifact-registry/noxfile.py index aeade22821e0..7bf0895ac528 100644 --- a/packages/google-cloud-artifact-registry/noxfile.py +++ b/packages/google-cloud-artifact-registry/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-asset/noxfile.py b/packages/google-cloud-asset/noxfile.py index 960608c217dc..66c26df2b9c2 100644 --- a/packages/google-cloud-asset/noxfile.py +++ b/packages/google-cloud-asset/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-assured-workloads/noxfile.py b/packages/google-cloud-assured-workloads/noxfile.py index c14a94b483cd..63f6191e1870 100644 --- a/packages/google-cloud-assured-workloads/noxfile.py +++ b/packages/google-cloud-assured-workloads/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-audit-log/noxfile.py b/packages/google-cloud-audit-log/noxfile.py index 4c77684320a8..a188e4b9bfb4 100644 --- a/packages/google-cloud-audit-log/noxfile.py +++ b/packages/google-cloud-audit-log/noxfile.py @@ -580,7 +580,7 @@ def import_profile(session): "python", str(profiler_script), "--module", - "unknown_module", + "google", "--iterations", "10", ) diff --git a/packages/google-cloud-auditmanager/noxfile.py b/packages/google-cloud-auditmanager/noxfile.py index ce11b46ff632..51f30d8928d7 100644 --- a/packages/google-cloud-auditmanager/noxfile.py +++ b/packages/google-cloud-auditmanager/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-automl/noxfile.py b/packages/google-cloud-automl/noxfile.py index fe31524cc67f..b5bb029dbad0 100644 --- a/packages/google-cloud-automl/noxfile.py +++ b/packages/google-cloud-automl/noxfile.py @@ -652,5 +652,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-backupdr/noxfile.py b/packages/google-cloud-backupdr/noxfile.py index fd424de54dd6..509ca140eb4a 100644 --- a/packages/google-cloud-backupdr/noxfile.py +++ b/packages/google-cloud-backupdr/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-bare-metal-solution/noxfile.py b/packages/google-cloud-bare-metal-solution/noxfile.py index a5dde33df129..fb7e646b60a6 100644 --- a/packages/google-cloud-bare-metal-solution/noxfile.py +++ b/packages/google-cloud-bare-metal-solution/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-batch/noxfile.py b/packages/google-cloud-batch/noxfile.py index 2f371117de91..423254fd4bae 100644 --- a/packages/google-cloud-batch/noxfile.py +++ b/packages/google-cloud-batch/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-beyondcorp-appconnections/noxfile.py b/packages/google-cloud-beyondcorp-appconnections/noxfile.py index 03579ee771c1..6762f78a0d4b 100644 --- a/packages/google-cloud-beyondcorp-appconnections/noxfile.py +++ b/packages/google-cloud-beyondcorp-appconnections/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-beyondcorp-appconnectors/noxfile.py b/packages/google-cloud-beyondcorp-appconnectors/noxfile.py index e336e0bdf0a4..899b14f44e0f 100644 --- a/packages/google-cloud-beyondcorp-appconnectors/noxfile.py +++ b/packages/google-cloud-beyondcorp-appconnectors/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-beyondcorp-appgateways/noxfile.py b/packages/google-cloud-beyondcorp-appgateways/noxfile.py index b90136f9fcc4..150de37e1c53 100644 --- a/packages/google-cloud-beyondcorp-appgateways/noxfile.py +++ b/packages/google-cloud-beyondcorp-appgateways/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py b/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py index 1bd252b2e5d1..affe8c1e5fa3 100644 --- a/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py +++ b/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-beyondcorp-clientgateways/noxfile.py b/packages/google-cloud-beyondcorp-clientgateways/noxfile.py index 25f236175d02..2cf2de669ea3 100644 --- a/packages/google-cloud-beyondcorp-clientgateways/noxfile.py +++ b/packages/google-cloud-beyondcorp-clientgateways/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-biglake-hive/noxfile.py b/packages/google-cloud-biglake-hive/noxfile.py index e584d65a2040..5e0a9d4771d4 100644 --- a/packages/google-cloud-biglake-hive/noxfile.py +++ b/packages/google-cloud-biglake-hive/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-biglake/noxfile.py b/packages/google-cloud-biglake/noxfile.py index 8c855f291049..3e3c60e4ff33 100644 --- a/packages/google-cloud-biglake/noxfile.py +++ b/packages/google-cloud-biglake/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-bigquery-analyticshub/noxfile.py b/packages/google-cloud-bigquery-analyticshub/noxfile.py index 40a147fb093a..f35a43e2d54f 100644 --- a/packages/google-cloud-bigquery-analyticshub/noxfile.py +++ b/packages/google-cloud-bigquery-analyticshub/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-bigquery-biglake/noxfile.py b/packages/google-cloud-bigquery-biglake/noxfile.py index d963e7ca2ce6..af6a9bcbb63e 100644 --- a/packages/google-cloud-bigquery-biglake/noxfile.py +++ b/packages/google-cloud-bigquery-biglake/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-bigquery-connection/noxfile.py b/packages/google-cloud-bigquery-connection/noxfile.py index 477e2abac239..fe9a15a7769d 100644 --- a/packages/google-cloud-bigquery-connection/noxfile.py +++ b/packages/google-cloud-bigquery-connection/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-bigquery-data-exchange/noxfile.py b/packages/google-cloud-bigquery-data-exchange/noxfile.py index cafc3fb2da5e..51333110286f 100644 --- a/packages/google-cloud-bigquery-data-exchange/noxfile.py +++ b/packages/google-cloud-bigquery-data-exchange/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-bigquery-datapolicies/noxfile.py b/packages/google-cloud-bigquery-datapolicies/noxfile.py index 514e9ab4f54b..813fa958c67c 100644 --- a/packages/google-cloud-bigquery-datapolicies/noxfile.py +++ b/packages/google-cloud-bigquery-datapolicies/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-bigquery-datatransfer/noxfile.py b/packages/google-cloud-bigquery-datatransfer/noxfile.py index 86f165efd67f..998be4f9941b 100644 --- a/packages/google-cloud-bigquery-datatransfer/noxfile.py +++ b/packages/google-cloud-bigquery-datatransfer/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-bigquery-logging/noxfile.py b/packages/google-cloud-bigquery-logging/noxfile.py index aecb1b0106d2..eb34c32918e4 100644 --- a/packages/google-cloud-bigquery-logging/noxfile.py +++ b/packages/google-cloud-bigquery-logging/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-bigquery-migration/noxfile.py b/packages/google-cloud-bigquery-migration/noxfile.py index 37754fbecb59..672bc32f4cad 100644 --- a/packages/google-cloud-bigquery-migration/noxfile.py +++ b/packages/google-cloud-bigquery-migration/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-bigquery-reservation/noxfile.py b/packages/google-cloud-bigquery-reservation/noxfile.py index 19d38b6ec392..abd5d5622e5b 100644 --- a/packages/google-cloud-bigquery-reservation/noxfile.py +++ b/packages/google-cloud-bigquery-reservation/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-bigquery-storage/noxfile.py b/packages/google-cloud-bigquery-storage/noxfile.py index d5b5616fe6e0..fb0b29834a7d 100644 --- a/packages/google-cloud-bigquery-storage/noxfile.py +++ b/packages/google-cloud-bigquery-storage/noxfile.py @@ -692,5 +692,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-bigquery/noxfile.py b/packages/google-cloud-bigquery/noxfile.py index 07291c38f5b5..7fcc5a45c65b 100644 --- a/packages/google-cloud-bigquery/noxfile.py +++ b/packages/google-cloud-bigquery/noxfile.py @@ -79,6 +79,7 @@ def wrapper(*args, **kwargs): "docs", "core_deps_from_source", "format", + "import_profile", ] @@ -599,20 +600,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-bigtable/noxfile.py b/packages/google-cloud-bigtable/noxfile.py index 3444d65a2ac1..7bc65f3aad28 100644 --- a/packages/google-cloud-bigtable/noxfile.py +++ b/packages/google-cloud-bigtable/noxfile.py @@ -33,6 +33,7 @@ "3.12", "3.13", "3.14", + "import_profile", ] UNIT_TEST_STANDARD_DEPENDENCIES = [ @@ -641,27 +642,7 @@ def import_profile(session): "python", str(profiler_script), "--module", - "google.cloud.bigtable.data", - "--iterations", - "10", - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google.cloud.bigtable.data", + "google", "--iterations", "10", ) diff --git a/packages/google-cloud-billing-budgets/noxfile.py b/packages/google-cloud-billing-budgets/noxfile.py index 0de09557cc35..1be9282c4107 100644 --- a/packages/google-cloud-billing-budgets/noxfile.py +++ b/packages/google-cloud-billing-budgets/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-billing/noxfile.py b/packages/google-cloud-billing/noxfile.py index 25edc73ec721..225e3cb8b8d0 100644 --- a/packages/google-cloud-billing/noxfile.py +++ b/packages/google-cloud-billing/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-binary-authorization/noxfile.py b/packages/google-cloud-binary-authorization/noxfile.py index 491bc9cbafee..98df4a170fb8 100644 --- a/packages/google-cloud-binary-authorization/noxfile.py +++ b/packages/google-cloud-binary-authorization/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-build/noxfile.py b/packages/google-cloud-build/noxfile.py index 97072556b717..27903d1557d1 100644 --- a/packages/google-cloud-build/noxfile.py +++ b/packages/google-cloud-build/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-capacityplanner/noxfile.py b/packages/google-cloud-capacityplanner/noxfile.py index 24651dc38879..4c4a2846fb76 100644 --- a/packages/google-cloud-capacityplanner/noxfile.py +++ b/packages/google-cloud-capacityplanner/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-certificate-manager/noxfile.py b/packages/google-cloud-certificate-manager/noxfile.py index 9cf80c5b1f3e..6a89dd993586 100644 --- a/packages/google-cloud-certificate-manager/noxfile.py +++ b/packages/google-cloud-certificate-manager/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-ces/noxfile.py b/packages/google-cloud-ces/noxfile.py index 5eda0360d316..6af691d14416 100644 --- a/packages/google-cloud-ces/noxfile.py +++ b/packages/google-cloud-ces/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-channel/noxfile.py b/packages/google-cloud-channel/noxfile.py index ad716c849749..b4fcb61e2175 100644 --- a/packages/google-cloud-channel/noxfile.py +++ b/packages/google-cloud-channel/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-chronicle/noxfile.py b/packages/google-cloud-chronicle/noxfile.py index f8d5376496e2..c4b902bf9cea 100644 --- a/packages/google-cloud-chronicle/noxfile.py +++ b/packages/google-cloud-chronicle/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-cloudcontrolspartner/noxfile.py b/packages/google-cloud-cloudcontrolspartner/noxfile.py index 1c7da30a1353..823ac102f951 100644 --- a/packages/google-cloud-cloudcontrolspartner/noxfile.py +++ b/packages/google-cloud-cloudcontrolspartner/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-cloudsecuritycompliance/noxfile.py b/packages/google-cloud-cloudsecuritycompliance/noxfile.py index a439a9c00767..d71fb1681f69 100644 --- a/packages/google-cloud-cloudsecuritycompliance/noxfile.py +++ b/packages/google-cloud-cloudsecuritycompliance/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-commerce-consumer-procurement/noxfile.py b/packages/google-cloud-commerce-consumer-procurement/noxfile.py index 311947f8107f..3f4e5b58d11e 100644 --- a/packages/google-cloud-commerce-consumer-procurement/noxfile.py +++ b/packages/google-cloud-commerce-consumer-procurement/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-common/noxfile.py b/packages/google-cloud-common/noxfile.py index ca4c9cba4b16..8517cce890b5 100644 --- a/packages/google-cloud-common/noxfile.py +++ b/packages/google-cloud-common/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-compute-v1beta/noxfile.py b/packages/google-cloud-compute-v1beta/noxfile.py index 0a039e1cbb33..7602aa435af2 100644 --- a/packages/google-cloud-compute-v1beta/noxfile.py +++ b/packages/google-cloud-compute-v1beta/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/client.py index 44d7a9d7ef1d..de282d391164 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/client.py @@ -107,78 +107,8 @@ class AcceleratorTypesClient(metaclass=AcceleratorTypesClientMeta): The AcceleratorTypes API. """ - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = AcceleratorTypesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = AcceleratorTypesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/client.py index c2205e17b4a4..f63466bebb84 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/client.py @@ -107,78 +107,8 @@ def get_transport_class( class AddressesClient(metaclass=AddressesClientMeta): """The Addresses API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = AddressesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = AddressesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/client.py index 362935f10dbb..bfb0336b17ff 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/client.py @@ -103,78 +103,8 @@ def get_transport_class( class AdviceClient(metaclass=AdviceClientMeta): """The Advice API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -366,49 +296,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = AdviceClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -442,30 +330,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = AdviceClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/client.py index 22d5a049eb86..1c146245a8ef 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/client.py @@ -107,78 +107,8 @@ def get_transport_class( class AutoscalersClient(metaclass=AutoscalersClientMeta): """The Autoscalers API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = AutoscalersClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = AutoscalersClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/client.py index f77441762c9d..cbb9d3cbca3e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/client.py @@ -107,78 +107,8 @@ def get_transport_class( class BackendBucketsClient(metaclass=BackendBucketsClientMeta): """The BackendBuckets API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = BackendBucketsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = BackendBucketsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/client.py index 8ad2520d3988..aea425ebffe7 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/client.py @@ -107,78 +107,8 @@ def get_transport_class( class BackendServicesClient(metaclass=BackendServicesClientMeta): """The BackendServices API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = BackendServicesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = BackendServicesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/client.py index f0fb6b654b69..00c37a250bed 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/client.py @@ -107,78 +107,8 @@ def get_transport_class( class CrossSiteNetworksClient(metaclass=CrossSiteNetworksClientMeta): """The CrossSiteNetworks API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = CrossSiteNetworksClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = CrossSiteNetworksClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/client.py index 40b595d9c103..ae9d9ea41fde 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/client.py @@ -104,78 +104,8 @@ def get_transport_class( class DiskTypesClient(metaclass=DiskTypesClientMeta): """The DiskTypes API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -367,49 +297,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = DiskTypesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -443,30 +331,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = DiskTypesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/client.py index 88dfa387504d..57ed7f860e4a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/client.py @@ -107,78 +107,8 @@ def get_transport_class( class DisksClient(metaclass=DisksClientMeta): """The Disks API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = DisksClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = DisksClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/client.py index 8779b0133c7e..5c867a544138 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/client.py @@ -107,78 +107,8 @@ def get_transport_class( class ExternalVpnGatewaysClient(metaclass=ExternalVpnGatewaysClientMeta): """The ExternalVpnGateways API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = ExternalVpnGatewaysClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = ExternalVpnGatewaysClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/client.py index 28ca5cbc2c25..08277e8c49bd 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/client.py @@ -107,78 +107,8 @@ def get_transport_class( class FirewallPoliciesClient(metaclass=FirewallPoliciesClientMeta): """The FirewallPolicies API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = FirewallPoliciesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = FirewallPoliciesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/client.py index a504fd9de6d4..089050d5171d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/client.py @@ -107,78 +107,8 @@ def get_transport_class( class FirewallsClient(metaclass=FirewallsClientMeta): """The Firewalls API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = FirewallsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = FirewallsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/client.py index 191c56a8e24f..75550b11f653 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/client.py @@ -107,78 +107,8 @@ def get_transport_class( class ForwardingRulesClient(metaclass=ForwardingRulesClientMeta): """The ForwardingRules API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = ForwardingRulesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = ForwardingRulesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/client.py index c9738a8588da..a4f7f35aae8f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/client.py @@ -107,78 +107,8 @@ def get_transport_class( class FutureReservationsClient(metaclass=FutureReservationsClientMeta): """The FutureReservations API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = FutureReservationsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = FutureReservationsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/client.py index bef4af1a0780..61e6de20074d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/client.py @@ -107,78 +107,8 @@ def get_transport_class( class GlobalAddressesClient(metaclass=GlobalAddressesClientMeta): """The GlobalAddresses API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = GlobalAddressesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = GlobalAddressesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/client.py index 05a682d32237..a216c257aa16 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/client.py @@ -107,78 +107,8 @@ def get_transport_class( class GlobalForwardingRulesClient(metaclass=GlobalForwardingRulesClientMeta): """The GlobalForwardingRules API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = GlobalForwardingRulesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -448,30 +336,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = GlobalForwardingRulesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/client.py index 13eb13fe3642..2994165c6d6b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/client.py @@ -109,78 +109,8 @@ class GlobalNetworkEndpointGroupsClient( ): """The GlobalNetworkEndpointGroups API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -372,49 +302,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = GlobalNetworkEndpointGroupsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -450,30 +338,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = GlobalNetworkEndpointGroupsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/client.py index 1495a1973ec7..4fe922a30611 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/client.py @@ -104,78 +104,8 @@ def get_transport_class( class GlobalOperationsClient(metaclass=GlobalOperationsClientMeta): """The GlobalOperations API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -367,49 +297,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = GlobalOperationsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -443,30 +331,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = GlobalOperationsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/client.py index 2cc2dd94b5dd..6feb23d9ca5a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/client.py @@ -106,78 +106,8 @@ class GlobalOrganizationOperationsClient( ): """The GlobalOrganizationOperations API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -371,51 +301,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = ( - GlobalOrganizationOperationsClient._use_client_cert_effective() - ) - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -451,30 +337,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = GlobalOrganizationOperationsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/client.py index 05f643df0598..435d7468fb06 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/client.py @@ -109,78 +109,8 @@ class GlobalPublicDelegatedPrefixesClient( ): """The GlobalPublicDelegatedPrefixes API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -374,51 +304,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = ( - GlobalPublicDelegatedPrefixesClient._use_client_cert_effective() - ) - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -454,30 +340,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = GlobalPublicDelegatedPrefixesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_vm_extension_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_vm_extension_policies/client.py index b4bac1c56dae..838c17fb5f90 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_vm_extension_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_vm_extension_policies/client.py @@ -107,78 +107,8 @@ def get_transport_class( class GlobalVmExtensionPoliciesClient(metaclass=GlobalVmExtensionPoliciesClientMeta): """The GlobalVmExtensionPolicies API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = GlobalVmExtensionPoliciesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -448,30 +336,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = GlobalVmExtensionPoliciesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/client.py index 035ddc12cc0f..4a7f6660bdf5 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/client.py @@ -107,78 +107,8 @@ def get_transport_class( class HealthChecksClient(metaclass=HealthChecksClientMeta): """The HealthChecks API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = HealthChecksClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = HealthChecksClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/client.py index 55a26f2289e5..b749d6d2034d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/client.py @@ -103,78 +103,8 @@ def get_transport_class( class ImageFamilyViewsClient(metaclass=ImageFamilyViewsClientMeta): """The ImageFamilyViews API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -366,49 +296,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = ImageFamilyViewsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -442,30 +330,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = ImageFamilyViewsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/images/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/images/client.py index 224756e906fa..eb087574a470 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/images/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/images/client.py @@ -107,78 +107,8 @@ def get_transport_class( class ImagesClient(metaclass=ImagesClientMeta): """The Images API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = ImagesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = ImagesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/client.py index 09e63bf97f81..41f3662016bc 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/client.py @@ -114,78 +114,8 @@ class InstanceGroupManagerResizeRequestsClient( ): """The InstanceGroupManagerResizeRequests API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -379,51 +309,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = ( - InstanceGroupManagerResizeRequestsClient._use_client_cert_effective() - ) - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -461,30 +347,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = InstanceGroupManagerResizeRequestsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/client.py index 984a885e6143..91bf52b5c7c4 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/client.py @@ -107,78 +107,8 @@ def get_transport_class( class InstanceGroupManagersClient(metaclass=InstanceGroupManagersClientMeta): """The InstanceGroupManagers API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = InstanceGroupManagersClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -448,30 +336,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = InstanceGroupManagersClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/client.py index cf8c6312e63c..90bce83ed152 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/client.py @@ -107,78 +107,8 @@ def get_transport_class( class InstanceGroupsClient(metaclass=InstanceGroupsClientMeta): """The InstanceGroups API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = InstanceGroupsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = InstanceGroupsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/client.py index 70b7a11df834..62dd8e1b533e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/client.py @@ -106,78 +106,8 @@ def get_transport_class( class InstanceSettingsServiceClient(metaclass=InstanceSettingsServiceClientMeta): """The InstanceSettings API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -369,49 +299,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = InstanceSettingsServiceClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -447,30 +335,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = InstanceSettingsServiceClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/client.py index a662cf02bc60..4924539ca9c5 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/client.py @@ -107,78 +107,8 @@ def get_transport_class( class InstanceTemplatesClient(metaclass=InstanceTemplatesClientMeta): """The InstanceTemplates API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = InstanceTemplatesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = InstanceTemplatesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/client.py index 25e8fda72057..5f9d854e0d3d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/client.py @@ -107,78 +107,8 @@ def get_transport_class( class InstancesClient(metaclass=InstancesClientMeta): """The Instances API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = InstancesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = InstancesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshot_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshot_groups/client.py index 7ba6f51fcc6f..3aaa9b0b3c2b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshot_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshot_groups/client.py @@ -107,78 +107,8 @@ def get_transport_class( class InstantSnapshotGroupsClient(metaclass=InstantSnapshotGroupsClientMeta): """The InstantSnapshotGroups API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = InstantSnapshotGroupsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -448,30 +336,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = InstantSnapshotGroupsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/client.py index 8a34b18a09c0..b908265225b8 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/client.py @@ -107,78 +107,8 @@ def get_transport_class( class InstantSnapshotsClient(metaclass=InstantSnapshotsClientMeta): """The InstantSnapshots API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = InstantSnapshotsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = InstantSnapshotsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/client.py index ad86663097b0..7fa889126dd0 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/client.py @@ -109,78 +109,8 @@ class InterconnectAttachmentGroupsClient( ): """The InterconnectAttachmentGroups API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -374,51 +304,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = ( - InterconnectAttachmentGroupsClient._use_client_cert_effective() - ) - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -454,30 +340,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = InterconnectAttachmentGroupsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/client.py index 6cacb5b66bf4..e59d156bee73 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/client.py @@ -107,78 +107,8 @@ def get_transport_class( class InterconnectAttachmentsClient(metaclass=InterconnectAttachmentsClientMeta): """The InterconnectAttachments API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = InterconnectAttachmentsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -448,30 +336,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = InterconnectAttachmentsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/client.py index 908821897454..144fa89a3934 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/client.py @@ -107,78 +107,8 @@ def get_transport_class( class InterconnectGroupsClient(metaclass=InterconnectGroupsClientMeta): """The InterconnectGroups API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = InterconnectGroupsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = InterconnectGroupsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/client.py index 214d6fd34d8e..44f162081bf8 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/client.py @@ -104,78 +104,8 @@ def get_transport_class( class InterconnectLocationsClient(metaclass=InterconnectLocationsClientMeta): """The InterconnectLocations API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -367,49 +297,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = InterconnectLocationsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -445,30 +333,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = InterconnectLocationsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/client.py index 66d931f67567..70ec0ee69b38 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/client.py @@ -106,78 +106,8 @@ class InterconnectRemoteLocationsClient( ): """The InterconnectRemoteLocations API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -369,49 +299,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = InterconnectRemoteLocationsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -447,30 +335,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = InterconnectRemoteLocationsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/client.py index ee7000b18d2a..0584208d5f29 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/client.py @@ -107,78 +107,8 @@ def get_transport_class( class InterconnectsClient(metaclass=InterconnectsClientMeta): """The Interconnects API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = InterconnectsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = InterconnectsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/client.py index 67cd416e8e1e..3f78ac08a7b3 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/client.py @@ -103,78 +103,8 @@ def get_transport_class( class LicenseCodesClient(metaclass=LicenseCodesClientMeta): """The LicenseCodes API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -366,49 +296,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = LicenseCodesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -442,30 +330,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = LicenseCodesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/client.py index 7d718709a172..342cce87e008 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/client.py @@ -107,78 +107,8 @@ def get_transport_class( class LicensesClient(metaclass=LicensesClientMeta): """The Licenses API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = LicensesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = LicensesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/client.py index c00d8dc1a60f..47e59d421e33 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/client.py @@ -107,78 +107,8 @@ def get_transport_class( class MachineImagesClient(metaclass=MachineImagesClientMeta): """The MachineImages API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = MachineImagesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = MachineImagesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/client.py index 763b20934de6..307844dd9add 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/client.py @@ -104,78 +104,8 @@ def get_transport_class( class MachineTypesClient(metaclass=MachineTypesClientMeta): """The MachineTypes API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -367,49 +297,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = MachineTypesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -443,30 +331,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = MachineTypesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/client.py index c3b6d5fc4bec..e3247a1837e8 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/client.py @@ -107,78 +107,8 @@ def get_transport_class( class NetworkAttachmentsClient(metaclass=NetworkAttachmentsClientMeta): """The NetworkAttachments API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = NetworkAttachmentsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = NetworkAttachmentsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/client.py index cf1a12c441c8..595a38b2f3e0 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/client.py @@ -109,78 +109,8 @@ class NetworkEdgeSecurityServicesClient( ): """The NetworkEdgeSecurityServices API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -372,49 +302,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = NetworkEdgeSecurityServicesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -450,30 +338,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = NetworkEdgeSecurityServicesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/client.py index d03482cfc732..de63d38c5ef8 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/client.py @@ -107,78 +107,8 @@ def get_transport_class( class NetworkEndpointGroupsClient(metaclass=NetworkEndpointGroupsClientMeta): """The NetworkEndpointGroups API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = NetworkEndpointGroupsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -448,30 +336,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = NetworkEndpointGroupsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/client.py index 93a0598a86fd..2e73b4cd3caf 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/client.py @@ -107,78 +107,8 @@ def get_transport_class( class NetworkFirewallPoliciesClient(metaclass=NetworkFirewallPoliciesClientMeta): """The NetworkFirewallPolicies API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = NetworkFirewallPoliciesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -448,30 +336,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = NetworkFirewallPoliciesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/client.py index c5f486efb164..0055c3071fac 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/client.py @@ -104,78 +104,8 @@ def get_transport_class( class NetworkProfilesClient(metaclass=NetworkProfilesClientMeta): """The NetworkProfiles API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -367,49 +297,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = NetworkProfilesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -443,30 +331,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = NetworkProfilesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/client.py index 15b52bdccb6b..21ebb63c13f8 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/client.py @@ -107,78 +107,8 @@ def get_transport_class( class NetworksClient(metaclass=NetworksClientMeta): """The Networks API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = NetworksClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = NetworksClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/client.py index 8d21617b2fa7..3df13a930679 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/client.py @@ -107,78 +107,8 @@ def get_transport_class( class NodeGroupsClient(metaclass=NodeGroupsClientMeta): """The NodeGroups API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = NodeGroupsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = NodeGroupsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/client.py index 3824a5dfe720..0d5d43d4016c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/client.py @@ -107,78 +107,8 @@ def get_transport_class( class NodeTemplatesClient(metaclass=NodeTemplatesClientMeta): """The NodeTemplates API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = NodeTemplatesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = NodeTemplatesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/client.py index 1622a2531c09..4ea9c92f745f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/client.py @@ -104,78 +104,8 @@ def get_transport_class( class NodeTypesClient(metaclass=NodeTypesClientMeta): """The NodeTypes API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -367,49 +297,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = NodeTypesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -443,30 +331,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = NodeTypesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/client.py index dab7672d8efa..190a08f76b70 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/client.py @@ -109,78 +109,8 @@ class OrganizationSecurityPoliciesClient( ): """The OrganizationSecurityPolicies API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -374,51 +304,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = ( - OrganizationSecurityPoliciesClient._use_client_cert_effective() - ) - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -454,30 +340,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = OrganizationSecurityPoliciesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/client.py index f4e40d33e4b0..1e57d2b66e61 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/client.py @@ -107,78 +107,8 @@ def get_transport_class( class PacketMirroringsClient(metaclass=PacketMirroringsClientMeta): """The PacketMirrorings API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = PacketMirroringsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = PacketMirroringsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/client.py index c9ac5da49ac1..f5119d67a5d9 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/client.py @@ -107,78 +107,8 @@ def get_transport_class( class PreviewFeaturesClient(metaclass=PreviewFeaturesClientMeta): """The PreviewFeatures API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = PreviewFeaturesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = PreviewFeaturesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/client.py index af82bc995a08..2ca4c071a039 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/client.py @@ -107,78 +107,8 @@ def get_transport_class( class ProjectsClient(metaclass=ProjectsClientMeta): """The Projects API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = ProjectsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = ProjectsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/client.py index dc863baa2019..99702a6ace2d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/client.py @@ -107,78 +107,8 @@ def get_transport_class( class PublicAdvertisedPrefixesClient(metaclass=PublicAdvertisedPrefixesClientMeta): """The PublicAdvertisedPrefixes API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = PublicAdvertisedPrefixesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -448,30 +336,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = PublicAdvertisedPrefixesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/client.py index e01d7a2e5bfe..07d54e19ee87 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/client.py @@ -107,78 +107,8 @@ def get_transport_class( class PublicDelegatedPrefixesClient(metaclass=PublicDelegatedPrefixesClientMeta): """The PublicDelegatedPrefixes API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = PublicDelegatedPrefixesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -448,30 +336,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = PublicDelegatedPrefixesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/client.py index a56846e1bada..d82be9744812 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RegionAutoscalersClient(metaclass=RegionAutoscalersClientMeta): """The RegionAutoscalers API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionAutoscalersClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionAutoscalersClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_buckets/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_buckets/client.py index 8f4a7b95cf7f..fe13e0837c54 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_buckets/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_buckets/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RegionBackendBucketsClient(metaclass=RegionBackendBucketsClientMeta): """The RegionBackendBuckets API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionBackendBucketsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionBackendBucketsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/client.py index e2f5d0b49d89..bf2372d12c7e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RegionBackendServicesClient(metaclass=RegionBackendServicesClientMeta): """The RegionBackendServices API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionBackendServicesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -448,30 +336,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionBackendServicesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/client.py index e39283a4fb3f..955b60de7713 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RegionCommitmentsClient(metaclass=RegionCommitmentsClientMeta): """The RegionCommitments API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionCommitmentsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionCommitmentsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/client.py index 9148571a7612..6a240d6a02b1 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/client.py @@ -109,78 +109,8 @@ class RegionCompositeHealthChecksClient( ): """The RegionCompositeHealthChecks API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -372,49 +302,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionCompositeHealthChecksClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -450,30 +338,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionCompositeHealthChecksClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/client.py index d478fea5679c..36b920f16971 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/client.py @@ -104,78 +104,8 @@ def get_transport_class( class RegionDiskTypesClient(metaclass=RegionDiskTypesClientMeta): """The RegionDiskTypes API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -367,49 +297,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionDiskTypesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -443,30 +331,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionDiskTypesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/client.py index d6a9c3cc5583..2f9b7f2b48fa 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RegionDisksClient(metaclass=RegionDisksClientMeta): """The RegionDisks API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionDisksClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionDisksClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/client.py index e1601d8a9b0f..c5dc3cddbc05 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/client.py @@ -112,78 +112,8 @@ class RegionHealthAggregationPoliciesClient( ): """The RegionHealthAggregationPolicies API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -377,51 +307,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = ( - RegionHealthAggregationPoliciesClient._use_client_cert_effective() - ) - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -457,30 +343,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionHealthAggregationPoliciesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/client.py index 112f8697ddea..4cc3a17013db 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RegionHealthCheckServicesClient(metaclass=RegionHealthCheckServicesClientMeta): """The RegionHealthCheckServices API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionHealthCheckServicesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -448,30 +336,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionHealthCheckServicesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/client.py index acf8ef76f413..6b4840f6c126 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RegionHealthChecksClient(metaclass=RegionHealthChecksClientMeta): """The RegionHealthChecks API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionHealthChecksClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionHealthChecksClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/client.py index 6b874fce30f9..fb725ba0a129 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RegionHealthSourcesClient(metaclass=RegionHealthSourcesClientMeta): """The RegionHealthSources API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionHealthSourcesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionHealthSourcesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_manager_resize_requests/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_manager_resize_requests/client.py index eb4d0f17f02b..e2ff13fef695 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_manager_resize_requests/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_manager_resize_requests/client.py @@ -114,78 +114,8 @@ class RegionInstanceGroupManagerResizeRequestsClient( ): """The RegionInstanceGroupManagerResizeRequests API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -379,51 +309,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = ( - RegionInstanceGroupManagerResizeRequestsClient._use_client_cert_effective() - ) - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -461,32 +347,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = ( - RegionInstanceGroupManagerResizeRequestsClient._DEFAULT_UNIVERSE - ) - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/client.py index 0ecb27fb666f..f822baf6a095 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/client.py @@ -109,78 +109,8 @@ class RegionInstanceGroupManagersClient( ): """The RegionInstanceGroupManagers API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -372,49 +302,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionInstanceGroupManagersClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -450,30 +338,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionInstanceGroupManagersClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/client.py index 244c3a2212c0..21d9dddc9e5c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RegionInstanceGroupsClient(metaclass=RegionInstanceGroupsClientMeta): """The RegionInstanceGroups API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionInstanceGroupsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionInstanceGroupsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/client.py index 4450773a6420..84a4f0befe11 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RegionInstanceTemplatesClient(metaclass=RegionInstanceTemplatesClientMeta): """The RegionInstanceTemplates API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionInstanceTemplatesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -448,30 +336,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionInstanceTemplatesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/client.py index 758b30a31767..c07f53dfa603 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/client.py @@ -106,78 +106,8 @@ def get_transport_class( class RegionInstancesClient(metaclass=RegionInstancesClientMeta): """The RegionInstances API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -369,49 +299,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionInstancesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -445,30 +333,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionInstancesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshot_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshot_groups/client.py index f534ec040185..fe57fadd78bd 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshot_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshot_groups/client.py @@ -109,78 +109,8 @@ class RegionInstantSnapshotGroupsClient( ): """The RegionInstantSnapshotGroups API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -372,49 +302,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionInstantSnapshotGroupsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -450,30 +338,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionInstantSnapshotGroupsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/client.py index 1810085dd55d..843b0909d24c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RegionInstantSnapshotsClient(metaclass=RegionInstantSnapshotsClientMeta): """The RegionInstantSnapshots API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionInstantSnapshotsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -448,30 +336,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionInstantSnapshotsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/client.py index 043345f354bb..fcfa52d58816 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/client.py @@ -109,78 +109,8 @@ class RegionNetworkEndpointGroupsClient( ): """The RegionNetworkEndpointGroups API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -372,49 +302,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionNetworkEndpointGroupsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -450,30 +338,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionNetworkEndpointGroupsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/client.py index 3fc654b6be93..73822ffa291a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/client.py @@ -109,78 +109,8 @@ class RegionNetworkFirewallPoliciesClient( ): """The RegionNetworkFirewallPolicies API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -374,51 +304,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = ( - RegionNetworkFirewallPoliciesClient._use_client_cert_effective() - ) - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -454,30 +340,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionNetworkFirewallPoliciesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/client.py index d60fd6d160b3..bb7dd0562992 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/client.py @@ -109,78 +109,8 @@ class RegionNotificationEndpointsClient( ): """The RegionNotificationEndpoints API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -372,49 +302,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionNotificationEndpointsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -450,30 +338,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionNotificationEndpointsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/client.py index 8fb2ae187242..c15c7f53e5b6 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/client.py @@ -104,78 +104,8 @@ def get_transport_class( class RegionOperationsClient(metaclass=RegionOperationsClientMeta): """The RegionOperations API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -367,49 +297,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionOperationsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -443,30 +331,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionOperationsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/client.py index c5ee12d04b1c..88968c11e6bb 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RegionSecurityPoliciesClient(metaclass=RegionSecurityPoliciesClientMeta): """The RegionSecurityPolicies API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionSecurityPoliciesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -448,30 +336,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionSecurityPoliciesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_snapshot_settings/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_snapshot_settings/client.py index ec5939ad0068..aec3d6c3d8e7 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_snapshot_settings/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_snapshot_settings/client.py @@ -106,78 +106,8 @@ def get_transport_class( class RegionSnapshotSettingsClient(metaclass=RegionSnapshotSettingsClientMeta): """The RegionSnapshotSettings API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -369,49 +299,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionSnapshotSettingsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -447,30 +335,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionSnapshotSettingsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_snapshots/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_snapshots/client.py index 904d29795338..7b9e559bf031 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_snapshots/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_snapshots/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RegionSnapshotsClient(metaclass=RegionSnapshotsClientMeta): """The RegionSnapshots API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionSnapshotsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionSnapshotsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/client.py index 405e0b493a2e..cddecab6cfee 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RegionSslCertificatesClient(metaclass=RegionSslCertificatesClientMeta): """The RegionSslCertificates API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionSslCertificatesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -448,30 +336,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionSslCertificatesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/client.py index e3b4f9585ffd..6fb1328e0e81 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RegionSslPoliciesClient(metaclass=RegionSslPoliciesClientMeta): """The RegionSslPolicies API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionSslPoliciesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionSslPoliciesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/client.py index 918adffd3077..58958c7e1a45 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RegionTargetHttpProxiesClient(metaclass=RegionTargetHttpProxiesClientMeta): """The RegionTargetHttpProxies API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionTargetHttpProxiesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -448,30 +336,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionTargetHttpProxiesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/client.py index f718e2cb9640..8f978639a584 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RegionTargetHttpsProxiesClient(metaclass=RegionTargetHttpsProxiesClientMeta): """The RegionTargetHttpsProxies API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionTargetHttpsProxiesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -448,30 +336,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionTargetHttpsProxiesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/client.py index eb357c5b31e0..58e0297b298a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RegionTargetTcpProxiesClient(metaclass=RegionTargetTcpProxiesClientMeta): """The RegionTargetTcpProxies API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionTargetTcpProxiesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -448,30 +336,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionTargetTcpProxiesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/client.py index d4ffcd7e4019..256e8c6d900e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RegionUrlMapsClient(metaclass=RegionUrlMapsClientMeta): """The RegionUrlMaps API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionUrlMapsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionUrlMapsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/client.py index cd8a556a4cac..1ca4f3574819 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/client.py @@ -104,78 +104,8 @@ def get_transport_class( class RegionZonesClient(metaclass=RegionZonesClientMeta): """The RegionZones API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -367,49 +297,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionZonesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -443,30 +331,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionZonesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/client.py index 9ff2a52f56d2..40c9fcfd028a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/client.py @@ -104,78 +104,8 @@ def get_transport_class( class RegionsClient(metaclass=RegionsClientMeta): """The Regions API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -367,49 +297,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RegionsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -443,30 +331,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RegionsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/client.py index 4443b29b4868..372e1d92c6cd 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/client.py @@ -107,78 +107,8 @@ def get_transport_class( class ReservationBlocksClient(metaclass=ReservationBlocksClientMeta): """The ReservationBlocks API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = ReservationBlocksClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = ReservationBlocksClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/client.py index ed4aeef3137c..fa15d4951b06 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/client.py @@ -107,78 +107,8 @@ def get_transport_class( class ReservationSlotsClient(metaclass=ReservationSlotsClientMeta): """The ReservationSlots API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = ReservationSlotsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = ReservationSlotsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/client.py index 71235e7aaf8d..b1c1c7bdce7e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/client.py @@ -107,78 +107,8 @@ def get_transport_class( class ReservationSubBlocksClient(metaclass=ReservationSubBlocksClientMeta): """The ReservationSubBlocks API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = ReservationSubBlocksClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = ReservationSubBlocksClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/client.py index 5eca38d9041b..f785c54f58e1 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/client.py @@ -107,78 +107,8 @@ def get_transport_class( class ReservationsClient(metaclass=ReservationsClientMeta): """The Reservations API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = ReservationsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = ReservationsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/client.py index d301e4191043..fb65749acaf2 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/client.py @@ -107,78 +107,8 @@ def get_transport_class( class ResourcePoliciesClient(metaclass=ResourcePoliciesClientMeta): """The ResourcePolicies API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = ResourcePoliciesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = ResourcePoliciesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/rollout_plans/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/rollout_plans/client.py index 667081b9fe48..2d19e45accdc 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/rollout_plans/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/rollout_plans/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RolloutPlansClient(metaclass=RolloutPlansClientMeta): """The RolloutPlans API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RolloutPlansClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RolloutPlansClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/rollouts/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/rollouts/client.py index 9a658ef00897..04fc47b4b6dc 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/rollouts/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/rollouts/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RolloutsClient(metaclass=RolloutsClientMeta): """The Rollouts API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RolloutsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RolloutsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/client.py index 06fd0231ba58..7ff84c19bd1d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RoutersClient(metaclass=RoutersClientMeta): """The Routers API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RoutersClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RoutersClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/client.py index e9c310cb627c..5fbacddc572e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/client.py @@ -107,78 +107,8 @@ def get_transport_class( class RoutesClient(metaclass=RoutesClientMeta): """The Routes API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = RoutesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = RoutesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/client.py index e083e35b1f7c..c673eebbf009 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/client.py @@ -107,78 +107,8 @@ def get_transport_class( class SecurityPoliciesClient(metaclass=SecurityPoliciesClientMeta): """The SecurityPolicies API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = SecurityPoliciesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = SecurityPoliciesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/client.py index efcc99655a52..d289dc574e31 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/client.py @@ -107,78 +107,8 @@ def get_transport_class( class ServiceAttachmentsClient(metaclass=ServiceAttachmentsClientMeta): """The ServiceAttachments API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = ServiceAttachmentsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = ServiceAttachmentsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/client.py index 7472a95de42a..5fde3df693ad 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/client.py @@ -106,78 +106,8 @@ def get_transport_class( class SnapshotSettingsServiceClient(metaclass=SnapshotSettingsServiceClientMeta): """The SnapshotSettings API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -369,49 +299,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = SnapshotSettingsServiceClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -447,30 +335,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = SnapshotSettingsServiceClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/client.py index 21070513325e..206d0f369ee9 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/client.py @@ -107,78 +107,8 @@ def get_transport_class( class SnapshotsClient(metaclass=SnapshotsClientMeta): """The Snapshots API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = SnapshotsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = SnapshotsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/client.py index 02d717c62ea0..c4b13e19b33e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/client.py @@ -107,78 +107,8 @@ def get_transport_class( class SslCertificatesClient(metaclass=SslCertificatesClientMeta): """The SslCertificates API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = SslCertificatesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = SslCertificatesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/client.py index 3351a5900346..6229ff620afb 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/client.py @@ -107,78 +107,8 @@ def get_transport_class( class SslPoliciesClient(metaclass=SslPoliciesClientMeta): """The SslPolicies API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = SslPoliciesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = SslPoliciesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/client.py index c453575db817..18f4940cd834 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/client.py @@ -104,78 +104,8 @@ def get_transport_class( class StoragePoolTypesClient(metaclass=StoragePoolTypesClientMeta): """The StoragePoolTypes API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -367,49 +297,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = StoragePoolTypesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -443,30 +331,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = StoragePoolTypesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/client.py index a9ce3ef27511..fd72f10ca2b5 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/client.py @@ -107,78 +107,8 @@ def get_transport_class( class StoragePoolsClient(metaclass=StoragePoolsClientMeta): """The StoragePools API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = StoragePoolsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = StoragePoolsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/client.py index 1f1bace31cb4..9df37d18a0af 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/client.py @@ -107,78 +107,8 @@ def get_transport_class( class SubnetworksClient(metaclass=SubnetworksClientMeta): """The Subnetworks API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = SubnetworksClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = SubnetworksClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/client.py index 39991f0f01b8..ac6b87decbfa 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/client.py @@ -107,78 +107,8 @@ def get_transport_class( class TargetGrpcProxiesClient(metaclass=TargetGrpcProxiesClientMeta): """The TargetGrpcProxies API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = TargetGrpcProxiesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = TargetGrpcProxiesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/client.py index 2db72e2bf617..c5daf132eb9e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/client.py @@ -107,78 +107,8 @@ def get_transport_class( class TargetHttpProxiesClient(metaclass=TargetHttpProxiesClientMeta): """The TargetHttpProxies API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = TargetHttpProxiesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = TargetHttpProxiesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/client.py index 44d807dd57f4..3769728f33d7 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/client.py @@ -107,78 +107,8 @@ def get_transport_class( class TargetHttpsProxiesClient(metaclass=TargetHttpsProxiesClientMeta): """The TargetHttpsProxies API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = TargetHttpsProxiesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = TargetHttpsProxiesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/client.py index 7e4992c4db64..461fd49b2fa7 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/client.py @@ -107,78 +107,8 @@ def get_transport_class( class TargetInstancesClient(metaclass=TargetInstancesClientMeta): """The TargetInstances API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = TargetInstancesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = TargetInstancesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/client.py index b86f70daaebf..e8ece6b7833f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/client.py @@ -107,78 +107,8 @@ def get_transport_class( class TargetPoolsClient(metaclass=TargetPoolsClientMeta): """The TargetPools API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = TargetPoolsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = TargetPoolsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/client.py index dce2bd2ea932..909ebd68c1bd 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/client.py @@ -107,78 +107,8 @@ def get_transport_class( class TargetSslProxiesClient(metaclass=TargetSslProxiesClientMeta): """The TargetSslProxies API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = TargetSslProxiesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = TargetSslProxiesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/client.py index 36fc4095cadd..128816725367 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/client.py @@ -107,78 +107,8 @@ def get_transport_class( class TargetTcpProxiesClient(metaclass=TargetTcpProxiesClientMeta): """The TargetTcpProxies API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = TargetTcpProxiesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = TargetTcpProxiesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/client.py index d51b03921809..0310b9670385 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/client.py @@ -107,78 +107,8 @@ def get_transport_class( class TargetVpnGatewaysClient(metaclass=TargetVpnGatewaysClientMeta): """The TargetVpnGateways API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = TargetVpnGatewaysClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = TargetVpnGatewaysClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/client.py index 1a9365973b0b..e51bae74af8c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/client.py @@ -107,78 +107,8 @@ def get_transport_class( class UrlMapsClient(metaclass=UrlMapsClientMeta): """The UrlMaps API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = UrlMapsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = UrlMapsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/client.py index a2db6bab6965..68b5a804bd58 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/client.py @@ -107,78 +107,8 @@ def get_transport_class( class VpnGatewaysClient(metaclass=VpnGatewaysClientMeta): """The VpnGateways API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = VpnGatewaysClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = VpnGatewaysClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/client.py index 097d83e6cb74..9cba502cf426 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/client.py @@ -107,78 +107,8 @@ def get_transport_class( class VpnTunnelsClient(metaclass=VpnTunnelsClientMeta): """The VpnTunnels API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = VpnTunnelsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = VpnTunnelsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/client.py index 9e9c7e69163e..3fad563c32f3 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/client.py @@ -107,78 +107,8 @@ def get_transport_class( class WireGroupsClient(metaclass=WireGroupsClientMeta): """The WireGroups API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = WireGroupsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -446,30 +334,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = WireGroupsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/client.py index 9e4a7ccb9366..8a723db7e9b1 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/client.py @@ -104,78 +104,8 @@ def get_transport_class( class ZoneOperationsClient(metaclass=ZoneOperationsClientMeta): """The ZoneOperations API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -367,49 +297,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = ZoneOperationsClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -443,30 +331,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = ZoneOperationsClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_vm_extension_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_vm_extension_policies/client.py index 1a944b412f85..79db386a784e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_vm_extension_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_vm_extension_policies/client.py @@ -107,78 +107,8 @@ def get_transport_class( class ZoneVmExtensionPoliciesClient(metaclass=ZoneVmExtensionPoliciesClientMeta): """The ZoneVmExtensionPolicies API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -370,49 +300,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = ZoneVmExtensionPoliciesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -448,30 +336,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = ZoneVmExtensionPoliciesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/client.py index ac6c2813e503..13fe6ddbbd38 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/client.py @@ -104,78 +104,8 @@ def get_transport_class( class ZonesClient(metaclass=ZonesClientMeta): """The Zones API.""" - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "compute.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -367,49 +297,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = ZonesClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -443,30 +331,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = ZonesClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/noxfile.py b/packages/google-cloud-compute/noxfile.py index 2e755609e4fb..a34bff72b302 100644 --- a/packages/google-cloud-compute/noxfile.py +++ b/packages/google-cloud-compute/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-confidentialcomputing/noxfile.py b/packages/google-cloud-confidentialcomputing/noxfile.py index 857dbbdaf8c7..0a858dc198e4 100644 --- a/packages/google-cloud-confidentialcomputing/noxfile.py +++ b/packages/google-cloud-confidentialcomputing/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-config/noxfile.py b/packages/google-cloud-config/noxfile.py index 961e33e80a07..9be1c6500862 100644 --- a/packages/google-cloud-config/noxfile.py +++ b/packages/google-cloud-config/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-configdelivery/noxfile.py b/packages/google-cloud-configdelivery/noxfile.py index 7ffc9ba9e754..55366c44f8f3 100644 --- a/packages/google-cloud-configdelivery/noxfile.py +++ b/packages/google-cloud-configdelivery/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-contact-center-insights/noxfile.py b/packages/google-cloud-contact-center-insights/noxfile.py index 07bfcb647ae4..324c08d9cc72 100644 --- a/packages/google-cloud-contact-center-insights/noxfile.py +++ b/packages/google-cloud-contact-center-insights/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-container/noxfile.py b/packages/google-cloud-container/noxfile.py index 6c2ecb978e67..9abb19cc3f2f 100644 --- a/packages/google-cloud-container/noxfile.py +++ b/packages/google-cloud-container/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-containeranalysis/noxfile.py b/packages/google-cloud-containeranalysis/noxfile.py index fc37a9820b48..9ee961b93a96 100644 --- a/packages/google-cloud-containeranalysis/noxfile.py +++ b/packages/google-cloud-containeranalysis/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-contentwarehouse/noxfile.py b/packages/google-cloud-contentwarehouse/noxfile.py index a666b63aad5a..4aaddfbb9659 100644 --- a/packages/google-cloud-contentwarehouse/noxfile.py +++ b/packages/google-cloud-contentwarehouse/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-core/noxfile.py b/packages/google-cloud-core/noxfile.py index cc39a19624af..41c3e2ac9868 100644 --- a/packages/google-cloud-core/noxfile.py +++ b/packages/google-cloud-core/noxfile.py @@ -431,20 +431,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-data-fusion/noxfile.py b/packages/google-cloud-data-fusion/noxfile.py index 0dad41a7f641..2de71a3ff640 100644 --- a/packages/google-cloud-data-fusion/noxfile.py +++ b/packages/google-cloud-data-fusion/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-data-qna/noxfile.py b/packages/google-cloud-data-qna/noxfile.py index fc8596401d90..0608153d39ba 100644 --- a/packages/google-cloud-data-qna/noxfile.py +++ b/packages/google-cloud-data-qna/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-databasecenter/noxfile.py b/packages/google-cloud-databasecenter/noxfile.py index dc8f40efc52f..fb31e9ea7c8e 100644 --- a/packages/google-cloud-databasecenter/noxfile.py +++ b/packages/google-cloud-databasecenter/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-datacatalog-lineage-configmanagement/noxfile.py b/packages/google-cloud-datacatalog-lineage-configmanagement/noxfile.py index 3c50903d597b..a41f1f4bd28f 100644 --- a/packages/google-cloud-datacatalog-lineage-configmanagement/noxfile.py +++ b/packages/google-cloud-datacatalog-lineage-configmanagement/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-datacatalog-lineage/noxfile.py b/packages/google-cloud-datacatalog-lineage/noxfile.py index 64fed32b57b5..e99cfb0f567f 100644 --- a/packages/google-cloud-datacatalog-lineage/noxfile.py +++ b/packages/google-cloud-datacatalog-lineage/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-datacatalog/noxfile.py b/packages/google-cloud-datacatalog/noxfile.py index 7c979390c252..388a72c307e5 100644 --- a/packages/google-cloud-datacatalog/noxfile.py +++ b/packages/google-cloud-datacatalog/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-dataflow-client/noxfile.py b/packages/google-cloud-dataflow-client/noxfile.py index 9377fab0c1fb..23c5987e6904 100644 --- a/packages/google-cloud-dataflow-client/noxfile.py +++ b/packages/google-cloud-dataflow-client/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-dataform/noxfile.py b/packages/google-cloud-dataform/noxfile.py index 036f66474d89..73cfdb4d3734 100644 --- a/packages/google-cloud-dataform/noxfile.py +++ b/packages/google-cloud-dataform/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-datalabeling/noxfile.py b/packages/google-cloud-datalabeling/noxfile.py index 5f1ae073db65..123efc75d4cd 100644 --- a/packages/google-cloud-datalabeling/noxfile.py +++ b/packages/google-cloud-datalabeling/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-dataplex/noxfile.py b/packages/google-cloud-dataplex/noxfile.py index 539e7a3189b9..717193edfc79 100644 --- a/packages/google-cloud-dataplex/noxfile.py +++ b/packages/google-cloud-dataplex/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-dataproc-metastore/noxfile.py b/packages/google-cloud-dataproc-metastore/noxfile.py index c09a283d9bbc..317c9cceebf8 100644 --- a/packages/google-cloud-dataproc-metastore/noxfile.py +++ b/packages/google-cloud-dataproc-metastore/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-dataproc/noxfile.py b/packages/google-cloud-dataproc/noxfile.py index 10f0f3d734cb..920964ff7f6b 100644 --- a/packages/google-cloud-dataproc/noxfile.py +++ b/packages/google-cloud-dataproc/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-datastore/noxfile.py b/packages/google-cloud-datastore/noxfile.py index d6dd338d95e6..97a1786db005 100644 --- a/packages/google-cloud-datastore/noxfile.py +++ b/packages/google-cloud-datastore/noxfile.py @@ -659,5 +659,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-datastream/noxfile.py b/packages/google-cloud-datastream/noxfile.py index 607a359737b9..9b0a13d1a10d 100644 --- a/packages/google-cloud-datastream/noxfile.py +++ b/packages/google-cloud-datastream/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-deploy/noxfile.py b/packages/google-cloud-deploy/noxfile.py index 70c612e6c140..12a4f078b9f1 100644 --- a/packages/google-cloud-deploy/noxfile.py +++ b/packages/google-cloud-deploy/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-developerconnect/noxfile.py b/packages/google-cloud-developerconnect/noxfile.py index 757e6ce4e7f4..250e5f250487 100644 --- a/packages/google-cloud-developerconnect/noxfile.py +++ b/packages/google-cloud-developerconnect/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-devicestreaming/noxfile.py b/packages/google-cloud-devicestreaming/noxfile.py index cef5cca1fe0c..3ce8b4976c07 100644 --- a/packages/google-cloud-devicestreaming/noxfile.py +++ b/packages/google-cloud-devicestreaming/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-dialogflow-cx/noxfile.py b/packages/google-cloud-dialogflow-cx/noxfile.py index 6ccf8c4cd0f0..eac420915b26 100644 --- a/packages/google-cloud-dialogflow-cx/noxfile.py +++ b/packages/google-cloud-dialogflow-cx/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-dialogflow/noxfile.py b/packages/google-cloud-dialogflow/noxfile.py index d87c461e88b7..1a4d1539850a 100644 --- a/packages/google-cloud-dialogflow/noxfile.py +++ b/packages/google-cloud-dialogflow/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-discoveryengine/noxfile.py b/packages/google-cloud-discoveryengine/noxfile.py index eedfeccd3b48..064112def637 100644 --- a/packages/google-cloud-discoveryengine/noxfile.py +++ b/packages/google-cloud-discoveryengine/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-dlp/noxfile.py b/packages/google-cloud-dlp/noxfile.py index cd569c4af767..0c3bb16e06d4 100644 --- a/packages/google-cloud-dlp/noxfile.py +++ b/packages/google-cloud-dlp/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-dms/noxfile.py b/packages/google-cloud-dms/noxfile.py index 2c90d3cf1e5f..a75ac008520f 100644 --- a/packages/google-cloud-dms/noxfile.py +++ b/packages/google-cloud-dms/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-dns/noxfile.py b/packages/google-cloud-dns/noxfile.py index 96b1a9b05830..7a856d15ac77 100644 --- a/packages/google-cloud-dns/noxfile.py +++ b/packages/google-cloud-dns/noxfile.py @@ -41,6 +41,7 @@ "3.12", "3.13", "3.14", + "import_profile", ] UNIT_TEST_STANDARD_DEPENDENCIES = [ "mock", @@ -526,20 +527,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-documentai-toolbox/noxfile.py b/packages/google-cloud-documentai-toolbox/noxfile.py index 68febcdb3ace..4e0a1ab5443e 100644 --- a/packages/google-cloud-documentai-toolbox/noxfile.py +++ b/packages/google-cloud-documentai-toolbox/noxfile.py @@ -41,6 +41,7 @@ "3.12", "3.13", "3.14", + "import_profile", ] UNIT_TEST_STANDARD_DEPENDENCIES = [ @@ -563,27 +564,7 @@ def import_profile(session): "python", str(profiler_script), "--module", - "google.cloud.documentai_toolbox", - "--iterations", - "10", - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google.cloud.documentai_toolbox", + "google", "--iterations", "10", ) diff --git a/packages/google-cloud-documentai/noxfile.py b/packages/google-cloud-documentai/noxfile.py index df8a45081779..1482ba225681 100644 --- a/packages/google-cloud-documentai/noxfile.py +++ b/packages/google-cloud-documentai/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-domains/noxfile.py b/packages/google-cloud-domains/noxfile.py index 8c04a20746f9..8c2b2f262014 100644 --- a/packages/google-cloud-domains/noxfile.py +++ b/packages/google-cloud-domains/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-edgecontainer/noxfile.py b/packages/google-cloud-edgecontainer/noxfile.py index 209ddddaa162..a870d0bdd0f8 100644 --- a/packages/google-cloud-edgecontainer/noxfile.py +++ b/packages/google-cloud-edgecontainer/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-edgenetwork/noxfile.py b/packages/google-cloud-edgenetwork/noxfile.py index 4087e574585f..08e5bd144b81 100644 --- a/packages/google-cloud-edgenetwork/noxfile.py +++ b/packages/google-cloud-edgenetwork/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-enterpriseknowledgegraph/noxfile.py b/packages/google-cloud-enterpriseknowledgegraph/noxfile.py index b9f88a3499f1..43a8c9de3937 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/noxfile.py +++ b/packages/google-cloud-enterpriseknowledgegraph/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-error-reporting/noxfile.py b/packages/google-cloud-error-reporting/noxfile.py index 6e934df196a2..cb593565bbf2 100644 --- a/packages/google-cloud-error-reporting/noxfile.py +++ b/packages/google-cloud-error-reporting/noxfile.py @@ -652,5 +652,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-essential-contacts/noxfile.py b/packages/google-cloud-essential-contacts/noxfile.py index bd500a6e85d8..7afcdfbfb9ae 100644 --- a/packages/google-cloud-essential-contacts/noxfile.py +++ b/packages/google-cloud-essential-contacts/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-eventarc-publishing/noxfile.py b/packages/google-cloud-eventarc-publishing/noxfile.py index 1b2798c5ec5a..6ba9a95492af 100644 --- a/packages/google-cloud-eventarc-publishing/noxfile.py +++ b/packages/google-cloud-eventarc-publishing/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-eventarc/noxfile.py b/packages/google-cloud-eventarc/noxfile.py index f4d33773050d..615a58b26ae5 100644 --- a/packages/google-cloud-eventarc/noxfile.py +++ b/packages/google-cloud-eventarc/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-filestore/noxfile.py b/packages/google-cloud-filestore/noxfile.py index 63bf6de0a2df..c685715579fc 100644 --- a/packages/google-cloud-filestore/noxfile.py +++ b/packages/google-cloud-filestore/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-financialservices/noxfile.py b/packages/google-cloud-financialservices/noxfile.py index 6b2dc7ec14d8..174df2b7a66f 100644 --- a/packages/google-cloud-financialservices/noxfile.py +++ b/packages/google-cloud-financialservices/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-firestore/noxfile.py b/packages/google-cloud-firestore/noxfile.py index 94d80f339f83..ced52e2d9e3d 100644 --- a/packages/google-cloud-firestore/noxfile.py +++ b/packages/google-cloud-firestore/noxfile.py @@ -714,5 +714,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-functions/noxfile.py b/packages/google-cloud-functions/noxfile.py index 8e0a43ece7b3..f85fcaa2f3f7 100644 --- a/packages/google-cloud-functions/noxfile.py +++ b/packages/google-cloud-functions/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-gdchardwaremanagement/noxfile.py b/packages/google-cloud-gdchardwaremanagement/noxfile.py index 2f3915756dff..ffa803877858 100644 --- a/packages/google-cloud-gdchardwaremanagement/noxfile.py +++ b/packages/google-cloud-gdchardwaremanagement/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-geminidataanalytics/noxfile.py b/packages/google-cloud-geminidataanalytics/noxfile.py index cb572aa26f4d..8a9253df0368 100644 --- a/packages/google-cloud-geminidataanalytics/noxfile.py +++ b/packages/google-cloud-geminidataanalytics/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-gke-backup/noxfile.py b/packages/google-cloud-gke-backup/noxfile.py index 6db9b35e0f94..42d083ca7f5b 100644 --- a/packages/google-cloud-gke-backup/noxfile.py +++ b/packages/google-cloud-gke-backup/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-gke-connect-gateway/noxfile.py b/packages/google-cloud-gke-connect-gateway/noxfile.py index 1229d9060642..99bf2a55e42c 100644 --- a/packages/google-cloud-gke-connect-gateway/noxfile.py +++ b/packages/google-cloud-gke-connect-gateway/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-gke-hub/noxfile.py b/packages/google-cloud-gke-hub/noxfile.py index a5cadae253e5..2d6c1ccb29bc 100644 --- a/packages/google-cloud-gke-hub/noxfile.py +++ b/packages/google-cloud-gke-hub/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-gke-multicloud/noxfile.py b/packages/google-cloud-gke-multicloud/noxfile.py index 1297a6009f33..576d7ced89e0 100644 --- a/packages/google-cloud-gke-multicloud/noxfile.py +++ b/packages/google-cloud-gke-multicloud/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-gkerecommender/noxfile.py b/packages/google-cloud-gkerecommender/noxfile.py index 80a8d33baa66..1939f5eb5402 100644 --- a/packages/google-cloud-gkerecommender/noxfile.py +++ b/packages/google-cloud-gkerecommender/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-gsuiteaddons/noxfile.py b/packages/google-cloud-gsuiteaddons/noxfile.py index f99a4a9a9cae..926f5f711930 100644 --- a/packages/google-cloud-gsuiteaddons/noxfile.py +++ b/packages/google-cloud-gsuiteaddons/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-hypercomputecluster/noxfile.py b/packages/google-cloud-hypercomputecluster/noxfile.py index 7f5528c7d680..76c72c4d5125 100644 --- a/packages/google-cloud-hypercomputecluster/noxfile.py +++ b/packages/google-cloud-hypercomputecluster/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-iam-logging/noxfile.py b/packages/google-cloud-iam-logging/noxfile.py index 0c6133eda26a..da1858259061 100644 --- a/packages/google-cloud-iam-logging/noxfile.py +++ b/packages/google-cloud-iam-logging/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-iam/noxfile.py b/packages/google-cloud-iam/noxfile.py index 689280cd44af..3846a48e0952 100644 --- a/packages/google-cloud-iam/noxfile.py +++ b/packages/google-cloud-iam/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-iamconnectorcredentials/noxfile.py b/packages/google-cloud-iamconnectorcredentials/noxfile.py index 26208f34cd20..467fabe2af8a 100644 --- a/packages/google-cloud-iamconnectorcredentials/noxfile.py +++ b/packages/google-cloud-iamconnectorcredentials/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-iap/noxfile.py b/packages/google-cloud-iap/noxfile.py index ad10713c6a4a..9a1173d90ce5 100644 --- a/packages/google-cloud-iap/noxfile.py +++ b/packages/google-cloud-iap/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-ids/noxfile.py b/packages/google-cloud-ids/noxfile.py index 72f73bc75a1e..31383bee1ff2 100644 --- a/packages/google-cloud-ids/noxfile.py +++ b/packages/google-cloud-ids/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-kms-inventory/noxfile.py b/packages/google-cloud-kms-inventory/noxfile.py index 4bd38375888c..1d993ca155af 100644 --- a/packages/google-cloud-kms-inventory/noxfile.py +++ b/packages/google-cloud-kms-inventory/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/client.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/client.py index fd5003ea45b9..ca66d3830f95 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/client.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/client.py @@ -136,78 +136,8 @@ class AutokeyClient(metaclass=AutokeyClientMeta): [ShowEffectiveAutokeyConfig][google.cloud.kms.v1.AutokeyAdmin.ShowEffectiveAutokeyConfig]. """ - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "cloudkms.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "cloudkms.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -445,49 +375,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = AutokeyClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -521,30 +409,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = AutokeyClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/client.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/client.py index 79cfb77e3d33..5e7bbe81fb59 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/client.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/client.py @@ -126,78 +126,8 @@ class AutokeyAdminClient(metaclass=AutokeyAdminClientMeta): delegated key management mode for same-project keys. """ - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "cloudkms.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "cloudkms.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -404,49 +334,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = AutokeyAdminClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -480,30 +368,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = AutokeyAdminClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/client.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/client.py index 9ab88628e743..372920b776a0 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/client.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/client.py @@ -123,78 +123,8 @@ class EkmServiceClient(metaclass=EkmServiceClientMeta): - [EkmConnection][google.cloud.kms.v1.EkmConnection] """ - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "cloudkms.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "cloudkms.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -451,49 +381,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = EkmServiceClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -527,30 +415,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = EkmServiceClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/client.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/client.py index 934b6a1bb710..8532a0a62209 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/client.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/client.py @@ -127,78 +127,8 @@ class HsmManagementClient(metaclass=HsmManagementClientMeta): - [SingleTenantHsmInstanceProposal][google.cloud.kms.v1.SingleTenantHsmInstanceProposal] """ - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "cloudkms.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "cloudkms.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -436,49 +366,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = HsmManagementClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -512,30 +400,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = HsmManagementClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/client.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/client.py index aff969e7a712..411283317f70 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/client.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/client.py @@ -134,78 +134,8 @@ class KeyManagementServiceClient(metaclass=KeyManagementServiceClientMeta): KMS `__. """ - @staticmethod - def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - Optional[str]: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - m = mtls_endpoint_re.match(api_endpoint) - if m is None: - # Could not parse api_endpoint; return as-is. - return api_endpoint - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "cloudkms.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "cloudkms.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @staticmethod - def _use_client_cert_effective(): - """Returns whether client certificate should be used for mTLS if the - google-auth version supports should_use_client_cert automatic mTLS enablement. - - Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. - - Returns: - bool: whether client certificate should be used for mTLS - Raises: - ValueError: (If using a version of google-auth without should_use_client_cert and - GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) - """ - # check if google-auth version supports should_use_client_cert for automatic mTLS enablement - if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER - return mtls.should_use_client_cert() - else: # pragma: NO COVER - # if unsupported, fallback to reading from env var - use_client_cert_str = os.getenv( - "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" - ).lower() - if use_client_cert_str not in ("true", "false"): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" - " either `true` or `false`" - ) - return use_client_cert_str == "true" - - @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -541,49 +471,7 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = KeyManagementServiceClient._use_client_cert_effective() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError( - "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - ) - return use_client_cert, use_mtls_endpoint, universe_domain_env - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -617,30 +505,6 @@ def _get_api_endpoint( ) return api_endpoint - @staticmethod - def _get_universe_domain( - client_universe_domain: Optional[str], universe_domain_env: Optional[str] - ) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = KeyManagementServiceClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-kms/noxfile.py b/packages/google-cloud-kms/noxfile.py index 0c9dddf6c10d..912e22a0a251 100644 --- a/packages/google-cloud-kms/noxfile.py +++ b/packages/google-cloud-kms/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-language/noxfile.py b/packages/google-cloud-language/noxfile.py index e5e9676293bb..5598c03a5b61 100644 --- a/packages/google-cloud-language/noxfile.py +++ b/packages/google-cloud-language/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-licensemanager/noxfile.py b/packages/google-cloud-licensemanager/noxfile.py index d0aaa7b35a9a..3271492f030a 100644 --- a/packages/google-cloud-licensemanager/noxfile.py +++ b/packages/google-cloud-licensemanager/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-life-sciences/noxfile.py b/packages/google-cloud-life-sciences/noxfile.py index 64bc3bee8615..ee09afa785c0 100644 --- a/packages/google-cloud-life-sciences/noxfile.py +++ b/packages/google-cloud-life-sciences/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-locationfinder/noxfile.py b/packages/google-cloud-locationfinder/noxfile.py index c0d2565e20ea..2c298dd18687 100644 --- a/packages/google-cloud-locationfinder/noxfile.py +++ b/packages/google-cloud-locationfinder/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-logging/noxfile.py b/packages/google-cloud-logging/noxfile.py index 0c08754e0e97..06304a8bd0ba 100644 --- a/packages/google-cloud-logging/noxfile.py +++ b/packages/google-cloud-logging/noxfile.py @@ -653,7 +653,7 @@ def import_profile(session): "python", str(profiler_script), "--module", - "unknown_module", + "google", "--iterations", "10", ) diff --git a/packages/google-cloud-lustre/noxfile.py b/packages/google-cloud-lustre/noxfile.py index fa43e4537b2d..fce678623521 100644 --- a/packages/google-cloud-lustre/noxfile.py +++ b/packages/google-cloud-lustre/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-maintenance-api/noxfile.py b/packages/google-cloud-maintenance-api/noxfile.py index 0cf163c4839b..38d16f765f24 100644 --- a/packages/google-cloud-maintenance-api/noxfile.py +++ b/packages/google-cloud-maintenance-api/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-managed-identities/noxfile.py b/packages/google-cloud-managed-identities/noxfile.py index 08c0726fe316..ccf750ada627 100644 --- a/packages/google-cloud-managed-identities/noxfile.py +++ b/packages/google-cloud-managed-identities/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-managedkafka-schemaregistry/noxfile.py b/packages/google-cloud-managedkafka-schemaregistry/noxfile.py index 4afb2c248c2d..84ed8c2c37c7 100644 --- a/packages/google-cloud-managedkafka-schemaregistry/noxfile.py +++ b/packages/google-cloud-managedkafka-schemaregistry/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-managedkafka/noxfile.py b/packages/google-cloud-managedkafka/noxfile.py index ee04bbbe4d8e..d9bf8c0a6822 100644 --- a/packages/google-cloud-managedkafka/noxfile.py +++ b/packages/google-cloud-managedkafka/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-media-translation/noxfile.py b/packages/google-cloud-media-translation/noxfile.py index 8aa2fe062c55..58f7d0022db2 100644 --- a/packages/google-cloud-media-translation/noxfile.py +++ b/packages/google-cloud-media-translation/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-memcache/noxfile.py b/packages/google-cloud-memcache/noxfile.py index 2c7e47a63175..59eb2eab215f 100644 --- a/packages/google-cloud-memcache/noxfile.py +++ b/packages/google-cloud-memcache/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-memorystore/noxfile.py b/packages/google-cloud-memorystore/noxfile.py index d1ff25e03612..83fecf90ab36 100644 --- a/packages/google-cloud-memorystore/noxfile.py +++ b/packages/google-cloud-memorystore/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-migrationcenter/noxfile.py b/packages/google-cloud-migrationcenter/noxfile.py index a03308fd442c..073597ee1690 100644 --- a/packages/google-cloud-migrationcenter/noxfile.py +++ b/packages/google-cloud-migrationcenter/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-modelarmor/noxfile.py b/packages/google-cloud-modelarmor/noxfile.py index 0c8e0f39a165..f655333ebdc5 100644 --- a/packages/google-cloud-modelarmor/noxfile.py +++ b/packages/google-cloud-modelarmor/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-monitoring-dashboards/noxfile.py b/packages/google-cloud-monitoring-dashboards/noxfile.py index 391420466ad8..95ca942edd0a 100644 --- a/packages/google-cloud-monitoring-dashboards/noxfile.py +++ b/packages/google-cloud-monitoring-dashboards/noxfile.py @@ -652,5 +652,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-monitoring-metrics-scopes/noxfile.py b/packages/google-cloud-monitoring-metrics-scopes/noxfile.py index 8940073ef574..ec1fb7ce1fa9 100644 --- a/packages/google-cloud-monitoring-metrics-scopes/noxfile.py +++ b/packages/google-cloud-monitoring-metrics-scopes/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-monitoring/noxfile.py b/packages/google-cloud-monitoring/noxfile.py index 69ad5d5e5565..699d24e42e85 100644 --- a/packages/google-cloud-monitoring/noxfile.py +++ b/packages/google-cloud-monitoring/noxfile.py @@ -653,5 +653,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-ndb/noxfile.py b/packages/google-cloud-ndb/noxfile.py index 3de992f08df2..df93c72a708b 100644 --- a/packages/google-cloud-ndb/noxfile.py +++ b/packages/google-cloud-ndb/noxfile.py @@ -42,6 +42,7 @@ "pytest-cov", "google-cloud-testutils", "google-cloud-core", + "import_profile", ] # Error if a python version is missing @@ -564,27 +565,7 @@ def import_profile(session): "python", str(profiler_script), "--module", - "google.cloud.ndb", - "--iterations", - "10", - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google.cloud.ndb", + "google", "--iterations", "10", ) diff --git a/packages/google-cloud-netapp/noxfile.py b/packages/google-cloud-netapp/noxfile.py index 97daa1939030..39a2b89172ad 100644 --- a/packages/google-cloud-netapp/noxfile.py +++ b/packages/google-cloud-netapp/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-network-connectivity/noxfile.py b/packages/google-cloud-network-connectivity/noxfile.py index 3f4c94d98da2..b04ae0d286d9 100644 --- a/packages/google-cloud-network-connectivity/noxfile.py +++ b/packages/google-cloud-network-connectivity/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-network-management/noxfile.py b/packages/google-cloud-network-management/noxfile.py index 8b9f2e7b7aac..e33d535129b7 100644 --- a/packages/google-cloud-network-management/noxfile.py +++ b/packages/google-cloud-network-management/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-network-security/noxfile.py b/packages/google-cloud-network-security/noxfile.py index d18ea7c84e3d..d524908a6539 100644 --- a/packages/google-cloud-network-security/noxfile.py +++ b/packages/google-cloud-network-security/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-network-services/noxfile.py b/packages/google-cloud-network-services/noxfile.py index 3b1028983087..b0c63c6a8e25 100644 --- a/packages/google-cloud-network-services/noxfile.py +++ b/packages/google-cloud-network-services/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-notebooks/noxfile.py b/packages/google-cloud-notebooks/noxfile.py index 1c56cc47dacb..cc50622d53f5 100644 --- a/packages/google-cloud-notebooks/noxfile.py +++ b/packages/google-cloud-notebooks/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-optimization/noxfile.py b/packages/google-cloud-optimization/noxfile.py index 602acfa99cb1..c6c3b1529d3f 100644 --- a/packages/google-cloud-optimization/noxfile.py +++ b/packages/google-cloud-optimization/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-oracledatabase/noxfile.py b/packages/google-cloud-oracledatabase/noxfile.py index cb674c6f1995..6e796e3b41da 100644 --- a/packages/google-cloud-oracledatabase/noxfile.py +++ b/packages/google-cloud-oracledatabase/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-orchestration-airflow/noxfile.py b/packages/google-cloud-orchestration-airflow/noxfile.py index d91ebf899bbd..6224c709b075 100644 --- a/packages/google-cloud-orchestration-airflow/noxfile.py +++ b/packages/google-cloud-orchestration-airflow/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-org-policy/noxfile.py b/packages/google-cloud-org-policy/noxfile.py index 56e6e0409c0a..8471e50c6acd 100644 --- a/packages/google-cloud-org-policy/noxfile.py +++ b/packages/google-cloud-org-policy/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-os-config/noxfile.py b/packages/google-cloud-os-config/noxfile.py index 12f7efefd632..d5f09f26bb2b 100644 --- a/packages/google-cloud-os-config/noxfile.py +++ b/packages/google-cloud-os-config/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-os-login/noxfile.py b/packages/google-cloud-os-login/noxfile.py index 18134febd9b3..9e2105ef776c 100644 --- a/packages/google-cloud-os-login/noxfile.py +++ b/packages/google-cloud-os-login/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-parallelstore/noxfile.py b/packages/google-cloud-parallelstore/noxfile.py index a78d2472952e..9f8fd7bceabf 100644 --- a/packages/google-cloud-parallelstore/noxfile.py +++ b/packages/google-cloud-parallelstore/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-parametermanager/noxfile.py b/packages/google-cloud-parametermanager/noxfile.py index afc695b512df..f3b0eaa78cdc 100644 --- a/packages/google-cloud-parametermanager/noxfile.py +++ b/packages/google-cloud-parametermanager/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-phishing-protection/noxfile.py b/packages/google-cloud-phishing-protection/noxfile.py index 25f6fe870561..ae30b0f33058 100644 --- a/packages/google-cloud-phishing-protection/noxfile.py +++ b/packages/google-cloud-phishing-protection/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-policy-troubleshooter/noxfile.py b/packages/google-cloud-policy-troubleshooter/noxfile.py index 440f9fe606e5..2c65c0758729 100644 --- a/packages/google-cloud-policy-troubleshooter/noxfile.py +++ b/packages/google-cloud-policy-troubleshooter/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-policysimulator/noxfile.py b/packages/google-cloud-policysimulator/noxfile.py index 12450bab7f3a..a550b1379466 100644 --- a/packages/google-cloud-policysimulator/noxfile.py +++ b/packages/google-cloud-policysimulator/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-policytroubleshooter-iam/noxfile.py b/packages/google-cloud-policytroubleshooter-iam/noxfile.py index 355577ec634a..d4a6848e245c 100644 --- a/packages/google-cloud-policytroubleshooter-iam/noxfile.py +++ b/packages/google-cloud-policytroubleshooter-iam/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-private-ca/noxfile.py b/packages/google-cloud-private-ca/noxfile.py index d3b3ae128e0b..0791331c0253 100644 --- a/packages/google-cloud-private-ca/noxfile.py +++ b/packages/google-cloud-private-ca/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-private-catalog/noxfile.py b/packages/google-cloud-private-catalog/noxfile.py index 90ca800521d7..64741cfcd48f 100644 --- a/packages/google-cloud-private-catalog/noxfile.py +++ b/packages/google-cloud-private-catalog/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-privilegedaccessmanager/noxfile.py b/packages/google-cloud-privilegedaccessmanager/noxfile.py index 735ba896c015..7f79a1900328 100644 --- a/packages/google-cloud-privilegedaccessmanager/noxfile.py +++ b/packages/google-cloud-privilegedaccessmanager/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-pubsub/noxfile.py b/packages/google-cloud-pubsub/noxfile.py index a4b1c6bf573f..c40cf145ed91 100644 --- a/packages/google-cloud-pubsub/noxfile.py +++ b/packages/google-cloud-pubsub/noxfile.py @@ -36,6 +36,7 @@ "3.12", "3.13", "3.14", + "import_profile", ] DEFAULT_PYTHON_VERSION = "3.14" @@ -636,20 +637,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google.cloud", "--iterations", "10" - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", str(profiler_script), "--module", "google.cloud", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-quotas/noxfile.py b/packages/google-cloud-quotas/noxfile.py index 08999c92667d..ff590a6a28d5 100644 --- a/packages/google-cloud-quotas/noxfile.py +++ b/packages/google-cloud-quotas/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-rapidmigrationassessment/noxfile.py b/packages/google-cloud-rapidmigrationassessment/noxfile.py index d17217d0255d..bf112a91dcfe 100644 --- a/packages/google-cloud-rapidmigrationassessment/noxfile.py +++ b/packages/google-cloud-rapidmigrationassessment/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-recaptcha-enterprise/noxfile.py b/packages/google-cloud-recaptcha-enterprise/noxfile.py index 21847936c769..08c1d42ded16 100644 --- a/packages/google-cloud-recaptcha-enterprise/noxfile.py +++ b/packages/google-cloud-recaptcha-enterprise/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-recommendations-ai/noxfile.py b/packages/google-cloud-recommendations-ai/noxfile.py index 0fc92ca705cb..24205aad018c 100644 --- a/packages/google-cloud-recommendations-ai/noxfile.py +++ b/packages/google-cloud-recommendations-ai/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-recommender/noxfile.py b/packages/google-cloud-recommender/noxfile.py index 0a80b32f6422..3bbb4d6fc22c 100644 --- a/packages/google-cloud-recommender/noxfile.py +++ b/packages/google-cloud-recommender/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-redis-cluster/noxfile.py b/packages/google-cloud-redis-cluster/noxfile.py index 78d319d1f7c9..88572b019370 100644 --- a/packages/google-cloud-redis-cluster/noxfile.py +++ b/packages/google-cloud-redis-cluster/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-redis/noxfile.py b/packages/google-cloud-redis/noxfile.py index cef26e7c5a7c..7607858dbbe2 100644 --- a/packages/google-cloud-redis/noxfile.py +++ b/packages/google-cloud-redis/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-resource-manager/noxfile.py b/packages/google-cloud-resource-manager/noxfile.py index fc0dc7847ce2..a048a5a726d1 100644 --- a/packages/google-cloud-resource-manager/noxfile.py +++ b/packages/google-cloud-resource-manager/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-retail/noxfile.py b/packages/google-cloud-retail/noxfile.py index 11452b85f24d..3f2ea9e83f3b 100644 --- a/packages/google-cloud-retail/noxfile.py +++ b/packages/google-cloud-retail/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-run/noxfile.py b/packages/google-cloud-run/noxfile.py index 3253de9773fd..3c503ba88328 100644 --- a/packages/google-cloud-run/noxfile.py +++ b/packages/google-cloud-run/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-runtimeconfig/noxfile.py b/packages/google-cloud-runtimeconfig/noxfile.py index 8ddfd1d9bf56..59f316735c54 100644 --- a/packages/google-cloud-runtimeconfig/noxfile.py +++ b/packages/google-cloud-runtimeconfig/noxfile.py @@ -522,20 +522,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-saasplatform-saasservicemgmt/noxfile.py b/packages/google-cloud-saasplatform-saasservicemgmt/noxfile.py index 71ec7167f504..5cde0760ad88 100644 --- a/packages/google-cloud-saasplatform-saasservicemgmt/noxfile.py +++ b/packages/google-cloud-saasplatform-saasservicemgmt/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-scheduler/noxfile.py b/packages/google-cloud-scheduler/noxfile.py index 4e17331ee38a..b2827bf02f60 100644 --- a/packages/google-cloud-scheduler/noxfile.py +++ b/packages/google-cloud-scheduler/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-secret-manager/noxfile.py b/packages/google-cloud-secret-manager/noxfile.py index 5d36853dea3a..46ab2efa1ad6 100644 --- a/packages/google-cloud-secret-manager/noxfile.py +++ b/packages/google-cloud-secret-manager/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-securesourcemanager/noxfile.py b/packages/google-cloud-securesourcemanager/noxfile.py index b300e0da64ac..dc61c4d3981e 100644 --- a/packages/google-cloud-securesourcemanager/noxfile.py +++ b/packages/google-cloud-securesourcemanager/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-security-publicca/noxfile.py b/packages/google-cloud-security-publicca/noxfile.py index bb62d133a738..2c2d5ea26f3c 100644 --- a/packages/google-cloud-security-publicca/noxfile.py +++ b/packages/google-cloud-security-publicca/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-securitycenter/noxfile.py b/packages/google-cloud-securitycenter/noxfile.py index d57effeea216..533350603995 100644 --- a/packages/google-cloud-securitycenter/noxfile.py +++ b/packages/google-cloud-securitycenter/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-securitycentermanagement/noxfile.py b/packages/google-cloud-securitycentermanagement/noxfile.py index 0ea6db67ea15..2a61726a9504 100644 --- a/packages/google-cloud-securitycentermanagement/noxfile.py +++ b/packages/google-cloud-securitycentermanagement/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-service-control/noxfile.py b/packages/google-cloud-service-control/noxfile.py index 20c092de2940..372155b76146 100644 --- a/packages/google-cloud-service-control/noxfile.py +++ b/packages/google-cloud-service-control/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-service-directory/noxfile.py b/packages/google-cloud-service-directory/noxfile.py index 5651f1a50755..e827649bb22c 100644 --- a/packages/google-cloud-service-directory/noxfile.py +++ b/packages/google-cloud-service-directory/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-service-management/noxfile.py b/packages/google-cloud-service-management/noxfile.py index f5cf266963be..3f82574cbb9a 100644 --- a/packages/google-cloud-service-management/noxfile.py +++ b/packages/google-cloud-service-management/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-service-usage/noxfile.py b/packages/google-cloud-service-usage/noxfile.py index 6f12e316c504..6a2bca1caa75 100644 --- a/packages/google-cloud-service-usage/noxfile.py +++ b/packages/google-cloud-service-usage/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-servicehealth/noxfile.py b/packages/google-cloud-servicehealth/noxfile.py index 31c81fc1d84b..d2eaed1a29dc 100644 --- a/packages/google-cloud-servicehealth/noxfile.py +++ b/packages/google-cloud-servicehealth/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-shell/noxfile.py b/packages/google-cloud-shell/noxfile.py index 7267ecf4f08f..708180a0fc23 100644 --- a/packages/google-cloud-shell/noxfile.py +++ b/packages/google-cloud-shell/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-source-context/noxfile.py b/packages/google-cloud-source-context/noxfile.py index 3e8c8d0a2c51..864433def8e1 100644 --- a/packages/google-cloud-source-context/noxfile.py +++ b/packages/google-cloud-source-context/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-spanner-dbapi-driver/noxfile.py b/packages/google-cloud-spanner-dbapi-driver/noxfile.py index 57bd00433972..2803c63894c7 100644 --- a/packages/google-cloud-spanner-dbapi-driver/noxfile.py +++ b/packages/google-cloud-spanner-dbapi-driver/noxfile.py @@ -618,5 +618,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-spanner/noxfile.py b/packages/google-cloud-spanner/noxfile.py index b2fc88375114..58e9ce45a7f7 100644 --- a/packages/google-cloud-spanner/noxfile.py +++ b/packages/google-cloud-spanner/noxfile.py @@ -36,6 +36,7 @@ "3.12", "3.13", "3.14", + "import_profile", ] UNIT_TEST_STANDARD_DEPENDENCIES = [ "mock", @@ -861,20 +862,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-speech/noxfile.py b/packages/google-cloud-speech/noxfile.py index 05aafb09845e..e96d284fe06f 100644 --- a/packages/google-cloud-speech/noxfile.py +++ b/packages/google-cloud-speech/noxfile.py @@ -652,5 +652,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-storage-control/noxfile.py b/packages/google-cloud-storage-control/noxfile.py index bbd2249a437b..63fc57413c49 100644 --- a/packages/google-cloud-storage-control/noxfile.py +++ b/packages/google-cloud-storage-control/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-storage-transfer/noxfile.py b/packages/google-cloud-storage-transfer/noxfile.py index ef83a31642d4..a3a623842a73 100644 --- a/packages/google-cloud-storage-transfer/noxfile.py +++ b/packages/google-cloud-storage-transfer/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-storage/noxfile.py b/packages/google-cloud-storage/noxfile.py index cce97b12929d..8eaf373a7497 100644 --- a/packages/google-cloud-storage/noxfile.py +++ b/packages/google-cloud-storage/noxfile.py @@ -729,7 +729,7 @@ def import_profile(session): "python", str(profiler_script), "--module", - "unknown_module", + "google", "--iterations", "10", ) diff --git a/packages/google-cloud-storagebatchoperations/noxfile.py b/packages/google-cloud-storagebatchoperations/noxfile.py index c7eb539fe1b4..2b3659c6b128 100644 --- a/packages/google-cloud-storagebatchoperations/noxfile.py +++ b/packages/google-cloud-storagebatchoperations/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-storageinsights/noxfile.py b/packages/google-cloud-storageinsights/noxfile.py index 8676f8fc6c1d..a9c0bd98deee 100644 --- a/packages/google-cloud-storageinsights/noxfile.py +++ b/packages/google-cloud-storageinsights/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-support/noxfile.py b/packages/google-cloud-support/noxfile.py index 16f001bc498a..2b45313baa74 100644 --- a/packages/google-cloud-support/noxfile.py +++ b/packages/google-cloud-support/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-talent/noxfile.py b/packages/google-cloud-talent/noxfile.py index e87be08bcef3..dca6d5478a3a 100644 --- a/packages/google-cloud-talent/noxfile.py +++ b/packages/google-cloud-talent/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-tasks/noxfile.py b/packages/google-cloud-tasks/noxfile.py index 6e92e77c61fe..94cf83c01a0f 100644 --- a/packages/google-cloud-tasks/noxfile.py +++ b/packages/google-cloud-tasks/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-telcoautomation/noxfile.py b/packages/google-cloud-telcoautomation/noxfile.py index 08e7d521068b..06bf9b9729bf 100644 --- a/packages/google-cloud-telcoautomation/noxfile.py +++ b/packages/google-cloud-telcoautomation/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-testutils/noxfile.py b/packages/google-cloud-testutils/noxfile.py index 138625a4d3ce..452a8cecc92f 100644 --- a/packages/google-cloud-testutils/noxfile.py +++ b/packages/google-cloud-testutils/noxfile.py @@ -27,6 +27,7 @@ nox.options.sessions = [ "check_lower_bounds", "format", + "import_profile", ] @@ -80,10 +81,8 @@ def format(session): # 2. Run Ruff to fix imports session.run( - "ruff", - "check", - "--select", - "I", + "ruff", "check", + "--select", "I", "--fix", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", @@ -92,8 +91,7 @@ def format(session): # 3. Run Ruff to format code session.run( - "ruff", - "format", + "ruff", "format", f"--target-version=py{ALL_PYTHON[0].replace('.', '')}", "--line-length=88", *BLACK_PATHS, @@ -331,12 +329,14 @@ def prerelease_deps(session): ) + @nox.session(python=DEFAULT_PYTHON_VERSION) def core_deps_from_source(session): """Run all tests with core dependencies installed from source rather than pulling the dependencies from PyPI. """ + # Install all dependencies constraints_path = str( CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" @@ -400,27 +400,7 @@ def import_profile(session): "python", str(profiler_script), "--module", - "unknown_module", - "--iterations", - "10", - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "unknown_module", + "google", "--iterations", "10", ) diff --git a/packages/google-cloud-texttospeech/noxfile.py b/packages/google-cloud-texttospeech/noxfile.py index 330d33187281..854bd4390049 100644 --- a/packages/google-cloud-texttospeech/noxfile.py +++ b/packages/google-cloud-texttospeech/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-tpu/noxfile.py b/packages/google-cloud-tpu/noxfile.py index f68a2770fe2f..86182ecd9d84 100644 --- a/packages/google-cloud-tpu/noxfile.py +++ b/packages/google-cloud-tpu/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-trace/noxfile.py b/packages/google-cloud-trace/noxfile.py index 23345075c142..b9e776ea8b43 100644 --- a/packages/google-cloud-trace/noxfile.py +++ b/packages/google-cloud-trace/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-translate/noxfile.py b/packages/google-cloud-translate/noxfile.py index 90d129501aaa..6519a4a97734 100644 --- a/packages/google-cloud-translate/noxfile.py +++ b/packages/google-cloud-translate/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-vectorsearch/noxfile.py b/packages/google-cloud-vectorsearch/noxfile.py index e00afbe55d53..5dd818f913e9 100644 --- a/packages/google-cloud-vectorsearch/noxfile.py +++ b/packages/google-cloud-vectorsearch/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-video-live-stream/noxfile.py b/packages/google-cloud-video-live-stream/noxfile.py index 13588b31dd39..fe58299473cb 100644 --- a/packages/google-cloud-video-live-stream/noxfile.py +++ b/packages/google-cloud-video-live-stream/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-video-stitcher/noxfile.py b/packages/google-cloud-video-stitcher/noxfile.py index 208ee56e7e52..aa6cd92cd591 100644 --- a/packages/google-cloud-video-stitcher/noxfile.py +++ b/packages/google-cloud-video-stitcher/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-video-transcoder/noxfile.py b/packages/google-cloud-video-transcoder/noxfile.py index a4ca8e2f5c28..181078acde80 100644 --- a/packages/google-cloud-video-transcoder/noxfile.py +++ b/packages/google-cloud-video-transcoder/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-videointelligence/noxfile.py b/packages/google-cloud-videointelligence/noxfile.py index 1254237487c8..9b62642fc281 100644 --- a/packages/google-cloud-videointelligence/noxfile.py +++ b/packages/google-cloud-videointelligence/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-vision/noxfile.py b/packages/google-cloud-vision/noxfile.py index c006321f4756..34805fef8639 100644 --- a/packages/google-cloud-vision/noxfile.py +++ b/packages/google-cloud-vision/noxfile.py @@ -652,5 +652,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-visionai/noxfile.py b/packages/google-cloud-visionai/noxfile.py index 4b8fd2804875..d17e0baf7e77 100644 --- a/packages/google-cloud-visionai/noxfile.py +++ b/packages/google-cloud-visionai/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-vm-migration/noxfile.py b/packages/google-cloud-vm-migration/noxfile.py index a418479389ff..aa1cd44d4f90 100644 --- a/packages/google-cloud-vm-migration/noxfile.py +++ b/packages/google-cloud-vm-migration/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-vmwareengine/noxfile.py b/packages/google-cloud-vmwareengine/noxfile.py index ed25a49c09d2..677cbc92f7ff 100644 --- a/packages/google-cloud-vmwareengine/noxfile.py +++ b/packages/google-cloud-vmwareengine/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-vpc-access/noxfile.py b/packages/google-cloud-vpc-access/noxfile.py index 88bf226cdcc2..94988fdf9484 100644 --- a/packages/google-cloud-vpc-access/noxfile.py +++ b/packages/google-cloud-vpc-access/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-webrisk/noxfile.py b/packages/google-cloud-webrisk/noxfile.py index fbb1c9b4053c..a7b38b08a2fa 100644 --- a/packages/google-cloud-webrisk/noxfile.py +++ b/packages/google-cloud-webrisk/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-websecurityscanner/noxfile.py b/packages/google-cloud-websecurityscanner/noxfile.py index 21e2caa4c178..ceaa5aedd223 100644 --- a/packages/google-cloud-websecurityscanner/noxfile.py +++ b/packages/google-cloud-websecurityscanner/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-workflows/noxfile.py b/packages/google-cloud-workflows/noxfile.py index a31876ffff4d..c8425a74129f 100644 --- a/packages/google-cloud-workflows/noxfile.py +++ b/packages/google-cloud-workflows/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-workloadmanager/noxfile.py b/packages/google-cloud-workloadmanager/noxfile.py index 1f8ef11ad647..da7c9faec917 100644 --- a/packages/google-cloud-workloadmanager/noxfile.py +++ b/packages/google-cloud-workloadmanager/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-cloud-workstations/noxfile.py b/packages/google-cloud-workstations/noxfile.py index 9ceaf5ddaeb5..9c7cb0b11472 100644 --- a/packages/google-cloud-workstations/noxfile.py +++ b/packages/google-cloud-workstations/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-developer-knowledge/noxfile.py b/packages/google-developer-knowledge/noxfile.py index 7a601e3c2e2e..cde71f0d9a38 100644 --- a/packages/google-developer-knowledge/noxfile.py +++ b/packages/google-developer-knowledge/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-devicesandservices-health/noxfile.py b/packages/google-devicesandservices-health/noxfile.py index 8bb4d4f54b47..99e05fde845c 100644 --- a/packages/google-devicesandservices-health/noxfile.py +++ b/packages/google-devicesandservices-health/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-geo-type/noxfile.py b/packages/google-geo-type/noxfile.py index c747ecefe0c3..ca149a2653fb 100644 --- a/packages/google-geo-type/noxfile.py +++ b/packages/google-geo-type/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-maps-addressvalidation/noxfile.py b/packages/google-maps-addressvalidation/noxfile.py index b8a3a66ae43d..876662bf4752 100644 --- a/packages/google-maps-addressvalidation/noxfile.py +++ b/packages/google-maps-addressvalidation/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-maps-areainsights/noxfile.py b/packages/google-maps-areainsights/noxfile.py index 1012441a475b..3cf8cac0ec50 100644 --- a/packages/google-maps-areainsights/noxfile.py +++ b/packages/google-maps-areainsights/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-maps-fleetengine-delivery/noxfile.py b/packages/google-maps-fleetengine-delivery/noxfile.py index b830c51e2296..4bcdfb09fa03 100644 --- a/packages/google-maps-fleetengine-delivery/noxfile.py +++ b/packages/google-maps-fleetengine-delivery/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-maps-fleetengine/noxfile.py b/packages/google-maps-fleetengine/noxfile.py index 1595c3868faf..d2fc100ed5c8 100644 --- a/packages/google-maps-fleetengine/noxfile.py +++ b/packages/google-maps-fleetengine/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-maps-geocode/noxfile.py b/packages/google-maps-geocode/noxfile.py index 20b4b720ef2e..2d338faa8484 100644 --- a/packages/google-maps-geocode/noxfile.py +++ b/packages/google-maps-geocode/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-maps-mapmanagement/noxfile.py b/packages/google-maps-mapmanagement/noxfile.py index 378f56726162..7835257f02b2 100644 --- a/packages/google-maps-mapmanagement/noxfile.py +++ b/packages/google-maps-mapmanagement/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-maps-mapsplatformdatasets/noxfile.py b/packages/google-maps-mapsplatformdatasets/noxfile.py index 3d10d8c41d49..f210fd9d8e54 100644 --- a/packages/google-maps-mapsplatformdatasets/noxfile.py +++ b/packages/google-maps-mapsplatformdatasets/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-maps-navconnect/noxfile.py b/packages/google-maps-navconnect/noxfile.py index 5b651b34028d..f88bf58c5ecd 100644 --- a/packages/google-maps-navconnect/noxfile.py +++ b/packages/google-maps-navconnect/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-maps-places/noxfile.py b/packages/google-maps-places/noxfile.py index 5bebf46d05e8..fde6497d963a 100644 --- a/packages/google-maps-places/noxfile.py +++ b/packages/google-maps-places/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-maps-routeoptimization/noxfile.py b/packages/google-maps-routeoptimization/noxfile.py index f95089005db3..20cff4c84f1c 100644 --- a/packages/google-maps-routeoptimization/noxfile.py +++ b/packages/google-maps-routeoptimization/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-maps-routing/noxfile.py b/packages/google-maps-routing/noxfile.py index 4d98fac639e2..6473b5ce489e 100644 --- a/packages/google-maps-routing/noxfile.py +++ b/packages/google-maps-routing/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-maps-solar/noxfile.py b/packages/google-maps-solar/noxfile.py index e389b65dfde0..1424432a2578 100644 --- a/packages/google-maps-solar/noxfile.py +++ b/packages/google-maps-solar/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-resumable-media/noxfile.py b/packages/google-resumable-media/noxfile.py index e9c5e340faa2..98913bef43b0 100644 --- a/packages/google-resumable-media/noxfile.py +++ b/packages/google-resumable-media/noxfile.py @@ -37,6 +37,7 @@ "blacken", "mypy", "doctest", + "import_profile", ] @@ -68,7 +69,7 @@ def unit(session): line_coverage, os.path.join("tests", "unit"), os.path.join("tests_async", "unit"), - *session.posargs, + *session.posargs ) @@ -106,7 +107,6 @@ def docs(session): os.path.join("docs", "_build", "html", ""), ) - @nox.session(python="3.10") def docfx(session): """Build the docfx yaml files for this library.""" @@ -320,9 +320,7 @@ def prerelease_deps(session): # version, the first version we test with in the unit tests sessions has a # constraints file containing all dependencies and extras. with open( - CURRENT_DIRECTORY - / "testing" - / f"constraints-{UNIT_TEST_PYTHON_VERSIONS[0]}.txt", + CURRENT_DIRECTORY / "testing" / f"constraints-{UNIT_TEST_PYTHON_VERSIONS[0]}.txt", encoding="utf-8", ) as constraints_file: constraints_text = constraints_file.read() @@ -403,9 +401,7 @@ def core_deps_from_source(session): # version, the first version we test with in the unit tests sessions has a # constraints file containing all dependencies and extras. with open( - CURRENT_DIRECTORY - / "testing" - / f"constraints-{UNIT_TEST_PYTHON_VERSIONS[0]}.txt", + CURRENT_DIRECTORY / "testing" / f"constraints-{UNIT_TEST_PYTHON_VERSIONS[0]}.txt", encoding="utf-8", ) as constraints_file: constraints_text = constraints_file.read() @@ -436,9 +432,7 @@ def core_deps_from_source(session): dep_paths = [str(deps_dir / dep) for dep in core_dependencies_from_source] session.install(*dep_paths, "--no-deps", "--ignore-installed") - print( - f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}" - ) + print(f"Installed {', '.join(core_dependencies_from_source)} locally from {deps_dir}") other_deps = [ "cryptography", @@ -468,20 +462,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-shopping-css/noxfile.py b/packages/google-shopping-css/noxfile.py index db0fa77a3bd2..b3f481bab451 100644 --- a/packages/google-shopping-css/noxfile.py +++ b/packages/google-shopping-css/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-shopping-merchant-accounts/noxfile.py b/packages/google-shopping-merchant-accounts/noxfile.py index d39107a1e49b..532bd620a34a 100644 --- a/packages/google-shopping-merchant-accounts/noxfile.py +++ b/packages/google-shopping-merchant-accounts/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-shopping-merchant-conversions/noxfile.py b/packages/google-shopping-merchant-conversions/noxfile.py index 4320cfd6379a..26cf2c084ffd 100644 --- a/packages/google-shopping-merchant-conversions/noxfile.py +++ b/packages/google-shopping-merchant-conversions/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-shopping-merchant-datasources/noxfile.py b/packages/google-shopping-merchant-datasources/noxfile.py index 009bbaa8b055..680dbe0227e5 100644 --- a/packages/google-shopping-merchant-datasources/noxfile.py +++ b/packages/google-shopping-merchant-datasources/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-shopping-merchant-inventories/noxfile.py b/packages/google-shopping-merchant-inventories/noxfile.py index 6050b8271428..516088661daa 100644 --- a/packages/google-shopping-merchant-inventories/noxfile.py +++ b/packages/google-shopping-merchant-inventories/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-shopping-merchant-issueresolution/noxfile.py b/packages/google-shopping-merchant-issueresolution/noxfile.py index 35a66d863a5a..5e67ff92e118 100644 --- a/packages/google-shopping-merchant-issueresolution/noxfile.py +++ b/packages/google-shopping-merchant-issueresolution/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-shopping-merchant-lfp/noxfile.py b/packages/google-shopping-merchant-lfp/noxfile.py index 997f44148ee2..5f58ef1c31c0 100644 --- a/packages/google-shopping-merchant-lfp/noxfile.py +++ b/packages/google-shopping-merchant-lfp/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-shopping-merchant-notifications/noxfile.py b/packages/google-shopping-merchant-notifications/noxfile.py index ac86477c39eb..7342a58c170b 100644 --- a/packages/google-shopping-merchant-notifications/noxfile.py +++ b/packages/google-shopping-merchant-notifications/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-shopping-merchant-ordertracking/noxfile.py b/packages/google-shopping-merchant-ordertracking/noxfile.py index b098ae8d6d2c..c853353fa5cc 100644 --- a/packages/google-shopping-merchant-ordertracking/noxfile.py +++ b/packages/google-shopping-merchant-ordertracking/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-shopping-merchant-products/noxfile.py b/packages/google-shopping-merchant-products/noxfile.py index 41596f28c46d..133dfa410bec 100644 --- a/packages/google-shopping-merchant-products/noxfile.py +++ b/packages/google-shopping-merchant-products/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-shopping-merchant-productstudio/noxfile.py b/packages/google-shopping-merchant-productstudio/noxfile.py index bbe8a6710485..bba0cbbf13ed 100644 --- a/packages/google-shopping-merchant-productstudio/noxfile.py +++ b/packages/google-shopping-merchant-productstudio/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-shopping-merchant-promotions/noxfile.py b/packages/google-shopping-merchant-promotions/noxfile.py index c80b2b4cbbd6..7f673392b5d6 100644 --- a/packages/google-shopping-merchant-promotions/noxfile.py +++ b/packages/google-shopping-merchant-promotions/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-shopping-merchant-quota/noxfile.py b/packages/google-shopping-merchant-quota/noxfile.py index 2a76170c8b4c..0bd9a74cef3a 100644 --- a/packages/google-shopping-merchant-quota/noxfile.py +++ b/packages/google-shopping-merchant-quota/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-shopping-merchant-reports/noxfile.py b/packages/google-shopping-merchant-reports/noxfile.py index f77aec074e1c..2776c5afe67e 100644 --- a/packages/google-shopping-merchant-reports/noxfile.py +++ b/packages/google-shopping-merchant-reports/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-shopping-merchant-reviews/noxfile.py b/packages/google-shopping-merchant-reviews/noxfile.py index 4e5109729cae..7965d9402799 100644 --- a/packages/google-shopping-merchant-reviews/noxfile.py +++ b/packages/google-shopping-merchant-reviews/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/google-shopping-type/noxfile.py b/packages/google-shopping-type/noxfile.py index eb8860937139..efa0f6b56d2c 100644 --- a/packages/google-shopping-type/noxfile.py +++ b/packages/google-shopping-type/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "google", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "google", + "--iterations", + "10", ) diff --git a/packages/googleapis-common-protos/noxfile.py b/packages/googleapis-common-protos/noxfile.py index b52825929435..5aaaef4e36d3 100644 --- a/packages/googleapis-common-protos/noxfile.py +++ b/packages/googleapis-common-protos/noxfile.py @@ -616,7 +616,7 @@ def import_profile(session): "python", str(profiler_script), "--module", - "unknown_module", + "google", "--iterations", "10", ) diff --git a/packages/grafeas/noxfile.py b/packages/grafeas/noxfile.py index b6171f0f4ea6..c8d718b8cb48 100644 --- a/packages/grafeas/noxfile.py +++ b/packages/grafeas/noxfile.py @@ -651,5 +651,10 @@ def import_profile(session): session.install(".") session.run( - "python", str(profiler_script), "--module", "grafeas", "--iterations", "10" + "python", + str(profiler_script), + "--module", + "grafeas", + "--iterations", + "10", ) diff --git a/packages/grpc-google-iam-v1/noxfile.py b/packages/grpc-google-iam-v1/noxfile.py index 7b24b0101620..7f36d938a092 100644 --- a/packages/grpc-google-iam-v1/noxfile.py +++ b/packages/grpc-google-iam-v1/noxfile.py @@ -601,7 +601,7 @@ def import_profile(session): "python", str(profiler_script), "--module", - "unknown_module", + "google", "--iterations", "10", ) diff --git a/packages/pandas-gbq/noxfile.py b/packages/pandas-gbq/noxfile.py index 549f1b4a4a84..ac2c70e36407 100644 --- a/packages/pandas-gbq/noxfile.py +++ b/packages/pandas-gbq/noxfile.py @@ -612,7 +612,7 @@ def import_profile(session): "python", str(profiler_script), "--module", - "unknown_module", + "google", "--iterations", "10", ) diff --git a/packages/proto-plus/noxfile.py b/packages/proto-plus/noxfile.py index 3a3d0411f202..ad4d80f2703e 100644 --- a/packages/proto-plus/noxfile.py +++ b/packages/proto-plus/noxfile.py @@ -369,27 +369,7 @@ def import_profile(session): "python", str(profiler_script), "--module", - "unknown_module", - "--iterations", - "10", - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "unknown_module", + "google", "--iterations", "10", ) diff --git a/packages/sqlalchemy-bigquery/noxfile.py b/packages/sqlalchemy-bigquery/noxfile.py index 1ea43b3281a4..41e81fa1fff1 100644 --- a/packages/sqlalchemy-bigquery/noxfile.py +++ b/packages/sqlalchemy-bigquery/noxfile.py @@ -40,6 +40,7 @@ "tests", "noxfile.py", "setup.py", + "import_profile", ] DEFAULT_PYTHON_VERSION = "3.14" @@ -758,27 +759,7 @@ def import_profile(session): "python", str(profiler_script), "--module", - "unknown_module", - "--iterations", - "10", - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "unknown_module", + "google", "--iterations", "10", ) diff --git a/packages/sqlalchemy-spanner/noxfile.py b/packages/sqlalchemy-spanner/noxfile.py index bf2b37b66538..597d728dcf1b 100644 --- a/packages/sqlalchemy-spanner/noxfile.py +++ b/packages/sqlalchemy-spanner/noxfile.py @@ -85,6 +85,7 @@ class = StreamHandler UNIT_TEST_STANDARD_DEPENDENCIES = [ "mock", "pytest", + "import_profile", ] UNIT_TEST_EXTERNAL_DEPENDENCIES = [ @@ -620,27 +621,7 @@ def import_profile(session): "python", str(profiler_script), "--module", - "unknown_module", - "--iterations", - "10", - ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "unknown_module", + "google", "--iterations", "10", ) From 42dd64af77809bbd67f7b6f98926e2bf871ae7bb Mon Sep 17 00:00:00 2001 From: Heba Alazzeh Date: Wed, 8 Jul 2026 16:27:18 +0000 Subject: [PATCH 08/13] chore: revert gapic-generator template and noxfile changes in packages --- packages/bigframes/noxfile.py | 21 --- packages/bigquery-magics/noxfile.py | 21 --- packages/db-dtypes/noxfile.py | 21 --- packages/django-google-spanner/noxfile.py | 20 --- .../gapic/templates/noxfile.py.j2 | 32 ---- packages/gapic-generator/noxfile.py | 21 +-- .../integration/goldens/asset/noxfile.py | 21 --- .../goldens/credentials/noxfile.py | 21 --- .../integration/goldens/eventarc/noxfile.py | 21 --- .../integration/goldens/logging/noxfile.py | 21 --- .../goldens/logging_internal/noxfile.py | 21 --- .../integration/goldens/redis/noxfile.py | 21 --- .../goldens/redis_selective/noxfile.py | 21 --- .../goldens/storagebatchoperations/noxfile.py | 21 --- packages/gcp-sphinx-docfx-yaml/noxfile.py | 21 --- packages/google-ads-admanager/noxfile.py | 21 --- packages/google-ads-datamanager/noxfile.py | 21 --- .../noxfile.py | 21 --- .../google-ai-generativelanguage/noxfile.py | 21 --- packages/google-analytics-admin/noxfile.py | 21 --- packages/google-analytics-data/noxfile.py | 21 --- packages/google-api-core/noxfile.py | 20 --- packages/google-apps-card/noxfile.py | 21 --- packages/google-apps-chat/noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-apps-meet/noxfile.py | 21 --- packages/google-apps-script-type/noxfile.py | 21 --- packages/google-area120-tables/noxfile.py | 21 --- packages/google-auth-httplib2/noxfile.py | 20 --- packages/google-auth-oauthlib/noxfile.py | 20 --- packages/google-auth/noxfile.py | 21 --- packages/google-backstory/noxfile.py | 21 --- .../google-cloud-access-approval/noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- .../google-cloud-agentregistry/noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-alloydb/noxfile.py | 21 --- packages/google-cloud-api-gateway/noxfile.py | 21 --- packages/google-cloud-api-keys/noxfile.py | 21 --- .../google-cloud-apigee-connect/noxfile.py | 21 --- .../google-cloud-apigee-registry/noxfile.py | 21 --- packages/google-cloud-apihub/noxfile.py | 21 --- packages/google-cloud-apiregistry/noxfile.py | 21 --- .../google-cloud-appengine-admin/noxfile.py | 21 --- .../google-cloud-appengine-logging/noxfile.py | 21 --- packages/google-cloud-apphub/noxfile.py | 21 --- packages/google-cloud-appoptimize/noxfile.py | 21 --- .../google-cloud-artifact-registry/noxfile.py | 21 --- packages/google-cloud-asset/noxfile.py | 21 --- .../google-cloud-assured-workloads/noxfile.py | 21 --- packages/google-cloud-audit-log/noxfile.py | 21 --- packages/google-cloud-auditmanager/noxfile.py | 21 --- packages/google-cloud-automl/noxfile.py | 21 --- packages/google-cloud-backupdr/noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-batch/noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-biglake-hive/noxfile.py | 21 --- packages/google-cloud-biglake/noxfile.py | 21 --- .../noxfile.py | 21 --- .../google-cloud-bigquery-biglake/noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- .../google-cloud-bigquery-logging/noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- .../google-cloud-bigquery-storage/noxfile.py | 21 --- packages/google-cloud-bigquery/noxfile.py | 21 --- packages/google-cloud-bigtable/noxfile.py | 21 --- .../google-cloud-billing-budgets/noxfile.py | 21 --- packages/google-cloud-billing/noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-build/noxfile.py | 21 --- .../google-cloud-capacityplanner/noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-ces/noxfile.py | 21 --- packages/google-cloud-channel/noxfile.py | 21 --- packages/google-cloud-chronicle/noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-common/noxfile.py | 21 --- .../google-cloud-compute-v1beta/noxfile.py | 21 --- .../services/accelerator_types/client.py | 136 +++++++++++++++++ .../compute_v1/services/addresses/client.py | 136 +++++++++++++++++ .../compute_v1/services/advice/client.py | 136 +++++++++++++++++ .../compute_v1/services/autoscalers/client.py | 136 +++++++++++++++++ .../services/backend_buckets/client.py | 136 +++++++++++++++++ .../services/backend_services/client.py | 136 +++++++++++++++++ .../services/cross_site_networks/client.py | 136 +++++++++++++++++ .../compute_v1/services/disk_types/client.py | 136 +++++++++++++++++ .../cloud/compute_v1/services/disks/client.py | 136 +++++++++++++++++ .../services/external_vpn_gateways/client.py | 136 +++++++++++++++++ .../services/firewall_policies/client.py | 136 +++++++++++++++++ .../compute_v1/services/firewalls/client.py | 136 +++++++++++++++++ .../services/forwarding_rules/client.py | 136 +++++++++++++++++ .../services/future_reservations/client.py | 136 +++++++++++++++++ .../services/global_addresses/client.py | 136 +++++++++++++++++ .../global_forwarding_rules/client.py | 136 +++++++++++++++++ .../global_network_endpoint_groups/client.py | 136 +++++++++++++++++ .../services/global_operations/client.py | 136 +++++++++++++++++ .../global_organization_operations/client.py | 138 +++++++++++++++++ .../client.py | 138 +++++++++++++++++ .../global_vm_extension_policies/client.py | 136 +++++++++++++++++ .../services/health_checks/client.py | 136 +++++++++++++++++ .../services/image_family_views/client.py | 136 +++++++++++++++++ .../compute_v1/services/images/client.py | 136 +++++++++++++++++ .../client.py | 138 +++++++++++++++++ .../instance_group_managers/client.py | 136 +++++++++++++++++ .../services/instance_groups/client.py | 136 +++++++++++++++++ .../instance_settings_service/client.py | 136 +++++++++++++++++ .../services/instance_templates/client.py | 136 +++++++++++++++++ .../compute_v1/services/instances/client.py | 136 +++++++++++++++++ .../instant_snapshot_groups/client.py | 136 +++++++++++++++++ .../services/instant_snapshots/client.py | 136 +++++++++++++++++ .../interconnect_attachment_groups/client.py | 138 +++++++++++++++++ .../interconnect_attachments/client.py | 136 +++++++++++++++++ .../services/interconnect_groups/client.py | 136 +++++++++++++++++ .../services/interconnect_locations/client.py | 136 +++++++++++++++++ .../interconnect_remote_locations/client.py | 136 +++++++++++++++++ .../services/interconnects/client.py | 136 +++++++++++++++++ .../services/license_codes/client.py | 136 +++++++++++++++++ .../compute_v1/services/licenses/client.py | 136 +++++++++++++++++ .../services/machine_images/client.py | 136 +++++++++++++++++ .../services/machine_types/client.py | 136 +++++++++++++++++ .../services/network_attachments/client.py | 136 +++++++++++++++++ .../network_edge_security_services/client.py | 136 +++++++++++++++++ .../network_endpoint_groups/client.py | 136 +++++++++++++++++ .../network_firewall_policies/client.py | 136 +++++++++++++++++ .../services/network_profiles/client.py | 136 +++++++++++++++++ .../compute_v1/services/networks/client.py | 136 +++++++++++++++++ .../compute_v1/services/node_groups/client.py | 136 +++++++++++++++++ .../services/node_templates/client.py | 136 +++++++++++++++++ .../compute_v1/services/node_types/client.py | 136 +++++++++++++++++ .../organization_security_policies/client.py | 138 +++++++++++++++++ .../services/packet_mirrorings/client.py | 136 +++++++++++++++++ .../services/preview_features/client.py | 136 +++++++++++++++++ .../compute_v1/services/projects/client.py | 136 +++++++++++++++++ .../public_advertised_prefixes/client.py | 136 +++++++++++++++++ .../public_delegated_prefixes/client.py | 136 +++++++++++++++++ .../services/region_autoscalers/client.py | 136 +++++++++++++++++ .../services/region_backend_buckets/client.py | 136 +++++++++++++++++ .../region_backend_services/client.py | 136 +++++++++++++++++ .../services/region_commitments/client.py | 136 +++++++++++++++++ .../region_composite_health_checks/client.py | 136 +++++++++++++++++ .../services/region_disk_types/client.py | 136 +++++++++++++++++ .../services/region_disks/client.py | 136 +++++++++++++++++ .../client.py | 138 +++++++++++++++++ .../region_health_check_services/client.py | 136 +++++++++++++++++ .../services/region_health_checks/client.py | 136 +++++++++++++++++ .../services/region_health_sources/client.py | 136 +++++++++++++++++ .../client.py | 140 ++++++++++++++++++ .../region_instance_group_managers/client.py | 136 +++++++++++++++++ .../services/region_instance_groups/client.py | 136 +++++++++++++++++ .../region_instance_templates/client.py | 136 +++++++++++++++++ .../services/region_instances/client.py | 136 +++++++++++++++++ .../region_instant_snapshot_groups/client.py | 136 +++++++++++++++++ .../region_instant_snapshots/client.py | 136 +++++++++++++++++ .../region_network_endpoint_groups/client.py | 136 +++++++++++++++++ .../client.py | 138 +++++++++++++++++ .../region_notification_endpoints/client.py | 136 +++++++++++++++++ .../services/region_operations/client.py | 136 +++++++++++++++++ .../region_security_policies/client.py | 136 +++++++++++++++++ .../region_snapshot_settings/client.py | 136 +++++++++++++++++ .../services/region_snapshots/client.py | 136 +++++++++++++++++ .../region_ssl_certificates/client.py | 136 +++++++++++++++++ .../services/region_ssl_policies/client.py | 136 +++++++++++++++++ .../region_target_http_proxies/client.py | 136 +++++++++++++++++ .../region_target_https_proxies/client.py | 136 +++++++++++++++++ .../region_target_tcp_proxies/client.py | 136 +++++++++++++++++ .../services/region_url_maps/client.py | 136 +++++++++++++++++ .../services/region_zones/client.py | 136 +++++++++++++++++ .../compute_v1/services/regions/client.py | 136 +++++++++++++++++ .../services/reservation_blocks/client.py | 136 +++++++++++++++++ .../services/reservation_slots/client.py | 136 +++++++++++++++++ .../services/reservation_sub_blocks/client.py | 136 +++++++++++++++++ .../services/reservations/client.py | 136 +++++++++++++++++ .../services/resource_policies/client.py | 136 +++++++++++++++++ .../services/rollout_plans/client.py | 136 +++++++++++++++++ .../compute_v1/services/rollouts/client.py | 136 +++++++++++++++++ .../compute_v1/services/routers/client.py | 136 +++++++++++++++++ .../compute_v1/services/routes/client.py | 136 +++++++++++++++++ .../services/security_policies/client.py | 136 +++++++++++++++++ .../services/service_attachments/client.py | 136 +++++++++++++++++ .../snapshot_settings_service/client.py | 136 +++++++++++++++++ .../compute_v1/services/snapshots/client.py | 136 +++++++++++++++++ .../services/ssl_certificates/client.py | 136 +++++++++++++++++ .../services/ssl_policies/client.py | 136 +++++++++++++++++ .../services/storage_pool_types/client.py | 136 +++++++++++++++++ .../services/storage_pools/client.py | 136 +++++++++++++++++ .../compute_v1/services/subnetworks/client.py | 136 +++++++++++++++++ .../services/target_grpc_proxies/client.py | 136 +++++++++++++++++ .../services/target_http_proxies/client.py | 136 +++++++++++++++++ .../services/target_https_proxies/client.py | 136 +++++++++++++++++ .../services/target_instances/client.py | 136 +++++++++++++++++ .../services/target_pools/client.py | 136 +++++++++++++++++ .../services/target_ssl_proxies/client.py | 136 +++++++++++++++++ .../services/target_tcp_proxies/client.py | 136 +++++++++++++++++ .../services/target_vpn_gateways/client.py | 136 +++++++++++++++++ .../compute_v1/services/url_maps/client.py | 136 +++++++++++++++++ .../services/vpn_gateways/client.py | 136 +++++++++++++++++ .../compute_v1/services/vpn_tunnels/client.py | 136 +++++++++++++++++ .../compute_v1/services/wire_groups/client.py | 136 +++++++++++++++++ .../services/zone_operations/client.py | 136 +++++++++++++++++ .../zone_vm_extension_policies/client.py | 136 +++++++++++++++++ .../cloud/compute_v1/services/zones/client.py | 136 +++++++++++++++++ packages/google-cloud-compute/noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-config/noxfile.py | 21 --- .../google-cloud-configdelivery/noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-container/noxfile.py | 21 --- .../google-cloud-containeranalysis/noxfile.py | 21 --- .../google-cloud-contentwarehouse/noxfile.py | 21 --- packages/google-cloud-core/noxfile.py | 20 --- packages/google-cloud-data-fusion/noxfile.py | 21 --- packages/google-cloud-data-qna/noxfile.py | 21 --- .../google-cloud-databasecenter/noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-datacatalog/noxfile.py | 21 --- .../google-cloud-dataflow-client/noxfile.py | 21 --- packages/google-cloud-dataform/noxfile.py | 21 --- packages/google-cloud-datalabeling/noxfile.py | 21 --- packages/google-cloud-dataplex/noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-dataproc/noxfile.py | 21 --- packages/google-cloud-datastore/noxfile.py | 21 --- packages/google-cloud-datastream/noxfile.py | 21 --- packages/google-cloud-deploy/noxfile.py | 21 --- .../google-cloud-developerconnect/noxfile.py | 21 --- .../google-cloud-devicestreaming/noxfile.py | 21 --- .../google-cloud-dialogflow-cx/noxfile.py | 21 --- packages/google-cloud-dialogflow/noxfile.py | 21 --- .../google-cloud-discoveryengine/noxfile.py | 21 --- packages/google-cloud-dlp/noxfile.py | 21 --- packages/google-cloud-dms/noxfile.py | 21 --- packages/google-cloud-dns/noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-documentai/noxfile.py | 21 --- packages/google-cloud-domains/noxfile.py | 21 --- .../google-cloud-edgecontainer/noxfile.py | 21 --- packages/google-cloud-edgenetwork/noxfile.py | 21 --- .../noxfile.py | 21 --- .../google-cloud-error-reporting/noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-eventarc/noxfile.py | 21 --- packages/google-cloud-filestore/noxfile.py | 21 --- .../google-cloud-financialservices/noxfile.py | 21 --- packages/google-cloud-firestore/noxfile.py | 21 --- packages/google-cloud-functions/noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-gke-backup/noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-gke-hub/noxfile.py | 21 --- .../google-cloud-gke-multicloud/noxfile.py | 21 --- .../google-cloud-gkerecommender/noxfile.py | 21 --- packages/google-cloud-gsuiteaddons/noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-iam-logging/noxfile.py | 21 --- packages/google-cloud-iam/noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-iap/noxfile.py | 21 --- packages/google-cloud-ids/noxfile.py | 21 --- .../google-cloud-kms-inventory/noxfile.py | 21 --- .../cloud/kms_v1/services/autokey/client.py | 136 +++++++++++++++++ .../kms_v1/services/autokey_admin/client.py | 136 +++++++++++++++++ .../kms_v1/services/ekm_service/client.py | 136 +++++++++++++++++ .../kms_v1/services/hsm_management/client.py | 136 +++++++++++++++++ .../services/key_management_service/client.py | 136 +++++++++++++++++ packages/google-cloud-kms/noxfile.py | 21 --- packages/google-cloud-language/noxfile.py | 21 --- .../google-cloud-licensemanager/noxfile.py | 21 --- .../google-cloud-life-sciences/noxfile.py | 21 --- .../google-cloud-locationfinder/noxfile.py | 21 --- packages/google-cloud-logging/noxfile.py | 21 --- packages/google-cloud-lustre/noxfile.py | 21 --- .../google-cloud-maintenance-api/noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-managedkafka/noxfile.py | 21 --- .../google-cloud-media-translation/noxfile.py | 21 --- packages/google-cloud-memcache/noxfile.py | 21 --- packages/google-cloud-memorystore/noxfile.py | 21 --- .../google-cloud-migrationcenter/noxfile.py | 21 --- packages/google-cloud-modelarmor/noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-monitoring/noxfile.py | 21 --- packages/google-cloud-ndb/noxfile.py | 21 --- packages/google-cloud-netapp/noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- .../google-cloud-network-security/noxfile.py | 21 --- .../google-cloud-network-services/noxfile.py | 21 --- packages/google-cloud-notebooks/noxfile.py | 21 --- packages/google-cloud-optimization/noxfile.py | 21 --- .../google-cloud-oracledatabase/noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-org-policy/noxfile.py | 21 --- packages/google-cloud-os-config/noxfile.py | 21 --- packages/google-cloud-os-login/noxfile.py | 21 --- .../google-cloud-parallelstore/noxfile.py | 21 --- .../google-cloud-parametermanager/noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- .../google-cloud-policysimulator/noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-private-ca/noxfile.py | 21 --- .../google-cloud-private-catalog/noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-pubsub/noxfile.py | 21 --- packages/google-cloud-quotas/noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-recommender/noxfile.py | 21 --- .../google-cloud-redis-cluster/noxfile.py | 21 --- packages/google-cloud-redis/noxfile.py | 21 --- .../google-cloud-resource-manager/noxfile.py | 21 --- packages/google-cloud-retail/noxfile.py | 21 --- packages/google-cloud-run/noxfile.py | 21 --- .../google-cloud-runtimeconfig/noxfile.py | 20 --- .../noxfile.py | 21 --- packages/google-cloud-scheduler/noxfile.py | 21 --- .../google-cloud-secret-manager/noxfile.py | 21 --- .../noxfile.py | 21 --- .../google-cloud-security-publicca/noxfile.py | 21 --- .../google-cloud-securitycenter/noxfile.py | 21 --- .../noxfile.py | 21 --- .../google-cloud-service-control/noxfile.py | 21 --- .../google-cloud-service-directory/noxfile.py | 21 --- .../noxfile.py | 21 --- .../google-cloud-service-usage/noxfile.py | 21 --- .../google-cloud-servicehealth/noxfile.py | 21 --- packages/google-cloud-shell/noxfile.py | 21 --- .../google-cloud-source-context/noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-spanner/noxfile.py | 21 --- packages/google-cloud-speech/noxfile.py | 21 --- .../google-cloud-storage-control/noxfile.py | 21 --- .../google-cloud-storage-transfer/noxfile.py | 21 --- packages/google-cloud-storage/noxfile.py | 21 --- .../noxfile.py | 21 --- .../google-cloud-storageinsights/noxfile.py | 21 --- packages/google-cloud-support/noxfile.py | 21 --- packages/google-cloud-talent/noxfile.py | 21 --- packages/google-cloud-tasks/noxfile.py | 21 --- .../google-cloud-telcoautomation/noxfile.py | 21 --- packages/google-cloud-testutils/noxfile.py | 21 --- packages/google-cloud-texttospeech/noxfile.py | 21 --- packages/google-cloud-tpu/noxfile.py | 21 --- packages/google-cloud-trace/noxfile.py | 21 --- packages/google-cloud-translate/noxfile.py | 21 --- packages/google-cloud-vectorsearch/noxfile.py | 21 --- .../google-cloud-video-live-stream/noxfile.py | 21 --- .../google-cloud-video-stitcher/noxfile.py | 21 --- .../google-cloud-video-transcoder/noxfile.py | 21 --- .../google-cloud-videointelligence/noxfile.py | 21 --- packages/google-cloud-vision/noxfile.py | 21 --- packages/google-cloud-visionai/noxfile.py | 21 --- packages/google-cloud-vm-migration/noxfile.py | 21 --- packages/google-cloud-vmwareengine/noxfile.py | 21 --- packages/google-cloud-vpc-access/noxfile.py | 21 --- packages/google-cloud-webrisk/noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-cloud-workflows/noxfile.py | 21 --- .../google-cloud-workloadmanager/noxfile.py | 21 --- packages/google-cloud-workstations/noxfile.py | 21 --- .../google-developer-knowledge/noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-geo-type/noxfile.py | 21 --- .../google-maps-addressvalidation/noxfile.py | 21 --- packages/google-maps-areainsights/noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-maps-fleetengine/noxfile.py | 21 --- packages/google-maps-geocode/noxfile.py | 21 --- packages/google-maps-mapmanagement/noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-maps-navconnect/noxfile.py | 21 --- packages/google-maps-places/noxfile.py | 21 --- .../google-maps-routeoptimization/noxfile.py | 21 --- packages/google-maps-routing/noxfile.py | 21 --- packages/google-maps-solar/noxfile.py | 21 --- packages/google-resumable-media/noxfile.py | 21 --- packages/google-shopping-css/noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- .../google-shopping-merchant-lfp/noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- .../google-shopping-merchant-quota/noxfile.py | 21 --- .../noxfile.py | 21 --- .../noxfile.py | 21 --- packages/google-shopping-type/noxfile.py | 21 --- packages/googleapis-common-protos/noxfile.py | 21 --- packages/grafeas/noxfile.py | 21 --- packages/grpc-google-iam-v1/noxfile.py | 21 --- packages/pandas-gbq/noxfile.py | 21 --- packages/proto-plus/noxfile.py | 20 --- packages/sqlalchemy-bigquery/noxfile.py | 21 --- packages/sqlalchemy-spanner/noxfile.py | 21 --- 418 files changed, 17427 insertions(+), 6093 deletions(-) diff --git a/packages/bigframes/noxfile.py b/packages/bigframes/noxfile.py index e1d19d697dd3..0a33264aa8ea 100644 --- a/packages/bigframes/noxfile.py +++ b/packages/bigframes/noxfile.py @@ -44,7 +44,6 @@ "3.10", # colab.research.google.com "3.11", - "import_profile", ] PYTEST_VERSION = "pytest==8.4.2" @@ -1093,23 +1092,3 @@ def mypy(session): "--explicit-package-bases", '--exclude="^third_party"', ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/bigquery-magics/noxfile.py b/packages/bigquery-magics/noxfile.py index f5f3f9206f8f..f275406b6905 100644 --- a/packages/bigquery-magics/noxfile.py +++ b/packages/bigquery-magics/noxfile.py @@ -41,7 +41,6 @@ "3.12", "3.13", "3.14", - "import_profile", ] UNIT_TEST_STANDARD_DEPENDENCIES = [ @@ -547,23 +546,3 @@ def mypy(session): # TODO(https://github.com/googleapis/google-cloud-python/issues/16014): # Add mypy tests session.skip("mypy tests are not yet supported") - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/db-dtypes/noxfile.py b/packages/db-dtypes/noxfile.py index 67c478ffb0a7..b80b1df6832a 100644 --- a/packages/db-dtypes/noxfile.py +++ b/packages/db-dtypes/noxfile.py @@ -42,7 +42,6 @@ "3.12", "3.13", "3.14", - "import_profile", ] UNIT_TEST_STANDARD_DEPENDENCIES = [ @@ -548,23 +547,3 @@ def mypy(session): "--ignore-missing-imports", *session.posargs, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/django-google-spanner/noxfile.py b/packages/django-google-spanner/noxfile.py index af0483e1e7c1..0b94e5b87bff 100644 --- a/packages/django-google-spanner/noxfile.py +++ b/packages/django-google-spanner/noxfile.py @@ -491,23 +491,3 @@ def format(session: nox.sessions.Session) -> None: "--line-length=88", # Standard Black line length *LINT_PATHS, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/gapic-generator/gapic/templates/noxfile.py.j2 b/packages/gapic-generator/gapic/templates/noxfile.py.j2 index 559adfa0c3e4..8db595319396 100644 --- a/packages/gapic-generator/gapic/templates/noxfile.py.j2 +++ b/packages/gapic-generator/gapic/templates/noxfile.py.j2 @@ -86,7 +86,6 @@ nox.options.sessions = [ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -642,35 +641,4 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - {% if api.naming.module_namespace %} - session.run( - "python", - str(profiler_script), - "--module", - "{{ api.naming.module_namespace[0] }}", - "--iterations", - "10", - ) - {% else %} - session.run( - "python", - str(profiler_script), - "--module", - "{{ api.naming.versioned_module_name }}", - "--iterations", - "10", - ) - {% endif %} {% endblock %} diff --git a/packages/gapic-generator/noxfile.py b/packages/gapic-generator/noxfile.py index 23b1734808b8..6fac5c48853d 100644 --- a/packages/gapic-generator/noxfile.py +++ b/packages/gapic-generator/noxfile.py @@ -847,23 +847,4 @@ def core_deps_from_source(session, protobuf_implementation): """Run all tests with core dependencies installed from source.""" # TODO(https://github.com/googleapis/google-cloud-python/issues/16185): # Implement logic to install core packages directly from the mono-repo directories. - session.skip("core_deps_from_source session is not yet implemented for gapic-generator-python.") - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) + session.skip("core_deps_from_source session is not yet implemented for gapic-generator-python.") \ No newline at end of file diff --git a/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py b/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py index 1c803e263c79..09d28712c73c 100755 --- a/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py @@ -93,7 +93,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -634,23 +633,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py b/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py index 3ffe0439c0bb..65e26efe21d3 100755 --- a/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py @@ -93,7 +93,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -634,23 +633,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py b/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py index 3dd516951f0d..42b2349e2cc1 100755 --- a/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py @@ -93,7 +93,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -634,23 +633,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py b/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py index 208d95f44b76..09e4b345592a 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py @@ -93,7 +93,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -634,23 +633,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py b/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py index 208d95f44b76..09e4b345592a 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py @@ -93,7 +93,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -634,23 +633,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py b/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py index ef6419e5dee9..9b3356dd1272 100755 --- a/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py @@ -93,7 +93,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -634,23 +633,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py b/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py index ef6419e5dee9..9b3356dd1272 100755 --- a/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py @@ -93,7 +93,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -634,23 +633,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py b/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py index bb885d07c222..db370dd3dd0f 100755 --- a/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py @@ -93,7 +93,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -634,23 +633,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/gcp-sphinx-docfx-yaml/noxfile.py b/packages/gcp-sphinx-docfx-yaml/noxfile.py index acc6492c90b9..ba5658c0e24f 100644 --- a/packages/gcp-sphinx-docfx-yaml/noxfile.py +++ b/packages/gcp-sphinx-docfx-yaml/noxfile.py @@ -32,7 +32,6 @@ "docs", "prerelease_deps", "core_deps_from_source", - "import_profile", ] @@ -174,23 +173,3 @@ def docfx(session): "DocFX build postponed during migration. " "Requires resolution of Sphinx 1.5.5 / Jinja2 compatibility." ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-ads-admanager/noxfile.py b/packages/google-ads-admanager/noxfile.py index dedf4a9af166..266ed37fd871 100644 --- a/packages/google-ads-admanager/noxfile.py +++ b/packages/google-ads-admanager/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-ads-datamanager/noxfile.py b/packages/google-ads-datamanager/noxfile.py index fce0cb56742b..f2936e9406bd 100644 --- a/packages/google-ads-datamanager/noxfile.py +++ b/packages/google-ads-datamanager/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-ads-marketingplatform-admin/noxfile.py b/packages/google-ads-marketingplatform-admin/noxfile.py index 06f87547da63..6671718f045c 100644 --- a/packages/google-ads-marketingplatform-admin/noxfile.py +++ b/packages/google-ads-marketingplatform-admin/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-ai-generativelanguage/noxfile.py b/packages/google-ai-generativelanguage/noxfile.py index 7c1eabfdac45..770a51d82198 100644 --- a/packages/google-ai-generativelanguage/noxfile.py +++ b/packages/google-ai-generativelanguage/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-analytics-admin/noxfile.py b/packages/google-analytics-admin/noxfile.py index d124274c02bb..c1cb27ce5fce 100644 --- a/packages/google-analytics-admin/noxfile.py +++ b/packages/google-analytics-admin/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-analytics-data/noxfile.py b/packages/google-analytics-data/noxfile.py index b6fc40f24fb0..0fcdca3b449b 100644 --- a/packages/google-analytics-data/noxfile.py +++ b/packages/google-analytics-data/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-api-core/noxfile.py b/packages/google-api-core/noxfile.py index 023ca033f95b..0bad668a80dd 100644 --- a/packages/google-api-core/noxfile.py +++ b/packages/google-api-core/noxfile.py @@ -464,23 +464,3 @@ def docfx(session): os.path.join("docs", ""), os.path.join("docs", "_build", "html", ""), ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-apps-card/noxfile.py b/packages/google-apps-card/noxfile.py index bebe7006874c..07e5821e034b 100644 --- a/packages/google-apps-card/noxfile.py +++ b/packages/google-apps-card/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-apps-chat/noxfile.py b/packages/google-apps-chat/noxfile.py index d91d3274fefe..068d9b29104c 100644 --- a/packages/google-apps-chat/noxfile.py +++ b/packages/google-apps-chat/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-apps-events-subscriptions/noxfile.py b/packages/google-apps-events-subscriptions/noxfile.py index 52a64de822c5..13b14c1d293c 100644 --- a/packages/google-apps-events-subscriptions/noxfile.py +++ b/packages/google-apps-events-subscriptions/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-apps-meet/noxfile.py b/packages/google-apps-meet/noxfile.py index 81fc96da0710..e10102a15d42 100644 --- a/packages/google-apps-meet/noxfile.py +++ b/packages/google-apps-meet/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-apps-script-type/noxfile.py b/packages/google-apps-script-type/noxfile.py index 1588a173aeff..a40e278a5761 100644 --- a/packages/google-apps-script-type/noxfile.py +++ b/packages/google-apps-script-type/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-area120-tables/noxfile.py b/packages/google-area120-tables/noxfile.py index 2f5ccdd80edb..4bcfad6e486e 100644 --- a/packages/google-area120-tables/noxfile.py +++ b/packages/google-area120-tables/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-auth-httplib2/noxfile.py b/packages/google-auth-httplib2/noxfile.py index 53cfa9f1153d..67b1bd420cc5 100644 --- a/packages/google-auth-httplib2/noxfile.py +++ b/packages/google-auth-httplib2/noxfile.py @@ -529,23 +529,3 @@ def core_deps_from_source(session): system_test_folder_path, *session.posargs, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-auth-oauthlib/noxfile.py b/packages/google-auth-oauthlib/noxfile.py index 4ccf6a8fe0b6..a028eb1f1900 100644 --- a/packages/google-auth-oauthlib/noxfile.py +++ b/packages/google-auth-oauthlib/noxfile.py @@ -474,23 +474,3 @@ def mypy(session): "-p", "google_auth_oauthlib", ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-auth/noxfile.py b/packages/google-auth/noxfile.py index 78894295de10..19cc47a02a03 100644 --- a/packages/google-auth/noxfile.py +++ b/packages/google-auth/noxfile.py @@ -69,7 +69,6 @@ "mypy", # cover must be last to avoid error `No data to report` "docs", - "import_profile", ] @@ -315,23 +314,3 @@ def core_deps_from_source(session): rather than pulling the dependencies from PyPI. """ session.skip("Skipping: Not applicable for google-auth.") - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-backstory/noxfile.py b/packages/google-backstory/noxfile.py index 1d72118c0ac5..44eaafe8e0f6 100644 --- a/packages/google-backstory/noxfile.py +++ b/packages/google-backstory/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-access-approval/noxfile.py b/packages/google-cloud-access-approval/noxfile.py index cb79279e0192..82e2a49f059d 100644 --- a/packages/google-cloud-access-approval/noxfile.py +++ b/packages/google-cloud-access-approval/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-access-context-manager/noxfile.py b/packages/google-cloud-access-context-manager/noxfile.py index 483619fa4bb6..b6ae8c821dca 100644 --- a/packages/google-cloud-access-context-manager/noxfile.py +++ b/packages/google-cloud-access-context-manager/noxfile.py @@ -85,7 +85,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -578,23 +577,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-advisorynotifications/noxfile.py b/packages/google-cloud-advisorynotifications/noxfile.py index 16ccdb125282..af26b1ac1af3 100644 --- a/packages/google-cloud-advisorynotifications/noxfile.py +++ b/packages/google-cloud-advisorynotifications/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-agentidentitycredentials/noxfile.py b/packages/google-cloud-agentidentitycredentials/noxfile.py index 0653b5357af3..e7d8e25739ad 100644 --- a/packages/google-cloud-agentidentitycredentials/noxfile.py +++ b/packages/google-cloud-agentidentitycredentials/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-agentregistry/noxfile.py b/packages/google-cloud-agentregistry/noxfile.py index 534109007b92..30cc228cfbd6 100644 --- a/packages/google-cloud-agentregistry/noxfile.py +++ b/packages/google-cloud-agentregistry/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-alloydb-connectors/noxfile.py b/packages/google-cloud-alloydb-connectors/noxfile.py index a6f9deae5574..a050f3c1881d 100644 --- a/packages/google-cloud-alloydb-connectors/noxfile.py +++ b/packages/google-cloud-alloydb-connectors/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-alloydb/noxfile.py b/packages/google-cloud-alloydb/noxfile.py index 0f9cd5463ba8..1f0b150ae2c6 100644 --- a/packages/google-cloud-alloydb/noxfile.py +++ b/packages/google-cloud-alloydb/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-api-gateway/noxfile.py b/packages/google-cloud-api-gateway/noxfile.py index ffb5de8245dc..5d48da9f9b29 100644 --- a/packages/google-cloud-api-gateway/noxfile.py +++ b/packages/google-cloud-api-gateway/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-api-keys/noxfile.py b/packages/google-cloud-api-keys/noxfile.py index c0e711a79270..086c9842c20b 100644 --- a/packages/google-cloud-api-keys/noxfile.py +++ b/packages/google-cloud-api-keys/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-apigee-connect/noxfile.py b/packages/google-cloud-apigee-connect/noxfile.py index 949315ae5280..3d316ce17189 100644 --- a/packages/google-cloud-apigee-connect/noxfile.py +++ b/packages/google-cloud-apigee-connect/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-apigee-registry/noxfile.py b/packages/google-cloud-apigee-registry/noxfile.py index 6b1bb29a59d9..48e99b7dc8f1 100644 --- a/packages/google-cloud-apigee-registry/noxfile.py +++ b/packages/google-cloud-apigee-registry/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-apihub/noxfile.py b/packages/google-cloud-apihub/noxfile.py index b56e806797b3..ce015b92c88c 100644 --- a/packages/google-cloud-apihub/noxfile.py +++ b/packages/google-cloud-apihub/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-apiregistry/noxfile.py b/packages/google-cloud-apiregistry/noxfile.py index 3ce22aaf2fa0..eea4a81bee54 100644 --- a/packages/google-cloud-apiregistry/noxfile.py +++ b/packages/google-cloud-apiregistry/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-appengine-admin/noxfile.py b/packages/google-cloud-appengine-admin/noxfile.py index f9d53da73541..ab3410edfff2 100644 --- a/packages/google-cloud-appengine-admin/noxfile.py +++ b/packages/google-cloud-appengine-admin/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-appengine-logging/noxfile.py b/packages/google-cloud-appengine-logging/noxfile.py index 16dd777064dc..9d295bb84faa 100644 --- a/packages/google-cloud-appengine-logging/noxfile.py +++ b/packages/google-cloud-appengine-logging/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-apphub/noxfile.py b/packages/google-cloud-apphub/noxfile.py index ca2360c35ec2..1ef74909a0de 100644 --- a/packages/google-cloud-apphub/noxfile.py +++ b/packages/google-cloud-apphub/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-appoptimize/noxfile.py b/packages/google-cloud-appoptimize/noxfile.py index 45c2eeaf7fca..00436f115a7e 100644 --- a/packages/google-cloud-appoptimize/noxfile.py +++ b/packages/google-cloud-appoptimize/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-artifact-registry/noxfile.py b/packages/google-cloud-artifact-registry/noxfile.py index 7bf0895ac528..a5ca48ed78cc 100644 --- a/packages/google-cloud-artifact-registry/noxfile.py +++ b/packages/google-cloud-artifact-registry/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-asset/noxfile.py b/packages/google-cloud-asset/noxfile.py index 66c26df2b9c2..b044cb25e9bd 100644 --- a/packages/google-cloud-asset/noxfile.py +++ b/packages/google-cloud-asset/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-assured-workloads/noxfile.py b/packages/google-cloud-assured-workloads/noxfile.py index 63f6191e1870..a643c7d6ccd9 100644 --- a/packages/google-cloud-assured-workloads/noxfile.py +++ b/packages/google-cloud-assured-workloads/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-audit-log/noxfile.py b/packages/google-cloud-audit-log/noxfile.py index a188e4b9bfb4..4724255759ff 100644 --- a/packages/google-cloud-audit-log/noxfile.py +++ b/packages/google-cloud-audit-log/noxfile.py @@ -85,7 +85,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -564,23 +563,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-auditmanager/noxfile.py b/packages/google-cloud-auditmanager/noxfile.py index 51f30d8928d7..20b95fcccee0 100644 --- a/packages/google-cloud-auditmanager/noxfile.py +++ b/packages/google-cloud-auditmanager/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-automl/noxfile.py b/packages/google-cloud-automl/noxfile.py index b5bb029dbad0..a819955ec879 100644 --- a/packages/google-cloud-automl/noxfile.py +++ b/packages/google-cloud-automl/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -639,23 +638,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-backupdr/noxfile.py b/packages/google-cloud-backupdr/noxfile.py index 509ca140eb4a..6a226a08584d 100644 --- a/packages/google-cloud-backupdr/noxfile.py +++ b/packages/google-cloud-backupdr/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-bare-metal-solution/noxfile.py b/packages/google-cloud-bare-metal-solution/noxfile.py index fb7e646b60a6..ff32011b2c06 100644 --- a/packages/google-cloud-bare-metal-solution/noxfile.py +++ b/packages/google-cloud-bare-metal-solution/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-batch/noxfile.py b/packages/google-cloud-batch/noxfile.py index 423254fd4bae..976947da12cf 100644 --- a/packages/google-cloud-batch/noxfile.py +++ b/packages/google-cloud-batch/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-beyondcorp-appconnections/noxfile.py b/packages/google-cloud-beyondcorp-appconnections/noxfile.py index 6762f78a0d4b..b4957d8a7c4b 100644 --- a/packages/google-cloud-beyondcorp-appconnections/noxfile.py +++ b/packages/google-cloud-beyondcorp-appconnections/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-beyondcorp-appconnectors/noxfile.py b/packages/google-cloud-beyondcorp-appconnectors/noxfile.py index 899b14f44e0f..7b8f48b26a26 100644 --- a/packages/google-cloud-beyondcorp-appconnectors/noxfile.py +++ b/packages/google-cloud-beyondcorp-appconnectors/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-beyondcorp-appgateways/noxfile.py b/packages/google-cloud-beyondcorp-appgateways/noxfile.py index 150de37e1c53..dd399e3a0da4 100644 --- a/packages/google-cloud-beyondcorp-appgateways/noxfile.py +++ b/packages/google-cloud-beyondcorp-appgateways/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py b/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py index affe8c1e5fa3..60ca6ca1fcb1 100644 --- a/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py +++ b/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-beyondcorp-clientgateways/noxfile.py b/packages/google-cloud-beyondcorp-clientgateways/noxfile.py index 2cf2de669ea3..b97d73b7ebe9 100644 --- a/packages/google-cloud-beyondcorp-clientgateways/noxfile.py +++ b/packages/google-cloud-beyondcorp-clientgateways/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-biglake-hive/noxfile.py b/packages/google-cloud-biglake-hive/noxfile.py index 5e0a9d4771d4..77c7118d3dfd 100644 --- a/packages/google-cloud-biglake-hive/noxfile.py +++ b/packages/google-cloud-biglake-hive/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-biglake/noxfile.py b/packages/google-cloud-biglake/noxfile.py index 3e3c60e4ff33..1ebc50a53211 100644 --- a/packages/google-cloud-biglake/noxfile.py +++ b/packages/google-cloud-biglake/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-bigquery-analyticshub/noxfile.py b/packages/google-cloud-bigquery-analyticshub/noxfile.py index f35a43e2d54f..be6693d95ee7 100644 --- a/packages/google-cloud-bigquery-analyticshub/noxfile.py +++ b/packages/google-cloud-bigquery-analyticshub/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-bigquery-biglake/noxfile.py b/packages/google-cloud-bigquery-biglake/noxfile.py index af6a9bcbb63e..0e743d519c6b 100644 --- a/packages/google-cloud-bigquery-biglake/noxfile.py +++ b/packages/google-cloud-bigquery-biglake/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-bigquery-connection/noxfile.py b/packages/google-cloud-bigquery-connection/noxfile.py index fe9a15a7769d..b6a28dbb4efc 100644 --- a/packages/google-cloud-bigquery-connection/noxfile.py +++ b/packages/google-cloud-bigquery-connection/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-bigquery-data-exchange/noxfile.py b/packages/google-cloud-bigquery-data-exchange/noxfile.py index 51333110286f..fb619fb7bb1a 100644 --- a/packages/google-cloud-bigquery-data-exchange/noxfile.py +++ b/packages/google-cloud-bigquery-data-exchange/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-bigquery-datapolicies/noxfile.py b/packages/google-cloud-bigquery-datapolicies/noxfile.py index 813fa958c67c..aabe19bd4e27 100644 --- a/packages/google-cloud-bigquery-datapolicies/noxfile.py +++ b/packages/google-cloud-bigquery-datapolicies/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-bigquery-datatransfer/noxfile.py b/packages/google-cloud-bigquery-datatransfer/noxfile.py index 998be4f9941b..44d603729ba5 100644 --- a/packages/google-cloud-bigquery-datatransfer/noxfile.py +++ b/packages/google-cloud-bigquery-datatransfer/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-bigquery-logging/noxfile.py b/packages/google-cloud-bigquery-logging/noxfile.py index eb34c32918e4..357903bd6d52 100644 --- a/packages/google-cloud-bigquery-logging/noxfile.py +++ b/packages/google-cloud-bigquery-logging/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-bigquery-migration/noxfile.py b/packages/google-cloud-bigquery-migration/noxfile.py index 672bc32f4cad..4b9be68bf2a8 100644 --- a/packages/google-cloud-bigquery-migration/noxfile.py +++ b/packages/google-cloud-bigquery-migration/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-bigquery-reservation/noxfile.py b/packages/google-cloud-bigquery-reservation/noxfile.py index abd5d5622e5b..839f10246119 100644 --- a/packages/google-cloud-bigquery-reservation/noxfile.py +++ b/packages/google-cloud-bigquery-reservation/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-bigquery-storage/noxfile.py b/packages/google-cloud-bigquery-storage/noxfile.py index fb0b29834a7d..4ec53338e333 100644 --- a/packages/google-cloud-bigquery-storage/noxfile.py +++ b/packages/google-cloud-bigquery-storage/noxfile.py @@ -99,7 +99,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -679,23 +678,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-bigquery/noxfile.py b/packages/google-cloud-bigquery/noxfile.py index 7fcc5a45c65b..c1dd1692b744 100644 --- a/packages/google-cloud-bigquery/noxfile.py +++ b/packages/google-cloud-bigquery/noxfile.py @@ -79,7 +79,6 @@ def wrapper(*args, **kwargs): "docs", "core_deps_from_source", "format", - "import_profile", ] @@ -587,23 +586,3 @@ def format(session: nox.sessions.Session) -> None: # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections session.run("isort", "--fss", *python_files) session.run("black", *python_files) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-bigtable/noxfile.py b/packages/google-cloud-bigtable/noxfile.py index 7bc65f3aad28..e6ef8c1e9911 100644 --- a/packages/google-cloud-bigtable/noxfile.py +++ b/packages/google-cloud-bigtable/noxfile.py @@ -33,7 +33,6 @@ "3.12", "3.13", "3.14", - "import_profile", ] UNIT_TEST_STANDARD_DEPENDENCIES = [ @@ -626,23 +625,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-billing-budgets/noxfile.py b/packages/google-cloud-billing-budgets/noxfile.py index 1be9282c4107..d1f4e6341b46 100644 --- a/packages/google-cloud-billing-budgets/noxfile.py +++ b/packages/google-cloud-billing-budgets/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-billing/noxfile.py b/packages/google-cloud-billing/noxfile.py index 225e3cb8b8d0..3f1f9d83aaf2 100644 --- a/packages/google-cloud-billing/noxfile.py +++ b/packages/google-cloud-billing/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-binary-authorization/noxfile.py b/packages/google-cloud-binary-authorization/noxfile.py index 98df4a170fb8..4ed4e5ad9604 100644 --- a/packages/google-cloud-binary-authorization/noxfile.py +++ b/packages/google-cloud-binary-authorization/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-build/noxfile.py b/packages/google-cloud-build/noxfile.py index 27903d1557d1..a0694e258d3f 100644 --- a/packages/google-cloud-build/noxfile.py +++ b/packages/google-cloud-build/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-capacityplanner/noxfile.py b/packages/google-cloud-capacityplanner/noxfile.py index 4c4a2846fb76..100e4db93531 100644 --- a/packages/google-cloud-capacityplanner/noxfile.py +++ b/packages/google-cloud-capacityplanner/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-certificate-manager/noxfile.py b/packages/google-cloud-certificate-manager/noxfile.py index 6a89dd993586..7d2237416f29 100644 --- a/packages/google-cloud-certificate-manager/noxfile.py +++ b/packages/google-cloud-certificate-manager/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-ces/noxfile.py b/packages/google-cloud-ces/noxfile.py index 6af691d14416..e52903354c45 100644 --- a/packages/google-cloud-ces/noxfile.py +++ b/packages/google-cloud-ces/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-channel/noxfile.py b/packages/google-cloud-channel/noxfile.py index b4fcb61e2175..026a1cb20eec 100644 --- a/packages/google-cloud-channel/noxfile.py +++ b/packages/google-cloud-channel/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-chronicle/noxfile.py b/packages/google-cloud-chronicle/noxfile.py index c4b902bf9cea..0bd323608bc8 100644 --- a/packages/google-cloud-chronicle/noxfile.py +++ b/packages/google-cloud-chronicle/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-cloudcontrolspartner/noxfile.py b/packages/google-cloud-cloudcontrolspartner/noxfile.py index 823ac102f951..26cc3368c7ba 100644 --- a/packages/google-cloud-cloudcontrolspartner/noxfile.py +++ b/packages/google-cloud-cloudcontrolspartner/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-cloudsecuritycompliance/noxfile.py b/packages/google-cloud-cloudsecuritycompliance/noxfile.py index d71fb1681f69..5f79e1a8c2b5 100644 --- a/packages/google-cloud-cloudsecuritycompliance/noxfile.py +++ b/packages/google-cloud-cloudsecuritycompliance/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-commerce-consumer-procurement/noxfile.py b/packages/google-cloud-commerce-consumer-procurement/noxfile.py index 3f4e5b58d11e..620844bc9d4f 100644 --- a/packages/google-cloud-commerce-consumer-procurement/noxfile.py +++ b/packages/google-cloud-commerce-consumer-procurement/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-common/noxfile.py b/packages/google-cloud-common/noxfile.py index 8517cce890b5..58d097ef35dc 100644 --- a/packages/google-cloud-common/noxfile.py +++ b/packages/google-cloud-common/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-compute-v1beta/noxfile.py b/packages/google-cloud-compute-v1beta/noxfile.py index 7602aa435af2..b0d0ee4f53ec 100644 --- a/packages/google-cloud-compute-v1beta/noxfile.py +++ b/packages/google-cloud-compute-v1beta/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/client.py index de282d391164..44d7a9d7ef1d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/client.py @@ -107,8 +107,78 @@ class AcceleratorTypesClient(metaclass=AcceleratorTypesClientMeta): The AcceleratorTypes API. """ + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = AcceleratorTypesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = AcceleratorTypesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/client.py index f63466bebb84..c2205e17b4a4 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/client.py @@ -107,8 +107,78 @@ def get_transport_class( class AddressesClient(metaclass=AddressesClientMeta): """The Addresses API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = AddressesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = AddressesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/client.py index bfb0336b17ff..362935f10dbb 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/client.py @@ -103,8 +103,78 @@ def get_transport_class( class AdviceClient(metaclass=AdviceClientMeta): """The Advice API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -296,7 +366,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = AdviceClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -330,6 +442,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = AdviceClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/client.py index 1c146245a8ef..22d5a049eb86 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/client.py @@ -107,8 +107,78 @@ def get_transport_class( class AutoscalersClient(metaclass=AutoscalersClientMeta): """The Autoscalers API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = AutoscalersClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = AutoscalersClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/client.py index cbb9d3cbca3e..f77441762c9d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/client.py @@ -107,8 +107,78 @@ def get_transport_class( class BackendBucketsClient(metaclass=BackendBucketsClientMeta): """The BackendBuckets API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = BackendBucketsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = BackendBucketsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/client.py index aea425ebffe7..8ad2520d3988 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/client.py @@ -107,8 +107,78 @@ def get_transport_class( class BackendServicesClient(metaclass=BackendServicesClientMeta): """The BackendServices API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = BackendServicesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = BackendServicesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/client.py index 00c37a250bed..f0fb6b654b69 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/client.py @@ -107,8 +107,78 @@ def get_transport_class( class CrossSiteNetworksClient(metaclass=CrossSiteNetworksClientMeta): """The CrossSiteNetworks API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = CrossSiteNetworksClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = CrossSiteNetworksClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/client.py index ae9d9ea41fde..40b595d9c103 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/client.py @@ -104,8 +104,78 @@ def get_transport_class( class DiskTypesClient(metaclass=DiskTypesClientMeta): """The DiskTypes API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -297,7 +367,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = DiskTypesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -331,6 +443,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = DiskTypesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/client.py index 57ed7f860e4a..88dfa387504d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/client.py @@ -107,8 +107,78 @@ def get_transport_class( class DisksClient(metaclass=DisksClientMeta): """The Disks API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = DisksClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = DisksClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/client.py index 5c867a544138..8779b0133c7e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/client.py @@ -107,8 +107,78 @@ def get_transport_class( class ExternalVpnGatewaysClient(metaclass=ExternalVpnGatewaysClientMeta): """The ExternalVpnGateways API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = ExternalVpnGatewaysClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = ExternalVpnGatewaysClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/client.py index 08277e8c49bd..28ca5cbc2c25 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/client.py @@ -107,8 +107,78 @@ def get_transport_class( class FirewallPoliciesClient(metaclass=FirewallPoliciesClientMeta): """The FirewallPolicies API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = FirewallPoliciesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = FirewallPoliciesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/client.py index 089050d5171d..a504fd9de6d4 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/client.py @@ -107,8 +107,78 @@ def get_transport_class( class FirewallsClient(metaclass=FirewallsClientMeta): """The Firewalls API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = FirewallsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = FirewallsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/client.py index 75550b11f653..191c56a8e24f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/client.py @@ -107,8 +107,78 @@ def get_transport_class( class ForwardingRulesClient(metaclass=ForwardingRulesClientMeta): """The ForwardingRules API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = ForwardingRulesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = ForwardingRulesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/client.py index a4f7f35aae8f..c9738a8588da 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/client.py @@ -107,8 +107,78 @@ def get_transport_class( class FutureReservationsClient(metaclass=FutureReservationsClientMeta): """The FutureReservations API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = FutureReservationsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = FutureReservationsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/client.py index 61e6de20074d..bef4af1a0780 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/client.py @@ -107,8 +107,78 @@ def get_transport_class( class GlobalAddressesClient(metaclass=GlobalAddressesClientMeta): """The GlobalAddresses API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = GlobalAddressesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = GlobalAddressesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/client.py index a216c257aa16..05a682d32237 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/client.py @@ -107,8 +107,78 @@ def get_transport_class( class GlobalForwardingRulesClient(metaclass=GlobalForwardingRulesClientMeta): """The GlobalForwardingRules API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = GlobalForwardingRulesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -336,6 +448,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = GlobalForwardingRulesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/client.py index 2994165c6d6b..13eb13fe3642 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/client.py @@ -109,8 +109,78 @@ class GlobalNetworkEndpointGroupsClient( ): """The GlobalNetworkEndpointGroups API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -302,7 +372,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = GlobalNetworkEndpointGroupsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -338,6 +450,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = GlobalNetworkEndpointGroupsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/client.py index 4fe922a30611..1495a1973ec7 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/client.py @@ -104,8 +104,78 @@ def get_transport_class( class GlobalOperationsClient(metaclass=GlobalOperationsClientMeta): """The GlobalOperations API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -297,7 +367,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = GlobalOperationsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -331,6 +443,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = GlobalOperationsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/client.py index 6feb23d9ca5a..2cc2dd94b5dd 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/client.py @@ -106,8 +106,78 @@ class GlobalOrganizationOperationsClient( ): """The GlobalOrganizationOperations API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -301,7 +371,51 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = ( + GlobalOrganizationOperationsClient._use_client_cert_effective() + ) + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -337,6 +451,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = GlobalOrganizationOperationsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/client.py index 435d7468fb06..05f643df0598 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/client.py @@ -109,8 +109,78 @@ class GlobalPublicDelegatedPrefixesClient( ): """The GlobalPublicDelegatedPrefixes API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -304,7 +374,51 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = ( + GlobalPublicDelegatedPrefixesClient._use_client_cert_effective() + ) + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -340,6 +454,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = GlobalPublicDelegatedPrefixesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_vm_extension_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_vm_extension_policies/client.py index 838c17fb5f90..b4bac1c56dae 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_vm_extension_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_vm_extension_policies/client.py @@ -107,8 +107,78 @@ def get_transport_class( class GlobalVmExtensionPoliciesClient(metaclass=GlobalVmExtensionPoliciesClientMeta): """The GlobalVmExtensionPolicies API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = GlobalVmExtensionPoliciesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -336,6 +448,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = GlobalVmExtensionPoliciesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/client.py index 4a7f6660bdf5..035ddc12cc0f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/client.py @@ -107,8 +107,78 @@ def get_transport_class( class HealthChecksClient(metaclass=HealthChecksClientMeta): """The HealthChecks API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = HealthChecksClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = HealthChecksClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/client.py index b749d6d2034d..55a26f2289e5 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/client.py @@ -103,8 +103,78 @@ def get_transport_class( class ImageFamilyViewsClient(metaclass=ImageFamilyViewsClientMeta): """The ImageFamilyViews API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -296,7 +366,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = ImageFamilyViewsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -330,6 +442,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = ImageFamilyViewsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/images/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/images/client.py index eb087574a470..224756e906fa 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/images/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/images/client.py @@ -107,8 +107,78 @@ def get_transport_class( class ImagesClient(metaclass=ImagesClientMeta): """The Images API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = ImagesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = ImagesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/client.py index 41f3662016bc..09e63bf97f81 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/client.py @@ -114,8 +114,78 @@ class InstanceGroupManagerResizeRequestsClient( ): """The InstanceGroupManagerResizeRequests API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -309,7 +379,51 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = ( + InstanceGroupManagerResizeRequestsClient._use_client_cert_effective() + ) + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -347,6 +461,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = InstanceGroupManagerResizeRequestsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/client.py index 91bf52b5c7c4..984a885e6143 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/client.py @@ -107,8 +107,78 @@ def get_transport_class( class InstanceGroupManagersClient(metaclass=InstanceGroupManagersClientMeta): """The InstanceGroupManagers API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = InstanceGroupManagersClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -336,6 +448,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = InstanceGroupManagersClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/client.py index 90bce83ed152..cf8c6312e63c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/client.py @@ -107,8 +107,78 @@ def get_transport_class( class InstanceGroupsClient(metaclass=InstanceGroupsClientMeta): """The InstanceGroups API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = InstanceGroupsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = InstanceGroupsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/client.py index 62dd8e1b533e..70b7a11df834 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/client.py @@ -106,8 +106,78 @@ def get_transport_class( class InstanceSettingsServiceClient(metaclass=InstanceSettingsServiceClientMeta): """The InstanceSettings API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -299,7 +369,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = InstanceSettingsServiceClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -335,6 +447,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = InstanceSettingsServiceClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/client.py index 4924539ca9c5..a662cf02bc60 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/client.py @@ -107,8 +107,78 @@ def get_transport_class( class InstanceTemplatesClient(metaclass=InstanceTemplatesClientMeta): """The InstanceTemplates API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = InstanceTemplatesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = InstanceTemplatesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/client.py index 5f9d854e0d3d..25e8fda72057 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/client.py @@ -107,8 +107,78 @@ def get_transport_class( class InstancesClient(metaclass=InstancesClientMeta): """The Instances API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = InstancesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = InstancesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshot_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshot_groups/client.py index 3aaa9b0b3c2b..7ba6f51fcc6f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshot_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshot_groups/client.py @@ -107,8 +107,78 @@ def get_transport_class( class InstantSnapshotGroupsClient(metaclass=InstantSnapshotGroupsClientMeta): """The InstantSnapshotGroups API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = InstantSnapshotGroupsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -336,6 +448,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = InstantSnapshotGroupsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/client.py index b908265225b8..8a34b18a09c0 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/client.py @@ -107,8 +107,78 @@ def get_transport_class( class InstantSnapshotsClient(metaclass=InstantSnapshotsClientMeta): """The InstantSnapshots API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = InstantSnapshotsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = InstantSnapshotsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/client.py index 7fa889126dd0..ad86663097b0 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/client.py @@ -109,8 +109,78 @@ class InterconnectAttachmentGroupsClient( ): """The InterconnectAttachmentGroups API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -304,7 +374,51 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = ( + InterconnectAttachmentGroupsClient._use_client_cert_effective() + ) + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -340,6 +454,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = InterconnectAttachmentGroupsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/client.py index e59d156bee73..6cacb5b66bf4 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/client.py @@ -107,8 +107,78 @@ def get_transport_class( class InterconnectAttachmentsClient(metaclass=InterconnectAttachmentsClientMeta): """The InterconnectAttachments API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = InterconnectAttachmentsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -336,6 +448,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = InterconnectAttachmentsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/client.py index 144fa89a3934..908821897454 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/client.py @@ -107,8 +107,78 @@ def get_transport_class( class InterconnectGroupsClient(metaclass=InterconnectGroupsClientMeta): """The InterconnectGroups API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = InterconnectGroupsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = InterconnectGroupsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/client.py index 44f162081bf8..214d6fd34d8e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/client.py @@ -104,8 +104,78 @@ def get_transport_class( class InterconnectLocationsClient(metaclass=InterconnectLocationsClientMeta): """The InterconnectLocations API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -297,7 +367,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = InterconnectLocationsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -333,6 +445,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = InterconnectLocationsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/client.py index 70ec0ee69b38..66d931f67567 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/client.py @@ -106,8 +106,78 @@ class InterconnectRemoteLocationsClient( ): """The InterconnectRemoteLocations API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -299,7 +369,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = InterconnectRemoteLocationsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -335,6 +447,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = InterconnectRemoteLocationsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/client.py index 0584208d5f29..ee7000b18d2a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/client.py @@ -107,8 +107,78 @@ def get_transport_class( class InterconnectsClient(metaclass=InterconnectsClientMeta): """The Interconnects API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = InterconnectsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = InterconnectsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/client.py index 3f78ac08a7b3..67cd416e8e1e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/client.py @@ -103,8 +103,78 @@ def get_transport_class( class LicenseCodesClient(metaclass=LicenseCodesClientMeta): """The LicenseCodes API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -296,7 +366,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = LicenseCodesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -330,6 +442,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = LicenseCodesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/client.py index 342cce87e008..7d718709a172 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/client.py @@ -107,8 +107,78 @@ def get_transport_class( class LicensesClient(metaclass=LicensesClientMeta): """The Licenses API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = LicensesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = LicensesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/client.py index 47e59d421e33..c00d8dc1a60f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/client.py @@ -107,8 +107,78 @@ def get_transport_class( class MachineImagesClient(metaclass=MachineImagesClientMeta): """The MachineImages API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = MachineImagesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = MachineImagesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/client.py index 307844dd9add..763b20934de6 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/client.py @@ -104,8 +104,78 @@ def get_transport_class( class MachineTypesClient(metaclass=MachineTypesClientMeta): """The MachineTypes API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -297,7 +367,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = MachineTypesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -331,6 +443,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = MachineTypesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/client.py index e3247a1837e8..c3b6d5fc4bec 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/client.py @@ -107,8 +107,78 @@ def get_transport_class( class NetworkAttachmentsClient(metaclass=NetworkAttachmentsClientMeta): """The NetworkAttachments API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = NetworkAttachmentsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = NetworkAttachmentsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/client.py index 595a38b2f3e0..cf1a12c441c8 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/client.py @@ -109,8 +109,78 @@ class NetworkEdgeSecurityServicesClient( ): """The NetworkEdgeSecurityServices API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -302,7 +372,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = NetworkEdgeSecurityServicesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -338,6 +450,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = NetworkEdgeSecurityServicesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/client.py index de63d38c5ef8..d03482cfc732 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/client.py @@ -107,8 +107,78 @@ def get_transport_class( class NetworkEndpointGroupsClient(metaclass=NetworkEndpointGroupsClientMeta): """The NetworkEndpointGroups API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = NetworkEndpointGroupsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -336,6 +448,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = NetworkEndpointGroupsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/client.py index 2e73b4cd3caf..93a0598a86fd 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/client.py @@ -107,8 +107,78 @@ def get_transport_class( class NetworkFirewallPoliciesClient(metaclass=NetworkFirewallPoliciesClientMeta): """The NetworkFirewallPolicies API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = NetworkFirewallPoliciesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -336,6 +448,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = NetworkFirewallPoliciesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/client.py index 0055c3071fac..c5f486efb164 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/client.py @@ -104,8 +104,78 @@ def get_transport_class( class NetworkProfilesClient(metaclass=NetworkProfilesClientMeta): """The NetworkProfiles API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -297,7 +367,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = NetworkProfilesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -331,6 +443,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = NetworkProfilesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/client.py index 21ebb63c13f8..15b52bdccb6b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/client.py @@ -107,8 +107,78 @@ def get_transport_class( class NetworksClient(metaclass=NetworksClientMeta): """The Networks API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = NetworksClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = NetworksClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/client.py index 3df13a930679..8d21617b2fa7 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/client.py @@ -107,8 +107,78 @@ def get_transport_class( class NodeGroupsClient(metaclass=NodeGroupsClientMeta): """The NodeGroups API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = NodeGroupsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = NodeGroupsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/client.py index 0d5d43d4016c..3824a5dfe720 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/client.py @@ -107,8 +107,78 @@ def get_transport_class( class NodeTemplatesClient(metaclass=NodeTemplatesClientMeta): """The NodeTemplates API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = NodeTemplatesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = NodeTemplatesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/client.py index 4ea9c92f745f..1622a2531c09 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/client.py @@ -104,8 +104,78 @@ def get_transport_class( class NodeTypesClient(metaclass=NodeTypesClientMeta): """The NodeTypes API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -297,7 +367,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = NodeTypesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -331,6 +443,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = NodeTypesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/client.py index 190a08f76b70..dab7672d8efa 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/client.py @@ -109,8 +109,78 @@ class OrganizationSecurityPoliciesClient( ): """The OrganizationSecurityPolicies API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -304,7 +374,51 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = ( + OrganizationSecurityPoliciesClient._use_client_cert_effective() + ) + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -340,6 +454,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = OrganizationSecurityPoliciesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/client.py index 1e57d2b66e61..f4e40d33e4b0 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/client.py @@ -107,8 +107,78 @@ def get_transport_class( class PacketMirroringsClient(metaclass=PacketMirroringsClientMeta): """The PacketMirrorings API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = PacketMirroringsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = PacketMirroringsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/client.py index f5119d67a5d9..c9ac5da49ac1 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/client.py @@ -107,8 +107,78 @@ def get_transport_class( class PreviewFeaturesClient(metaclass=PreviewFeaturesClientMeta): """The PreviewFeatures API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = PreviewFeaturesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = PreviewFeaturesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/client.py index 2ca4c071a039..af82bc995a08 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/client.py @@ -107,8 +107,78 @@ def get_transport_class( class ProjectsClient(metaclass=ProjectsClientMeta): """The Projects API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = ProjectsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = ProjectsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/client.py index 99702a6ace2d..dc863baa2019 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/client.py @@ -107,8 +107,78 @@ def get_transport_class( class PublicAdvertisedPrefixesClient(metaclass=PublicAdvertisedPrefixesClientMeta): """The PublicAdvertisedPrefixes API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = PublicAdvertisedPrefixesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -336,6 +448,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = PublicAdvertisedPrefixesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/client.py index 07d54e19ee87..e01d7a2e5bfe 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/client.py @@ -107,8 +107,78 @@ def get_transport_class( class PublicDelegatedPrefixesClient(metaclass=PublicDelegatedPrefixesClientMeta): """The PublicDelegatedPrefixes API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = PublicDelegatedPrefixesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -336,6 +448,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = PublicDelegatedPrefixesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/client.py index d82be9744812..a56846e1bada 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RegionAutoscalersClient(metaclass=RegionAutoscalersClientMeta): """The RegionAutoscalers API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionAutoscalersClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionAutoscalersClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_buckets/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_buckets/client.py index fe13e0837c54..8f4a7b95cf7f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_buckets/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_buckets/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RegionBackendBucketsClient(metaclass=RegionBackendBucketsClientMeta): """The RegionBackendBuckets API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionBackendBucketsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionBackendBucketsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/client.py index bf2372d12c7e..e2f5d0b49d89 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RegionBackendServicesClient(metaclass=RegionBackendServicesClientMeta): """The RegionBackendServices API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionBackendServicesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -336,6 +448,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionBackendServicesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/client.py index 955b60de7713..e39283a4fb3f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RegionCommitmentsClient(metaclass=RegionCommitmentsClientMeta): """The RegionCommitments API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionCommitmentsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionCommitmentsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/client.py index 6a240d6a02b1..9148571a7612 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/client.py @@ -109,8 +109,78 @@ class RegionCompositeHealthChecksClient( ): """The RegionCompositeHealthChecks API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -302,7 +372,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionCompositeHealthChecksClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -338,6 +450,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionCompositeHealthChecksClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/client.py index 36b920f16971..d478fea5679c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/client.py @@ -104,8 +104,78 @@ def get_transport_class( class RegionDiskTypesClient(metaclass=RegionDiskTypesClientMeta): """The RegionDiskTypes API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -297,7 +367,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionDiskTypesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -331,6 +443,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionDiskTypesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/client.py index 2f9b7f2b48fa..d6a9c3cc5583 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RegionDisksClient(metaclass=RegionDisksClientMeta): """The RegionDisks API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionDisksClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionDisksClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/client.py index c5dc3cddbc05..e1601d8a9b0f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/client.py @@ -112,8 +112,78 @@ class RegionHealthAggregationPoliciesClient( ): """The RegionHealthAggregationPolicies API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -307,7 +377,51 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = ( + RegionHealthAggregationPoliciesClient._use_client_cert_effective() + ) + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -343,6 +457,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionHealthAggregationPoliciesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/client.py index 4cc3a17013db..112f8697ddea 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RegionHealthCheckServicesClient(metaclass=RegionHealthCheckServicesClientMeta): """The RegionHealthCheckServices API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionHealthCheckServicesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -336,6 +448,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionHealthCheckServicesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/client.py index 6b4840f6c126..acf8ef76f413 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RegionHealthChecksClient(metaclass=RegionHealthChecksClientMeta): """The RegionHealthChecks API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionHealthChecksClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionHealthChecksClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/client.py index fb725ba0a129..6b874fce30f9 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RegionHealthSourcesClient(metaclass=RegionHealthSourcesClientMeta): """The RegionHealthSources API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionHealthSourcesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionHealthSourcesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_manager_resize_requests/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_manager_resize_requests/client.py index e2ff13fef695..eb4d0f17f02b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_manager_resize_requests/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_manager_resize_requests/client.py @@ -114,8 +114,78 @@ class RegionInstanceGroupManagerResizeRequestsClient( ): """The RegionInstanceGroupManagerResizeRequests API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -309,7 +379,51 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = ( + RegionInstanceGroupManagerResizeRequestsClient._use_client_cert_effective() + ) + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -347,6 +461,32 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = ( + RegionInstanceGroupManagerResizeRequestsClient._DEFAULT_UNIVERSE + ) + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/client.py index f822baf6a095..0ecb27fb666f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/client.py @@ -109,8 +109,78 @@ class RegionInstanceGroupManagersClient( ): """The RegionInstanceGroupManagers API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -302,7 +372,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionInstanceGroupManagersClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -338,6 +450,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionInstanceGroupManagersClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/client.py index 21d9dddc9e5c..244c3a2212c0 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RegionInstanceGroupsClient(metaclass=RegionInstanceGroupsClientMeta): """The RegionInstanceGroups API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionInstanceGroupsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionInstanceGroupsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/client.py index 84a4f0befe11..4450773a6420 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RegionInstanceTemplatesClient(metaclass=RegionInstanceTemplatesClientMeta): """The RegionInstanceTemplates API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionInstanceTemplatesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -336,6 +448,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionInstanceTemplatesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/client.py index c07f53dfa603..758b30a31767 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/client.py @@ -106,8 +106,78 @@ def get_transport_class( class RegionInstancesClient(metaclass=RegionInstancesClientMeta): """The RegionInstances API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -299,7 +369,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionInstancesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -333,6 +445,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionInstancesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshot_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshot_groups/client.py index fe57fadd78bd..f534ec040185 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshot_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshot_groups/client.py @@ -109,8 +109,78 @@ class RegionInstantSnapshotGroupsClient( ): """The RegionInstantSnapshotGroups API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -302,7 +372,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionInstantSnapshotGroupsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -338,6 +450,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionInstantSnapshotGroupsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/client.py index 843b0909d24c..1810085dd55d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RegionInstantSnapshotsClient(metaclass=RegionInstantSnapshotsClientMeta): """The RegionInstantSnapshots API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionInstantSnapshotsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -336,6 +448,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionInstantSnapshotsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/client.py index fcfa52d58816..043345f354bb 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/client.py @@ -109,8 +109,78 @@ class RegionNetworkEndpointGroupsClient( ): """The RegionNetworkEndpointGroups API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -302,7 +372,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionNetworkEndpointGroupsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -338,6 +450,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionNetworkEndpointGroupsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/client.py index 73822ffa291a..3fc654b6be93 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/client.py @@ -109,8 +109,78 @@ class RegionNetworkFirewallPoliciesClient( ): """The RegionNetworkFirewallPolicies API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -304,7 +374,51 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = ( + RegionNetworkFirewallPoliciesClient._use_client_cert_effective() + ) + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -340,6 +454,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionNetworkFirewallPoliciesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/client.py index bb7dd0562992..d60fd6d160b3 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/client.py @@ -109,8 +109,78 @@ class RegionNotificationEndpointsClient( ): """The RegionNotificationEndpoints API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -302,7 +372,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionNotificationEndpointsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -338,6 +450,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionNotificationEndpointsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/client.py index c15c7f53e5b6..8fb2ae187242 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/client.py @@ -104,8 +104,78 @@ def get_transport_class( class RegionOperationsClient(metaclass=RegionOperationsClientMeta): """The RegionOperations API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -297,7 +367,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionOperationsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -331,6 +443,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionOperationsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/client.py index 88968c11e6bb..c5ee12d04b1c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RegionSecurityPoliciesClient(metaclass=RegionSecurityPoliciesClientMeta): """The RegionSecurityPolicies API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionSecurityPoliciesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -336,6 +448,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionSecurityPoliciesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_snapshot_settings/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_snapshot_settings/client.py index aec3d6c3d8e7..ec5939ad0068 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_snapshot_settings/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_snapshot_settings/client.py @@ -106,8 +106,78 @@ def get_transport_class( class RegionSnapshotSettingsClient(metaclass=RegionSnapshotSettingsClientMeta): """The RegionSnapshotSettings API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -299,7 +369,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionSnapshotSettingsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -335,6 +447,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionSnapshotSettingsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_snapshots/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_snapshots/client.py index 7b9e559bf031..904d29795338 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_snapshots/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_snapshots/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RegionSnapshotsClient(metaclass=RegionSnapshotsClientMeta): """The RegionSnapshots API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionSnapshotsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionSnapshotsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/client.py index cddecab6cfee..405e0b493a2e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RegionSslCertificatesClient(metaclass=RegionSslCertificatesClientMeta): """The RegionSslCertificates API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionSslCertificatesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -336,6 +448,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionSslCertificatesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/client.py index 6fb1328e0e81..e3b4f9585ffd 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RegionSslPoliciesClient(metaclass=RegionSslPoliciesClientMeta): """The RegionSslPolicies API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionSslPoliciesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionSslPoliciesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/client.py index 58958c7e1a45..918adffd3077 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RegionTargetHttpProxiesClient(metaclass=RegionTargetHttpProxiesClientMeta): """The RegionTargetHttpProxies API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionTargetHttpProxiesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -336,6 +448,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionTargetHttpProxiesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/client.py index 8f978639a584..f718e2cb9640 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RegionTargetHttpsProxiesClient(metaclass=RegionTargetHttpsProxiesClientMeta): """The RegionTargetHttpsProxies API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionTargetHttpsProxiesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -336,6 +448,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionTargetHttpsProxiesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/client.py index 58e0297b298a..eb357c5b31e0 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RegionTargetTcpProxiesClient(metaclass=RegionTargetTcpProxiesClientMeta): """The RegionTargetTcpProxies API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionTargetTcpProxiesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -336,6 +448,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionTargetTcpProxiesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/client.py index 256e8c6d900e..d4ffcd7e4019 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RegionUrlMapsClient(metaclass=RegionUrlMapsClientMeta): """The RegionUrlMaps API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionUrlMapsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionUrlMapsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/client.py index 1ca4f3574819..cd8a556a4cac 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/client.py @@ -104,8 +104,78 @@ def get_transport_class( class RegionZonesClient(metaclass=RegionZonesClientMeta): """The RegionZones API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -297,7 +367,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionZonesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -331,6 +443,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionZonesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/client.py index 40c9fcfd028a..9ff2a52f56d2 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/client.py @@ -104,8 +104,78 @@ def get_transport_class( class RegionsClient(metaclass=RegionsClientMeta): """The Regions API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -297,7 +367,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RegionsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -331,6 +443,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RegionsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/client.py index 372e1d92c6cd..4443b29b4868 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/client.py @@ -107,8 +107,78 @@ def get_transport_class( class ReservationBlocksClient(metaclass=ReservationBlocksClientMeta): """The ReservationBlocks API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = ReservationBlocksClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = ReservationBlocksClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/client.py index fa15d4951b06..ed4aeef3137c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/client.py @@ -107,8 +107,78 @@ def get_transport_class( class ReservationSlotsClient(metaclass=ReservationSlotsClientMeta): """The ReservationSlots API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = ReservationSlotsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = ReservationSlotsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/client.py index b1c1c7bdce7e..71235e7aaf8d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/client.py @@ -107,8 +107,78 @@ def get_transport_class( class ReservationSubBlocksClient(metaclass=ReservationSubBlocksClientMeta): """The ReservationSubBlocks API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = ReservationSubBlocksClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = ReservationSubBlocksClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/client.py index f785c54f58e1..5eca38d9041b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/client.py @@ -107,8 +107,78 @@ def get_transport_class( class ReservationsClient(metaclass=ReservationsClientMeta): """The Reservations API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = ReservationsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = ReservationsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/client.py index fb65749acaf2..d301e4191043 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/client.py @@ -107,8 +107,78 @@ def get_transport_class( class ResourcePoliciesClient(metaclass=ResourcePoliciesClientMeta): """The ResourcePolicies API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = ResourcePoliciesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = ResourcePoliciesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/rollout_plans/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/rollout_plans/client.py index 2d19e45accdc..667081b9fe48 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/rollout_plans/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/rollout_plans/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RolloutPlansClient(metaclass=RolloutPlansClientMeta): """The RolloutPlans API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RolloutPlansClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RolloutPlansClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/rollouts/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/rollouts/client.py index 04fc47b4b6dc..9a658ef00897 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/rollouts/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/rollouts/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RolloutsClient(metaclass=RolloutsClientMeta): """The Rollouts API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RolloutsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RolloutsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/client.py index 7ff84c19bd1d..06fd0231ba58 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RoutersClient(metaclass=RoutersClientMeta): """The Routers API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RoutersClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RoutersClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/client.py index 5fbacddc572e..e9c310cb627c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/client.py @@ -107,8 +107,78 @@ def get_transport_class( class RoutesClient(metaclass=RoutesClientMeta): """The Routes API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = RoutesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = RoutesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/client.py index c673eebbf009..e083e35b1f7c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/client.py @@ -107,8 +107,78 @@ def get_transport_class( class SecurityPoliciesClient(metaclass=SecurityPoliciesClientMeta): """The SecurityPolicies API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = SecurityPoliciesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = SecurityPoliciesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/client.py index d289dc574e31..efcc99655a52 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/client.py @@ -107,8 +107,78 @@ def get_transport_class( class ServiceAttachmentsClient(metaclass=ServiceAttachmentsClientMeta): """The ServiceAttachments API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = ServiceAttachmentsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = ServiceAttachmentsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/client.py index 5fde3df693ad..7472a95de42a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/client.py @@ -106,8 +106,78 @@ def get_transport_class( class SnapshotSettingsServiceClient(metaclass=SnapshotSettingsServiceClientMeta): """The SnapshotSettings API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -299,7 +369,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = SnapshotSettingsServiceClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -335,6 +447,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = SnapshotSettingsServiceClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/client.py index 206d0f369ee9..21070513325e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/client.py @@ -107,8 +107,78 @@ def get_transport_class( class SnapshotsClient(metaclass=SnapshotsClientMeta): """The Snapshots API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = SnapshotsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = SnapshotsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/client.py index c4b13e19b33e..02d717c62ea0 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/client.py @@ -107,8 +107,78 @@ def get_transport_class( class SslCertificatesClient(metaclass=SslCertificatesClientMeta): """The SslCertificates API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = SslCertificatesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = SslCertificatesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/client.py index 6229ff620afb..3351a5900346 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/client.py @@ -107,8 +107,78 @@ def get_transport_class( class SslPoliciesClient(metaclass=SslPoliciesClientMeta): """The SslPolicies API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = SslPoliciesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = SslPoliciesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/client.py index 18f4940cd834..c453575db817 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/client.py @@ -104,8 +104,78 @@ def get_transport_class( class StoragePoolTypesClient(metaclass=StoragePoolTypesClientMeta): """The StoragePoolTypes API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -297,7 +367,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = StoragePoolTypesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -331,6 +443,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = StoragePoolTypesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/client.py index fd72f10ca2b5..a9ce3ef27511 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/client.py @@ -107,8 +107,78 @@ def get_transport_class( class StoragePoolsClient(metaclass=StoragePoolsClientMeta): """The StoragePools API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = StoragePoolsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = StoragePoolsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/client.py index 9df37d18a0af..1f1bace31cb4 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/client.py @@ -107,8 +107,78 @@ def get_transport_class( class SubnetworksClient(metaclass=SubnetworksClientMeta): """The Subnetworks API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = SubnetworksClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = SubnetworksClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/client.py index ac6b87decbfa..39991f0f01b8 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/client.py @@ -107,8 +107,78 @@ def get_transport_class( class TargetGrpcProxiesClient(metaclass=TargetGrpcProxiesClientMeta): """The TargetGrpcProxies API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = TargetGrpcProxiesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = TargetGrpcProxiesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/client.py index c5daf132eb9e..2db72e2bf617 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/client.py @@ -107,8 +107,78 @@ def get_transport_class( class TargetHttpProxiesClient(metaclass=TargetHttpProxiesClientMeta): """The TargetHttpProxies API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = TargetHttpProxiesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = TargetHttpProxiesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/client.py index 3769728f33d7..44d807dd57f4 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/client.py @@ -107,8 +107,78 @@ def get_transport_class( class TargetHttpsProxiesClient(metaclass=TargetHttpsProxiesClientMeta): """The TargetHttpsProxies API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = TargetHttpsProxiesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = TargetHttpsProxiesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/client.py index 461fd49b2fa7..7e4992c4db64 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/client.py @@ -107,8 +107,78 @@ def get_transport_class( class TargetInstancesClient(metaclass=TargetInstancesClientMeta): """The TargetInstances API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = TargetInstancesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = TargetInstancesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/client.py index e8ece6b7833f..b86f70daaebf 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/client.py @@ -107,8 +107,78 @@ def get_transport_class( class TargetPoolsClient(metaclass=TargetPoolsClientMeta): """The TargetPools API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = TargetPoolsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = TargetPoolsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/client.py index 909ebd68c1bd..dce2bd2ea932 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/client.py @@ -107,8 +107,78 @@ def get_transport_class( class TargetSslProxiesClient(metaclass=TargetSslProxiesClientMeta): """The TargetSslProxies API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = TargetSslProxiesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = TargetSslProxiesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/client.py index 128816725367..36fc4095cadd 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/client.py @@ -107,8 +107,78 @@ def get_transport_class( class TargetTcpProxiesClient(metaclass=TargetTcpProxiesClientMeta): """The TargetTcpProxies API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = TargetTcpProxiesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = TargetTcpProxiesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/client.py index 0310b9670385..d51b03921809 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/client.py @@ -107,8 +107,78 @@ def get_transport_class( class TargetVpnGatewaysClient(metaclass=TargetVpnGatewaysClientMeta): """The TargetVpnGateways API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = TargetVpnGatewaysClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = TargetVpnGatewaysClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/client.py index e51bae74af8c..1a9365973b0b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/client.py @@ -107,8 +107,78 @@ def get_transport_class( class UrlMapsClient(metaclass=UrlMapsClientMeta): """The UrlMaps API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = UrlMapsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = UrlMapsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/client.py index 68b5a804bd58..a2db6bab6965 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/client.py @@ -107,8 +107,78 @@ def get_transport_class( class VpnGatewaysClient(metaclass=VpnGatewaysClientMeta): """The VpnGateways API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = VpnGatewaysClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = VpnGatewaysClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/client.py index 9cba502cf426..097d83e6cb74 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/client.py @@ -107,8 +107,78 @@ def get_transport_class( class VpnTunnelsClient(metaclass=VpnTunnelsClientMeta): """The VpnTunnels API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = VpnTunnelsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = VpnTunnelsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/client.py index 3fad563c32f3..9e9c7e69163e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/client.py @@ -107,8 +107,78 @@ def get_transport_class( class WireGroupsClient(metaclass=WireGroupsClientMeta): """The WireGroups API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = WireGroupsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -334,6 +446,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = WireGroupsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/client.py index 8a723db7e9b1..9e4a7ccb9366 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/client.py @@ -104,8 +104,78 @@ def get_transport_class( class ZoneOperationsClient(metaclass=ZoneOperationsClientMeta): """The ZoneOperations API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -297,7 +367,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = ZoneOperationsClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -331,6 +443,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = ZoneOperationsClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_vm_extension_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_vm_extension_policies/client.py index 79db386a784e..1a944b412f85 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_vm_extension_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_vm_extension_policies/client.py @@ -107,8 +107,78 @@ def get_transport_class( class ZoneVmExtensionPoliciesClient(metaclass=ZoneVmExtensionPoliciesClientMeta): """The ZoneVmExtensionPolicies API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -300,7 +370,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = ZoneVmExtensionPoliciesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -336,6 +448,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = ZoneVmExtensionPoliciesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/client.py index 13fe6ddbbd38..ac6c2813e503 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/client.py @@ -104,8 +104,78 @@ def get_transport_class( class ZonesClient(metaclass=ZonesClientMeta): """The Zones API.""" + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "compute.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "compute.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -297,7 +367,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = ZonesClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -331,6 +443,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = ZonesClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-compute/noxfile.py b/packages/google-cloud-compute/noxfile.py index a34bff72b302..e4103b0c9ffb 100644 --- a/packages/google-cloud-compute/noxfile.py +++ b/packages/google-cloud-compute/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-confidentialcomputing/noxfile.py b/packages/google-cloud-confidentialcomputing/noxfile.py index 0a858dc198e4..2a3d9e9aa558 100644 --- a/packages/google-cloud-confidentialcomputing/noxfile.py +++ b/packages/google-cloud-confidentialcomputing/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-config/noxfile.py b/packages/google-cloud-config/noxfile.py index 9be1c6500862..9e253aa7bb01 100644 --- a/packages/google-cloud-config/noxfile.py +++ b/packages/google-cloud-config/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-configdelivery/noxfile.py b/packages/google-cloud-configdelivery/noxfile.py index 55366c44f8f3..b030cca9d976 100644 --- a/packages/google-cloud-configdelivery/noxfile.py +++ b/packages/google-cloud-configdelivery/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-contact-center-insights/noxfile.py b/packages/google-cloud-contact-center-insights/noxfile.py index 324c08d9cc72..fa7a8ecf4016 100644 --- a/packages/google-cloud-contact-center-insights/noxfile.py +++ b/packages/google-cloud-contact-center-insights/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-container/noxfile.py b/packages/google-cloud-container/noxfile.py index 9abb19cc3f2f..c681b455965e 100644 --- a/packages/google-cloud-container/noxfile.py +++ b/packages/google-cloud-container/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-containeranalysis/noxfile.py b/packages/google-cloud-containeranalysis/noxfile.py index 9ee961b93a96..a919287d3dc0 100644 --- a/packages/google-cloud-containeranalysis/noxfile.py +++ b/packages/google-cloud-containeranalysis/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-contentwarehouse/noxfile.py b/packages/google-cloud-contentwarehouse/noxfile.py index 4aaddfbb9659..b276ac47b184 100644 --- a/packages/google-cloud-contentwarehouse/noxfile.py +++ b/packages/google-cloud-contentwarehouse/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-core/noxfile.py b/packages/google-cloud-core/noxfile.py index 41c3e2ac9868..2de40dfb9234 100644 --- a/packages/google-cloud-core/noxfile.py +++ b/packages/google-cloud-core/noxfile.py @@ -418,23 +418,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-data-fusion/noxfile.py b/packages/google-cloud-data-fusion/noxfile.py index 2de71a3ff640..bd3ea36f0386 100644 --- a/packages/google-cloud-data-fusion/noxfile.py +++ b/packages/google-cloud-data-fusion/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-data-qna/noxfile.py b/packages/google-cloud-data-qna/noxfile.py index 0608153d39ba..043ebd79a0bb 100644 --- a/packages/google-cloud-data-qna/noxfile.py +++ b/packages/google-cloud-data-qna/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-databasecenter/noxfile.py b/packages/google-cloud-databasecenter/noxfile.py index fb31e9ea7c8e..003b7dd3c53f 100644 --- a/packages/google-cloud-databasecenter/noxfile.py +++ b/packages/google-cloud-databasecenter/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-datacatalog-lineage-configmanagement/noxfile.py b/packages/google-cloud-datacatalog-lineage-configmanagement/noxfile.py index a41f1f4bd28f..5ba2db6104ad 100644 --- a/packages/google-cloud-datacatalog-lineage-configmanagement/noxfile.py +++ b/packages/google-cloud-datacatalog-lineage-configmanagement/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-datacatalog-lineage/noxfile.py b/packages/google-cloud-datacatalog-lineage/noxfile.py index e99cfb0f567f..1cf9b67d7e28 100644 --- a/packages/google-cloud-datacatalog-lineage/noxfile.py +++ b/packages/google-cloud-datacatalog-lineage/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-datacatalog/noxfile.py b/packages/google-cloud-datacatalog/noxfile.py index 388a72c307e5..f1d0baa07491 100644 --- a/packages/google-cloud-datacatalog/noxfile.py +++ b/packages/google-cloud-datacatalog/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-dataflow-client/noxfile.py b/packages/google-cloud-dataflow-client/noxfile.py index 23c5987e6904..eb858582eda7 100644 --- a/packages/google-cloud-dataflow-client/noxfile.py +++ b/packages/google-cloud-dataflow-client/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-dataform/noxfile.py b/packages/google-cloud-dataform/noxfile.py index 73cfdb4d3734..19c4147fe1de 100644 --- a/packages/google-cloud-dataform/noxfile.py +++ b/packages/google-cloud-dataform/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-datalabeling/noxfile.py b/packages/google-cloud-datalabeling/noxfile.py index 123efc75d4cd..e4f28c74368b 100644 --- a/packages/google-cloud-datalabeling/noxfile.py +++ b/packages/google-cloud-datalabeling/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-dataplex/noxfile.py b/packages/google-cloud-dataplex/noxfile.py index 717193edfc79..861b281f03a7 100644 --- a/packages/google-cloud-dataplex/noxfile.py +++ b/packages/google-cloud-dataplex/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-dataproc-metastore/noxfile.py b/packages/google-cloud-dataproc-metastore/noxfile.py index 317c9cceebf8..47eff28054f9 100644 --- a/packages/google-cloud-dataproc-metastore/noxfile.py +++ b/packages/google-cloud-dataproc-metastore/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-dataproc/noxfile.py b/packages/google-cloud-dataproc/noxfile.py index 920964ff7f6b..4c1c13c5d053 100644 --- a/packages/google-cloud-dataproc/noxfile.py +++ b/packages/google-cloud-dataproc/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-datastore/noxfile.py b/packages/google-cloud-datastore/noxfile.py index 97a1786db005..af42d740478e 100644 --- a/packages/google-cloud-datastore/noxfile.py +++ b/packages/google-cloud-datastore/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -646,23 +645,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-datastream/noxfile.py b/packages/google-cloud-datastream/noxfile.py index 9b0a13d1a10d..2769c61b3d26 100644 --- a/packages/google-cloud-datastream/noxfile.py +++ b/packages/google-cloud-datastream/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-deploy/noxfile.py b/packages/google-cloud-deploy/noxfile.py index 12a4f078b9f1..8b14ce1ff03a 100644 --- a/packages/google-cloud-deploy/noxfile.py +++ b/packages/google-cloud-deploy/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-developerconnect/noxfile.py b/packages/google-cloud-developerconnect/noxfile.py index 250e5f250487..e4b4e0709514 100644 --- a/packages/google-cloud-developerconnect/noxfile.py +++ b/packages/google-cloud-developerconnect/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-devicestreaming/noxfile.py b/packages/google-cloud-devicestreaming/noxfile.py index 3ce8b4976c07..35e6971161be 100644 --- a/packages/google-cloud-devicestreaming/noxfile.py +++ b/packages/google-cloud-devicestreaming/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-dialogflow-cx/noxfile.py b/packages/google-cloud-dialogflow-cx/noxfile.py index eac420915b26..805659bdd66f 100644 --- a/packages/google-cloud-dialogflow-cx/noxfile.py +++ b/packages/google-cloud-dialogflow-cx/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-dialogflow/noxfile.py b/packages/google-cloud-dialogflow/noxfile.py index 1a4d1539850a..16dd69716f10 100644 --- a/packages/google-cloud-dialogflow/noxfile.py +++ b/packages/google-cloud-dialogflow/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-discoveryengine/noxfile.py b/packages/google-cloud-discoveryengine/noxfile.py index 064112def637..762d1dda8f95 100644 --- a/packages/google-cloud-discoveryengine/noxfile.py +++ b/packages/google-cloud-discoveryengine/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-dlp/noxfile.py b/packages/google-cloud-dlp/noxfile.py index 0c3bb16e06d4..08977f0c92b7 100644 --- a/packages/google-cloud-dlp/noxfile.py +++ b/packages/google-cloud-dlp/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-dms/noxfile.py b/packages/google-cloud-dms/noxfile.py index a75ac008520f..e7c9e6377709 100644 --- a/packages/google-cloud-dms/noxfile.py +++ b/packages/google-cloud-dms/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-dns/noxfile.py b/packages/google-cloud-dns/noxfile.py index 7a856d15ac77..bb38d1e08a91 100644 --- a/packages/google-cloud-dns/noxfile.py +++ b/packages/google-cloud-dns/noxfile.py @@ -41,7 +41,6 @@ "3.12", "3.13", "3.14", - "import_profile", ] UNIT_TEST_STANDARD_DEPENDENCIES = [ "mock", @@ -514,23 +513,3 @@ def core_deps_from_source(session): "py.test", "tests/unit", ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-documentai-toolbox/noxfile.py b/packages/google-cloud-documentai-toolbox/noxfile.py index 4e0a1ab5443e..db70716c5d6b 100644 --- a/packages/google-cloud-documentai-toolbox/noxfile.py +++ b/packages/google-cloud-documentai-toolbox/noxfile.py @@ -41,7 +41,6 @@ "3.12", "3.13", "3.14", - "import_profile", ] UNIT_TEST_STANDARD_DEPENDENCIES = [ @@ -548,23 +547,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-documentai/noxfile.py b/packages/google-cloud-documentai/noxfile.py index 1482ba225681..8dcff8465a6c 100644 --- a/packages/google-cloud-documentai/noxfile.py +++ b/packages/google-cloud-documentai/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-domains/noxfile.py b/packages/google-cloud-domains/noxfile.py index 8c2b2f262014..e1810b6976dd 100644 --- a/packages/google-cloud-domains/noxfile.py +++ b/packages/google-cloud-domains/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-edgecontainer/noxfile.py b/packages/google-cloud-edgecontainer/noxfile.py index a870d0bdd0f8..43042ab41c58 100644 --- a/packages/google-cloud-edgecontainer/noxfile.py +++ b/packages/google-cloud-edgecontainer/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-edgenetwork/noxfile.py b/packages/google-cloud-edgenetwork/noxfile.py index 08e5bd144b81..52259b092b2c 100644 --- a/packages/google-cloud-edgenetwork/noxfile.py +++ b/packages/google-cloud-edgenetwork/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-enterpriseknowledgegraph/noxfile.py b/packages/google-cloud-enterpriseknowledgegraph/noxfile.py index 43a8c9de3937..d8171fa7ea3a 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/noxfile.py +++ b/packages/google-cloud-enterpriseknowledgegraph/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-error-reporting/noxfile.py b/packages/google-cloud-error-reporting/noxfile.py index cb593565bbf2..e13108291d94 100644 --- a/packages/google-cloud-error-reporting/noxfile.py +++ b/packages/google-cloud-error-reporting/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -639,23 +638,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-essential-contacts/noxfile.py b/packages/google-cloud-essential-contacts/noxfile.py index 7afcdfbfb9ae..4da6f982d14b 100644 --- a/packages/google-cloud-essential-contacts/noxfile.py +++ b/packages/google-cloud-essential-contacts/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-eventarc-publishing/noxfile.py b/packages/google-cloud-eventarc-publishing/noxfile.py index 6ba9a95492af..4ab114200c08 100644 --- a/packages/google-cloud-eventarc-publishing/noxfile.py +++ b/packages/google-cloud-eventarc-publishing/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-eventarc/noxfile.py b/packages/google-cloud-eventarc/noxfile.py index 615a58b26ae5..6d8722a224dc 100644 --- a/packages/google-cloud-eventarc/noxfile.py +++ b/packages/google-cloud-eventarc/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-filestore/noxfile.py b/packages/google-cloud-filestore/noxfile.py index c685715579fc..dcb7a07707a3 100644 --- a/packages/google-cloud-filestore/noxfile.py +++ b/packages/google-cloud-filestore/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-financialservices/noxfile.py b/packages/google-cloud-financialservices/noxfile.py index 174df2b7a66f..e9376f8c2c18 100644 --- a/packages/google-cloud-financialservices/noxfile.py +++ b/packages/google-cloud-financialservices/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-firestore/noxfile.py b/packages/google-cloud-firestore/noxfile.py index ced52e2d9e3d..4df37240719c 100644 --- a/packages/google-cloud-firestore/noxfile.py +++ b/packages/google-cloud-firestore/noxfile.py @@ -96,7 +96,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -701,23 +700,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-functions/noxfile.py b/packages/google-cloud-functions/noxfile.py index f85fcaa2f3f7..c46cf4fc5cad 100644 --- a/packages/google-cloud-functions/noxfile.py +++ b/packages/google-cloud-functions/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-gdchardwaremanagement/noxfile.py b/packages/google-cloud-gdchardwaremanagement/noxfile.py index ffa803877858..6f51ea26c38b 100644 --- a/packages/google-cloud-gdchardwaremanagement/noxfile.py +++ b/packages/google-cloud-gdchardwaremanagement/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-geminidataanalytics/noxfile.py b/packages/google-cloud-geminidataanalytics/noxfile.py index 8a9253df0368..8e27ba9291da 100644 --- a/packages/google-cloud-geminidataanalytics/noxfile.py +++ b/packages/google-cloud-geminidataanalytics/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-gke-backup/noxfile.py b/packages/google-cloud-gke-backup/noxfile.py index 42d083ca7f5b..56fab5920e83 100644 --- a/packages/google-cloud-gke-backup/noxfile.py +++ b/packages/google-cloud-gke-backup/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-gke-connect-gateway/noxfile.py b/packages/google-cloud-gke-connect-gateway/noxfile.py index 99bf2a55e42c..0154a64bc1b5 100644 --- a/packages/google-cloud-gke-connect-gateway/noxfile.py +++ b/packages/google-cloud-gke-connect-gateway/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-gke-hub/noxfile.py b/packages/google-cloud-gke-hub/noxfile.py index 2d6c1ccb29bc..a5124d5be99a 100644 --- a/packages/google-cloud-gke-hub/noxfile.py +++ b/packages/google-cloud-gke-hub/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-gke-multicloud/noxfile.py b/packages/google-cloud-gke-multicloud/noxfile.py index 576d7ced89e0..6dbc9a81300b 100644 --- a/packages/google-cloud-gke-multicloud/noxfile.py +++ b/packages/google-cloud-gke-multicloud/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-gkerecommender/noxfile.py b/packages/google-cloud-gkerecommender/noxfile.py index 1939f5eb5402..b11b2a44dfee 100644 --- a/packages/google-cloud-gkerecommender/noxfile.py +++ b/packages/google-cloud-gkerecommender/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-gsuiteaddons/noxfile.py b/packages/google-cloud-gsuiteaddons/noxfile.py index 926f5f711930..da154872a469 100644 --- a/packages/google-cloud-gsuiteaddons/noxfile.py +++ b/packages/google-cloud-gsuiteaddons/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-hypercomputecluster/noxfile.py b/packages/google-cloud-hypercomputecluster/noxfile.py index 76c72c4d5125..0a5b009a3092 100644 --- a/packages/google-cloud-hypercomputecluster/noxfile.py +++ b/packages/google-cloud-hypercomputecluster/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-iam-logging/noxfile.py b/packages/google-cloud-iam-logging/noxfile.py index da1858259061..eb1274b44083 100644 --- a/packages/google-cloud-iam-logging/noxfile.py +++ b/packages/google-cloud-iam-logging/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-iam/noxfile.py b/packages/google-cloud-iam/noxfile.py index 3846a48e0952..60be3c6e4e18 100644 --- a/packages/google-cloud-iam/noxfile.py +++ b/packages/google-cloud-iam/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-iamconnectorcredentials/noxfile.py b/packages/google-cloud-iamconnectorcredentials/noxfile.py index 467fabe2af8a..1fff9f2e6f1e 100644 --- a/packages/google-cloud-iamconnectorcredentials/noxfile.py +++ b/packages/google-cloud-iamconnectorcredentials/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-iap/noxfile.py b/packages/google-cloud-iap/noxfile.py index 9a1173d90ce5..239436d95342 100644 --- a/packages/google-cloud-iap/noxfile.py +++ b/packages/google-cloud-iap/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-ids/noxfile.py b/packages/google-cloud-ids/noxfile.py index 31383bee1ff2..039b77ebbb70 100644 --- a/packages/google-cloud-ids/noxfile.py +++ b/packages/google-cloud-ids/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-kms-inventory/noxfile.py b/packages/google-cloud-kms-inventory/noxfile.py index 1d993ca155af..beb750ab1711 100644 --- a/packages/google-cloud-kms-inventory/noxfile.py +++ b/packages/google-cloud-kms-inventory/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/client.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/client.py index ca66d3830f95..fd5003ea45b9 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/client.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/client.py @@ -136,8 +136,78 @@ class AutokeyClient(metaclass=AutokeyClientMeta): [ShowEffectiveAutokeyConfig][google.cloud.kms.v1.AutokeyAdmin.ShowEffectiveAutokeyConfig]. """ + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "cloudkms.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "cloudkms.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -375,7 +445,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = AutokeyClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -409,6 +521,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = AutokeyClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/client.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/client.py index 5e7bbe81fb59..79cfb77e3d33 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/client.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/client.py @@ -126,8 +126,78 @@ class AutokeyAdminClient(metaclass=AutokeyAdminClientMeta): delegated key management mode for same-project keys. """ + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "cloudkms.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "cloudkms.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -334,7 +404,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = AutokeyAdminClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -368,6 +480,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = AutokeyAdminClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/client.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/client.py index 372920b776a0..9ab88628e743 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/client.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/client.py @@ -123,8 +123,78 @@ class EkmServiceClient(metaclass=EkmServiceClientMeta): - [EkmConnection][google.cloud.kms.v1.EkmConnection] """ + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "cloudkms.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "cloudkms.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -381,7 +451,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = EkmServiceClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -415,6 +527,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = EkmServiceClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/client.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/client.py index 8532a0a62209..934b6a1bb710 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/client.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/client.py @@ -127,8 +127,78 @@ class HsmManagementClient(metaclass=HsmManagementClientMeta): - [SingleTenantHsmInstanceProposal][google.cloud.kms.v1.SingleTenantHsmInstanceProposal] """ + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "cloudkms.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "cloudkms.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -366,7 +436,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = HsmManagementClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -400,6 +512,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = HsmManagementClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/client.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/client.py index 411283317f70..aff969e7a712 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/client.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/client.py @@ -134,8 +134,78 @@ class KeyManagementServiceClient(metaclass=KeyManagementServiceClientMeta): KMS `__. """ + @staticmethod + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "cloudkms.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "cloudkms.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @staticmethod + def _use_client_cert_effective(): + """Returns whether client certificate should be used for mTLS if the + google-auth version supports should_use_client_cert automatic mTLS enablement. + + Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. + + Returns: + bool: whether client certificate should be used for mTLS + Raises: + ValueError: (If using a version of google-auth without should_use_client_cert and + GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) + """ + # check if google-auth version supports should_use_client_cert for automatic mTLS enablement + if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER + return mtls.should_use_client_cert() + else: # pragma: NO COVER + # if unsupported, fallback to reading from env var + use_client_cert_str = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert_str not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert_str == "true" + + @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): """Creates an instance of this client using the provided credentials info. @@ -471,7 +541,49 @@ def get_mtls_endpoint_and_cert_source( return api_endpoint, client_cert_source + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = KeyManagementServiceClient._use_client_cert_effective() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ) -> str: @@ -505,6 +617,30 @@ def _get_api_endpoint( ) return api_endpoint + @staticmethod + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = KeyManagementServiceClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain def _validate_universe_domain(self): """Validates client's and credentials' universe domains are consistent. diff --git a/packages/google-cloud-kms/noxfile.py b/packages/google-cloud-kms/noxfile.py index 912e22a0a251..0468f42a5bc4 100644 --- a/packages/google-cloud-kms/noxfile.py +++ b/packages/google-cloud-kms/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-language/noxfile.py b/packages/google-cloud-language/noxfile.py index 5598c03a5b61..7c8f31734518 100644 --- a/packages/google-cloud-language/noxfile.py +++ b/packages/google-cloud-language/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-licensemanager/noxfile.py b/packages/google-cloud-licensemanager/noxfile.py index 3271492f030a..faab51c77445 100644 --- a/packages/google-cloud-licensemanager/noxfile.py +++ b/packages/google-cloud-licensemanager/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-life-sciences/noxfile.py b/packages/google-cloud-life-sciences/noxfile.py index ee09afa785c0..21cf5135ed89 100644 --- a/packages/google-cloud-life-sciences/noxfile.py +++ b/packages/google-cloud-life-sciences/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-locationfinder/noxfile.py b/packages/google-cloud-locationfinder/noxfile.py index 2c298dd18687..cc2ef53e813b 100644 --- a/packages/google-cloud-locationfinder/noxfile.py +++ b/packages/google-cloud-locationfinder/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-logging/noxfile.py b/packages/google-cloud-logging/noxfile.py index 06304a8bd0ba..f243539c2d21 100644 --- a/packages/google-cloud-logging/noxfile.py +++ b/packages/google-cloud-logging/noxfile.py @@ -98,7 +98,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -637,23 +636,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-lustre/noxfile.py b/packages/google-cloud-lustre/noxfile.py index fce678623521..adedfe930707 100644 --- a/packages/google-cloud-lustre/noxfile.py +++ b/packages/google-cloud-lustre/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-maintenance-api/noxfile.py b/packages/google-cloud-maintenance-api/noxfile.py index 38d16f765f24..c454a3334353 100644 --- a/packages/google-cloud-maintenance-api/noxfile.py +++ b/packages/google-cloud-maintenance-api/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-managed-identities/noxfile.py b/packages/google-cloud-managed-identities/noxfile.py index ccf750ada627..a9c496f3b4cf 100644 --- a/packages/google-cloud-managed-identities/noxfile.py +++ b/packages/google-cloud-managed-identities/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-managedkafka-schemaregistry/noxfile.py b/packages/google-cloud-managedkafka-schemaregistry/noxfile.py index 84ed8c2c37c7..84a7800166e5 100644 --- a/packages/google-cloud-managedkafka-schemaregistry/noxfile.py +++ b/packages/google-cloud-managedkafka-schemaregistry/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-managedkafka/noxfile.py b/packages/google-cloud-managedkafka/noxfile.py index d9bf8c0a6822..c37d675428ee 100644 --- a/packages/google-cloud-managedkafka/noxfile.py +++ b/packages/google-cloud-managedkafka/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-media-translation/noxfile.py b/packages/google-cloud-media-translation/noxfile.py index 58f7d0022db2..32561ecc46e5 100644 --- a/packages/google-cloud-media-translation/noxfile.py +++ b/packages/google-cloud-media-translation/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-memcache/noxfile.py b/packages/google-cloud-memcache/noxfile.py index 59eb2eab215f..53eca79c60e2 100644 --- a/packages/google-cloud-memcache/noxfile.py +++ b/packages/google-cloud-memcache/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-memorystore/noxfile.py b/packages/google-cloud-memorystore/noxfile.py index 83fecf90ab36..f25e737a088f 100644 --- a/packages/google-cloud-memorystore/noxfile.py +++ b/packages/google-cloud-memorystore/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-migrationcenter/noxfile.py b/packages/google-cloud-migrationcenter/noxfile.py index 073597ee1690..24d0f586240d 100644 --- a/packages/google-cloud-migrationcenter/noxfile.py +++ b/packages/google-cloud-migrationcenter/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-modelarmor/noxfile.py b/packages/google-cloud-modelarmor/noxfile.py index f655333ebdc5..543e80995c76 100644 --- a/packages/google-cloud-modelarmor/noxfile.py +++ b/packages/google-cloud-modelarmor/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-monitoring-dashboards/noxfile.py b/packages/google-cloud-monitoring-dashboards/noxfile.py index 95ca942edd0a..f74cd9919ad2 100644 --- a/packages/google-cloud-monitoring-dashboards/noxfile.py +++ b/packages/google-cloud-monitoring-dashboards/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -639,23 +638,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-monitoring-metrics-scopes/noxfile.py b/packages/google-cloud-monitoring-metrics-scopes/noxfile.py index ec1fb7ce1fa9..c28daef40ff2 100644 --- a/packages/google-cloud-monitoring-metrics-scopes/noxfile.py +++ b/packages/google-cloud-monitoring-metrics-scopes/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-monitoring/noxfile.py b/packages/google-cloud-monitoring/noxfile.py index 699d24e42e85..ed53a8853665 100644 --- a/packages/google-cloud-monitoring/noxfile.py +++ b/packages/google-cloud-monitoring/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -640,23 +639,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-ndb/noxfile.py b/packages/google-cloud-ndb/noxfile.py index df93c72a708b..e447badd711c 100644 --- a/packages/google-cloud-ndb/noxfile.py +++ b/packages/google-cloud-ndb/noxfile.py @@ -42,7 +42,6 @@ "pytest-cov", "google-cloud-testutils", "google-cloud-core", - "import_profile", ] # Error if a python version is missing @@ -549,23 +548,3 @@ def lint_setup_py(session): """Verify that setup.py is valid (including RST check).""" session.install("setuptools", "docutils", "pygments") session.run("python", "setup.py", "check", "--restructuredtext", "--strict") - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-netapp/noxfile.py b/packages/google-cloud-netapp/noxfile.py index 39a2b89172ad..9cdc985be32a 100644 --- a/packages/google-cloud-netapp/noxfile.py +++ b/packages/google-cloud-netapp/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-network-connectivity/noxfile.py b/packages/google-cloud-network-connectivity/noxfile.py index b04ae0d286d9..52a57bff4416 100644 --- a/packages/google-cloud-network-connectivity/noxfile.py +++ b/packages/google-cloud-network-connectivity/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-network-management/noxfile.py b/packages/google-cloud-network-management/noxfile.py index e33d535129b7..c30a6b93d952 100644 --- a/packages/google-cloud-network-management/noxfile.py +++ b/packages/google-cloud-network-management/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-network-security/noxfile.py b/packages/google-cloud-network-security/noxfile.py index d524908a6539..14d2cb6a6f53 100644 --- a/packages/google-cloud-network-security/noxfile.py +++ b/packages/google-cloud-network-security/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-network-services/noxfile.py b/packages/google-cloud-network-services/noxfile.py index b0c63c6a8e25..7061cef385ac 100644 --- a/packages/google-cloud-network-services/noxfile.py +++ b/packages/google-cloud-network-services/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-notebooks/noxfile.py b/packages/google-cloud-notebooks/noxfile.py index cc50622d53f5..215850a5af4b 100644 --- a/packages/google-cloud-notebooks/noxfile.py +++ b/packages/google-cloud-notebooks/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-optimization/noxfile.py b/packages/google-cloud-optimization/noxfile.py index c6c3b1529d3f..b023be356097 100644 --- a/packages/google-cloud-optimization/noxfile.py +++ b/packages/google-cloud-optimization/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-oracledatabase/noxfile.py b/packages/google-cloud-oracledatabase/noxfile.py index 6e796e3b41da..22a47f0fa4ff 100644 --- a/packages/google-cloud-oracledatabase/noxfile.py +++ b/packages/google-cloud-oracledatabase/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-orchestration-airflow/noxfile.py b/packages/google-cloud-orchestration-airflow/noxfile.py index 6224c709b075..0d1aed8f2c70 100644 --- a/packages/google-cloud-orchestration-airflow/noxfile.py +++ b/packages/google-cloud-orchestration-airflow/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-org-policy/noxfile.py b/packages/google-cloud-org-policy/noxfile.py index 8471e50c6acd..6cf84cb47c03 100644 --- a/packages/google-cloud-org-policy/noxfile.py +++ b/packages/google-cloud-org-policy/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-os-config/noxfile.py b/packages/google-cloud-os-config/noxfile.py index d5f09f26bb2b..5a23e3023a8b 100644 --- a/packages/google-cloud-os-config/noxfile.py +++ b/packages/google-cloud-os-config/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-os-login/noxfile.py b/packages/google-cloud-os-login/noxfile.py index 9e2105ef776c..8f85dfe7f505 100644 --- a/packages/google-cloud-os-login/noxfile.py +++ b/packages/google-cloud-os-login/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-parallelstore/noxfile.py b/packages/google-cloud-parallelstore/noxfile.py index 9f8fd7bceabf..9797fedc7bb5 100644 --- a/packages/google-cloud-parallelstore/noxfile.py +++ b/packages/google-cloud-parallelstore/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-parametermanager/noxfile.py b/packages/google-cloud-parametermanager/noxfile.py index f3b0eaa78cdc..7cc0bf8cba28 100644 --- a/packages/google-cloud-parametermanager/noxfile.py +++ b/packages/google-cloud-parametermanager/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-phishing-protection/noxfile.py b/packages/google-cloud-phishing-protection/noxfile.py index ae30b0f33058..26b29d321260 100644 --- a/packages/google-cloud-phishing-protection/noxfile.py +++ b/packages/google-cloud-phishing-protection/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-policy-troubleshooter/noxfile.py b/packages/google-cloud-policy-troubleshooter/noxfile.py index 2c65c0758729..e58bdb90dc5d 100644 --- a/packages/google-cloud-policy-troubleshooter/noxfile.py +++ b/packages/google-cloud-policy-troubleshooter/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-policysimulator/noxfile.py b/packages/google-cloud-policysimulator/noxfile.py index a550b1379466..3d3c18d50ed7 100644 --- a/packages/google-cloud-policysimulator/noxfile.py +++ b/packages/google-cloud-policysimulator/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-policytroubleshooter-iam/noxfile.py b/packages/google-cloud-policytroubleshooter-iam/noxfile.py index d4a6848e245c..64b3a1946ab8 100644 --- a/packages/google-cloud-policytroubleshooter-iam/noxfile.py +++ b/packages/google-cloud-policytroubleshooter-iam/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-private-ca/noxfile.py b/packages/google-cloud-private-ca/noxfile.py index 0791331c0253..63dbc9f15da1 100644 --- a/packages/google-cloud-private-ca/noxfile.py +++ b/packages/google-cloud-private-ca/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-private-catalog/noxfile.py b/packages/google-cloud-private-catalog/noxfile.py index 64741cfcd48f..6c62e204bc2c 100644 --- a/packages/google-cloud-private-catalog/noxfile.py +++ b/packages/google-cloud-private-catalog/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-privilegedaccessmanager/noxfile.py b/packages/google-cloud-privilegedaccessmanager/noxfile.py index 7f79a1900328..59636262695a 100644 --- a/packages/google-cloud-privilegedaccessmanager/noxfile.py +++ b/packages/google-cloud-privilegedaccessmanager/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-pubsub/noxfile.py b/packages/google-cloud-pubsub/noxfile.py index c40cf145ed91..fb01bc8d1105 100644 --- a/packages/google-cloud-pubsub/noxfile.py +++ b/packages/google-cloud-pubsub/noxfile.py @@ -36,7 +36,6 @@ "3.12", "3.13", "3.14", - "import_profile", ] DEFAULT_PYTHON_VERSION = "3.14" @@ -624,23 +623,3 @@ def prerelease_deps(session, protobuf_implementation): def core_deps_from_source(session, protobuf_implementation): """Skipping until Pub/Sub migration is complete.""" session.skip("Skipping core_deps_from_source for google-cloud-pubsub.") - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-quotas/noxfile.py b/packages/google-cloud-quotas/noxfile.py index ff590a6a28d5..53416e6741d4 100644 --- a/packages/google-cloud-quotas/noxfile.py +++ b/packages/google-cloud-quotas/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-rapidmigrationassessment/noxfile.py b/packages/google-cloud-rapidmigrationassessment/noxfile.py index bf112a91dcfe..7963a1ae7b82 100644 --- a/packages/google-cloud-rapidmigrationassessment/noxfile.py +++ b/packages/google-cloud-rapidmigrationassessment/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-recaptcha-enterprise/noxfile.py b/packages/google-cloud-recaptcha-enterprise/noxfile.py index 08c1d42ded16..cc7f5fec5d0c 100644 --- a/packages/google-cloud-recaptcha-enterprise/noxfile.py +++ b/packages/google-cloud-recaptcha-enterprise/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-recommendations-ai/noxfile.py b/packages/google-cloud-recommendations-ai/noxfile.py index 24205aad018c..1b1048928076 100644 --- a/packages/google-cloud-recommendations-ai/noxfile.py +++ b/packages/google-cloud-recommendations-ai/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-recommender/noxfile.py b/packages/google-cloud-recommender/noxfile.py index 3bbb4d6fc22c..144f17361952 100644 --- a/packages/google-cloud-recommender/noxfile.py +++ b/packages/google-cloud-recommender/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-redis-cluster/noxfile.py b/packages/google-cloud-redis-cluster/noxfile.py index 88572b019370..04445b2b2ed8 100644 --- a/packages/google-cloud-redis-cluster/noxfile.py +++ b/packages/google-cloud-redis-cluster/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-redis/noxfile.py b/packages/google-cloud-redis/noxfile.py index 7607858dbbe2..1aaaa5ee824f 100644 --- a/packages/google-cloud-redis/noxfile.py +++ b/packages/google-cloud-redis/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-resource-manager/noxfile.py b/packages/google-cloud-resource-manager/noxfile.py index a048a5a726d1..d767a44baff2 100644 --- a/packages/google-cloud-resource-manager/noxfile.py +++ b/packages/google-cloud-resource-manager/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-retail/noxfile.py b/packages/google-cloud-retail/noxfile.py index 3f2ea9e83f3b..fab57e38aee8 100644 --- a/packages/google-cloud-retail/noxfile.py +++ b/packages/google-cloud-retail/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-run/noxfile.py b/packages/google-cloud-run/noxfile.py index 3c503ba88328..4c75b5e990d9 100644 --- a/packages/google-cloud-run/noxfile.py +++ b/packages/google-cloud-run/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-runtimeconfig/noxfile.py b/packages/google-cloud-runtimeconfig/noxfile.py index 59f316735c54..42e77572607e 100644 --- a/packages/google-cloud-runtimeconfig/noxfile.py +++ b/packages/google-cloud-runtimeconfig/noxfile.py @@ -509,23 +509,3 @@ def core_deps_from_source(session): system_test_folder_path, *session.posargs, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-saasplatform-saasservicemgmt/noxfile.py b/packages/google-cloud-saasplatform-saasservicemgmt/noxfile.py index 5cde0760ad88..554ed2d56036 100644 --- a/packages/google-cloud-saasplatform-saasservicemgmt/noxfile.py +++ b/packages/google-cloud-saasplatform-saasservicemgmt/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-scheduler/noxfile.py b/packages/google-cloud-scheduler/noxfile.py index b2827bf02f60..55917f9775bc 100644 --- a/packages/google-cloud-scheduler/noxfile.py +++ b/packages/google-cloud-scheduler/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-secret-manager/noxfile.py b/packages/google-cloud-secret-manager/noxfile.py index 46ab2efa1ad6..3efeca5e9834 100644 --- a/packages/google-cloud-secret-manager/noxfile.py +++ b/packages/google-cloud-secret-manager/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-securesourcemanager/noxfile.py b/packages/google-cloud-securesourcemanager/noxfile.py index dc61c4d3981e..1f33a21f0c23 100644 --- a/packages/google-cloud-securesourcemanager/noxfile.py +++ b/packages/google-cloud-securesourcemanager/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-security-publicca/noxfile.py b/packages/google-cloud-security-publicca/noxfile.py index 2c2d5ea26f3c..e7c9130eecea 100644 --- a/packages/google-cloud-security-publicca/noxfile.py +++ b/packages/google-cloud-security-publicca/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-securitycenter/noxfile.py b/packages/google-cloud-securitycenter/noxfile.py index 533350603995..f0c5e28a829e 100644 --- a/packages/google-cloud-securitycenter/noxfile.py +++ b/packages/google-cloud-securitycenter/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-securitycentermanagement/noxfile.py b/packages/google-cloud-securitycentermanagement/noxfile.py index 2a61726a9504..6a6d67de2999 100644 --- a/packages/google-cloud-securitycentermanagement/noxfile.py +++ b/packages/google-cloud-securitycentermanagement/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-service-control/noxfile.py b/packages/google-cloud-service-control/noxfile.py index 372155b76146..3d3b1d64d329 100644 --- a/packages/google-cloud-service-control/noxfile.py +++ b/packages/google-cloud-service-control/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-service-directory/noxfile.py b/packages/google-cloud-service-directory/noxfile.py index e827649bb22c..70e9c93bbe31 100644 --- a/packages/google-cloud-service-directory/noxfile.py +++ b/packages/google-cloud-service-directory/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-service-management/noxfile.py b/packages/google-cloud-service-management/noxfile.py index 3f82574cbb9a..b647a373a1ed 100644 --- a/packages/google-cloud-service-management/noxfile.py +++ b/packages/google-cloud-service-management/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-service-usage/noxfile.py b/packages/google-cloud-service-usage/noxfile.py index 6a2bca1caa75..257a0a3d32c2 100644 --- a/packages/google-cloud-service-usage/noxfile.py +++ b/packages/google-cloud-service-usage/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-servicehealth/noxfile.py b/packages/google-cloud-servicehealth/noxfile.py index d2eaed1a29dc..0fc8677b4458 100644 --- a/packages/google-cloud-servicehealth/noxfile.py +++ b/packages/google-cloud-servicehealth/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-shell/noxfile.py b/packages/google-cloud-shell/noxfile.py index 708180a0fc23..e28e2365335d 100644 --- a/packages/google-cloud-shell/noxfile.py +++ b/packages/google-cloud-shell/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-source-context/noxfile.py b/packages/google-cloud-source-context/noxfile.py index 864433def8e1..6488b4a11907 100644 --- a/packages/google-cloud-source-context/noxfile.py +++ b/packages/google-cloud-source-context/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-spanner-dbapi-driver/noxfile.py b/packages/google-cloud-spanner-dbapi-driver/noxfile.py index 2803c63894c7..2fedee7ee5af 100644 --- a/packages/google-cloud-spanner-dbapi-driver/noxfile.py +++ b/packages/google-cloud-spanner-dbapi-driver/noxfile.py @@ -94,7 +94,6 @@ "lint", "lint_setup_py", "docs", - "import_profile", ] # Error if a python version is missing @@ -605,23 +604,3 @@ def install(session): Install locally """ session.install("-e", ".") - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-spanner/noxfile.py b/packages/google-cloud-spanner/noxfile.py index 58e9ce45a7f7..fa74716b8142 100644 --- a/packages/google-cloud-spanner/noxfile.py +++ b/packages/google-cloud-spanner/noxfile.py @@ -36,7 +36,6 @@ "3.12", "3.13", "3.14", - "import_profile", ] UNIT_TEST_STANDARD_DEPENDENCIES = [ "mock", @@ -849,23 +848,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-speech/noxfile.py b/packages/google-cloud-speech/noxfile.py index e96d284fe06f..bc07809189ba 100644 --- a/packages/google-cloud-speech/noxfile.py +++ b/packages/google-cloud-speech/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -639,23 +638,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-storage-control/noxfile.py b/packages/google-cloud-storage-control/noxfile.py index 63fc57413c49..b4ade172c441 100644 --- a/packages/google-cloud-storage-control/noxfile.py +++ b/packages/google-cloud-storage-control/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-storage-transfer/noxfile.py b/packages/google-cloud-storage-transfer/noxfile.py index a3a623842a73..ef9feee7ac3a 100644 --- a/packages/google-cloud-storage-transfer/noxfile.py +++ b/packages/google-cloud-storage-transfer/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-storage/noxfile.py b/packages/google-cloud-storage/noxfile.py index 8eaf373a7497..6e8d41c60b3d 100644 --- a/packages/google-cloud-storage/noxfile.py +++ b/packages/google-cloud-storage/noxfile.py @@ -94,7 +94,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -713,23 +712,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-storagebatchoperations/noxfile.py b/packages/google-cloud-storagebatchoperations/noxfile.py index 2b3659c6b128..dbd49e2ac733 100644 --- a/packages/google-cloud-storagebatchoperations/noxfile.py +++ b/packages/google-cloud-storagebatchoperations/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-storageinsights/noxfile.py b/packages/google-cloud-storageinsights/noxfile.py index a9c0bd98deee..dfe9e473684a 100644 --- a/packages/google-cloud-storageinsights/noxfile.py +++ b/packages/google-cloud-storageinsights/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-support/noxfile.py b/packages/google-cloud-support/noxfile.py index 2b45313baa74..f5db58067a57 100644 --- a/packages/google-cloud-support/noxfile.py +++ b/packages/google-cloud-support/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-talent/noxfile.py b/packages/google-cloud-talent/noxfile.py index dca6d5478a3a..c77bb19d1a87 100644 --- a/packages/google-cloud-talent/noxfile.py +++ b/packages/google-cloud-talent/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-tasks/noxfile.py b/packages/google-cloud-tasks/noxfile.py index 94cf83c01a0f..5d43c1960802 100644 --- a/packages/google-cloud-tasks/noxfile.py +++ b/packages/google-cloud-tasks/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-telcoautomation/noxfile.py b/packages/google-cloud-telcoautomation/noxfile.py index 06bf9b9729bf..0516d14eba3d 100644 --- a/packages/google-cloud-telcoautomation/noxfile.py +++ b/packages/google-cloud-telcoautomation/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-testutils/noxfile.py b/packages/google-cloud-testutils/noxfile.py index 452a8cecc92f..0e86a298190e 100644 --- a/packages/google-cloud-testutils/noxfile.py +++ b/packages/google-cloud-testutils/noxfile.py @@ -27,7 +27,6 @@ nox.options.sessions = [ "check_lower_bounds", "format", - "import_profile", ] @@ -384,23 +383,3 @@ def core_deps_from_source(session): "py.test", "tests/unit", ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-texttospeech/noxfile.py b/packages/google-cloud-texttospeech/noxfile.py index 854bd4390049..b5467a458b91 100644 --- a/packages/google-cloud-texttospeech/noxfile.py +++ b/packages/google-cloud-texttospeech/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-tpu/noxfile.py b/packages/google-cloud-tpu/noxfile.py index 86182ecd9d84..ad1769c6ddb5 100644 --- a/packages/google-cloud-tpu/noxfile.py +++ b/packages/google-cloud-tpu/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-trace/noxfile.py b/packages/google-cloud-trace/noxfile.py index b9e776ea8b43..39a6649e1562 100644 --- a/packages/google-cloud-trace/noxfile.py +++ b/packages/google-cloud-trace/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-translate/noxfile.py b/packages/google-cloud-translate/noxfile.py index 6519a4a97734..0f6ce885ea75 100644 --- a/packages/google-cloud-translate/noxfile.py +++ b/packages/google-cloud-translate/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-vectorsearch/noxfile.py b/packages/google-cloud-vectorsearch/noxfile.py index 5dd818f913e9..a0a96a3b681b 100644 --- a/packages/google-cloud-vectorsearch/noxfile.py +++ b/packages/google-cloud-vectorsearch/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-video-live-stream/noxfile.py b/packages/google-cloud-video-live-stream/noxfile.py index fe58299473cb..f655209973ee 100644 --- a/packages/google-cloud-video-live-stream/noxfile.py +++ b/packages/google-cloud-video-live-stream/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-video-stitcher/noxfile.py b/packages/google-cloud-video-stitcher/noxfile.py index aa6cd92cd591..0aee9c67760b 100644 --- a/packages/google-cloud-video-stitcher/noxfile.py +++ b/packages/google-cloud-video-stitcher/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-video-transcoder/noxfile.py b/packages/google-cloud-video-transcoder/noxfile.py index 181078acde80..6947719b3abd 100644 --- a/packages/google-cloud-video-transcoder/noxfile.py +++ b/packages/google-cloud-video-transcoder/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-videointelligence/noxfile.py b/packages/google-cloud-videointelligence/noxfile.py index 9b62642fc281..ea240e5ae562 100644 --- a/packages/google-cloud-videointelligence/noxfile.py +++ b/packages/google-cloud-videointelligence/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-vision/noxfile.py b/packages/google-cloud-vision/noxfile.py index 34805fef8639..a8c68f537b0c 100644 --- a/packages/google-cloud-vision/noxfile.py +++ b/packages/google-cloud-vision/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -639,23 +638,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-visionai/noxfile.py b/packages/google-cloud-visionai/noxfile.py index d17e0baf7e77..14c9964d9a0e 100644 --- a/packages/google-cloud-visionai/noxfile.py +++ b/packages/google-cloud-visionai/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-vm-migration/noxfile.py b/packages/google-cloud-vm-migration/noxfile.py index aa1cd44d4f90..d8f091d84d1d 100644 --- a/packages/google-cloud-vm-migration/noxfile.py +++ b/packages/google-cloud-vm-migration/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-vmwareengine/noxfile.py b/packages/google-cloud-vmwareengine/noxfile.py index 677cbc92f7ff..7f6b1caa7cca 100644 --- a/packages/google-cloud-vmwareengine/noxfile.py +++ b/packages/google-cloud-vmwareengine/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-vpc-access/noxfile.py b/packages/google-cloud-vpc-access/noxfile.py index 94988fdf9484..a7fb5d0c91e1 100644 --- a/packages/google-cloud-vpc-access/noxfile.py +++ b/packages/google-cloud-vpc-access/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-webrisk/noxfile.py b/packages/google-cloud-webrisk/noxfile.py index a7b38b08a2fa..0f2c3773d9fe 100644 --- a/packages/google-cloud-webrisk/noxfile.py +++ b/packages/google-cloud-webrisk/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-websecurityscanner/noxfile.py b/packages/google-cloud-websecurityscanner/noxfile.py index ceaa5aedd223..9f29ec42138c 100644 --- a/packages/google-cloud-websecurityscanner/noxfile.py +++ b/packages/google-cloud-websecurityscanner/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-workflows/noxfile.py b/packages/google-cloud-workflows/noxfile.py index c8425a74129f..1dcb81730459 100644 --- a/packages/google-cloud-workflows/noxfile.py +++ b/packages/google-cloud-workflows/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-workloadmanager/noxfile.py b/packages/google-cloud-workloadmanager/noxfile.py index da7c9faec917..b6227bea2e3b 100644 --- a/packages/google-cloud-workloadmanager/noxfile.py +++ b/packages/google-cloud-workloadmanager/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-workstations/noxfile.py b/packages/google-cloud-workstations/noxfile.py index 9c7cb0b11472..29ad30aa8dce 100644 --- a/packages/google-cloud-workstations/noxfile.py +++ b/packages/google-cloud-workstations/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-developer-knowledge/noxfile.py b/packages/google-developer-knowledge/noxfile.py index cde71f0d9a38..24048446e495 100644 --- a/packages/google-developer-knowledge/noxfile.py +++ b/packages/google-developer-knowledge/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-devicesandservices-health/noxfile.py b/packages/google-devicesandservices-health/noxfile.py index 99e05fde845c..167314ff8a7a 100644 --- a/packages/google-devicesandservices-health/noxfile.py +++ b/packages/google-devicesandservices-health/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-geo-type/noxfile.py b/packages/google-geo-type/noxfile.py index ca149a2653fb..c7dd9bef9aaa 100644 --- a/packages/google-geo-type/noxfile.py +++ b/packages/google-geo-type/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-maps-addressvalidation/noxfile.py b/packages/google-maps-addressvalidation/noxfile.py index 876662bf4752..680ee645d9d6 100644 --- a/packages/google-maps-addressvalidation/noxfile.py +++ b/packages/google-maps-addressvalidation/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-maps-areainsights/noxfile.py b/packages/google-maps-areainsights/noxfile.py index 3cf8cac0ec50..6c48887a54f5 100644 --- a/packages/google-maps-areainsights/noxfile.py +++ b/packages/google-maps-areainsights/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-maps-fleetengine-delivery/noxfile.py b/packages/google-maps-fleetengine-delivery/noxfile.py index 4bcdfb09fa03..965946a51d4c 100644 --- a/packages/google-maps-fleetengine-delivery/noxfile.py +++ b/packages/google-maps-fleetengine-delivery/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-maps-fleetengine/noxfile.py b/packages/google-maps-fleetengine/noxfile.py index d2fc100ed5c8..a4e7bf463821 100644 --- a/packages/google-maps-fleetengine/noxfile.py +++ b/packages/google-maps-fleetengine/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-maps-geocode/noxfile.py b/packages/google-maps-geocode/noxfile.py index 2d338faa8484..6a24a982cd73 100644 --- a/packages/google-maps-geocode/noxfile.py +++ b/packages/google-maps-geocode/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-maps-mapmanagement/noxfile.py b/packages/google-maps-mapmanagement/noxfile.py index 7835257f02b2..253e9b89e435 100644 --- a/packages/google-maps-mapmanagement/noxfile.py +++ b/packages/google-maps-mapmanagement/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-maps-mapsplatformdatasets/noxfile.py b/packages/google-maps-mapsplatformdatasets/noxfile.py index f210fd9d8e54..d04d30a53abe 100644 --- a/packages/google-maps-mapsplatformdatasets/noxfile.py +++ b/packages/google-maps-mapsplatformdatasets/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-maps-navconnect/noxfile.py b/packages/google-maps-navconnect/noxfile.py index f88bf58c5ecd..1d057e793d4b 100644 --- a/packages/google-maps-navconnect/noxfile.py +++ b/packages/google-maps-navconnect/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-maps-places/noxfile.py b/packages/google-maps-places/noxfile.py index fde6497d963a..e27fd8dfee63 100644 --- a/packages/google-maps-places/noxfile.py +++ b/packages/google-maps-places/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-maps-routeoptimization/noxfile.py b/packages/google-maps-routeoptimization/noxfile.py index 20cff4c84f1c..8293b48192cf 100644 --- a/packages/google-maps-routeoptimization/noxfile.py +++ b/packages/google-maps-routeoptimization/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-maps-routing/noxfile.py b/packages/google-maps-routing/noxfile.py index 6473b5ce489e..e2059db87494 100644 --- a/packages/google-maps-routing/noxfile.py +++ b/packages/google-maps-routing/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-maps-solar/noxfile.py b/packages/google-maps-solar/noxfile.py index 1424432a2578..f08fec5fb5d2 100644 --- a/packages/google-maps-solar/noxfile.py +++ b/packages/google-maps-solar/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-resumable-media/noxfile.py b/packages/google-resumable-media/noxfile.py index 98913bef43b0..a1c1ae199709 100644 --- a/packages/google-resumable-media/noxfile.py +++ b/packages/google-resumable-media/noxfile.py @@ -37,7 +37,6 @@ "blacken", "mypy", "doctest", - "import_profile", ] @@ -449,23 +448,3 @@ def core_deps_from_source(session): os.path.join("tests_async", "unit"), *session.posargs, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-shopping-css/noxfile.py b/packages/google-shopping-css/noxfile.py index b3f481bab451..02e587c9552e 100644 --- a/packages/google-shopping-css/noxfile.py +++ b/packages/google-shopping-css/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-shopping-merchant-accounts/noxfile.py b/packages/google-shopping-merchant-accounts/noxfile.py index 532bd620a34a..0616e719e46a 100644 --- a/packages/google-shopping-merchant-accounts/noxfile.py +++ b/packages/google-shopping-merchant-accounts/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-shopping-merchant-conversions/noxfile.py b/packages/google-shopping-merchant-conversions/noxfile.py index 26cf2c084ffd..a68d0e59fb95 100644 --- a/packages/google-shopping-merchant-conversions/noxfile.py +++ b/packages/google-shopping-merchant-conversions/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-shopping-merchant-datasources/noxfile.py b/packages/google-shopping-merchant-datasources/noxfile.py index 680dbe0227e5..a127b28df77e 100644 --- a/packages/google-shopping-merchant-datasources/noxfile.py +++ b/packages/google-shopping-merchant-datasources/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-shopping-merchant-inventories/noxfile.py b/packages/google-shopping-merchant-inventories/noxfile.py index 516088661daa..0e2b1e69e4c3 100644 --- a/packages/google-shopping-merchant-inventories/noxfile.py +++ b/packages/google-shopping-merchant-inventories/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-shopping-merchant-issueresolution/noxfile.py b/packages/google-shopping-merchant-issueresolution/noxfile.py index 5e67ff92e118..2969c82734bc 100644 --- a/packages/google-shopping-merchant-issueresolution/noxfile.py +++ b/packages/google-shopping-merchant-issueresolution/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-shopping-merchant-lfp/noxfile.py b/packages/google-shopping-merchant-lfp/noxfile.py index 5f58ef1c31c0..9afbefc28ecc 100644 --- a/packages/google-shopping-merchant-lfp/noxfile.py +++ b/packages/google-shopping-merchant-lfp/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-shopping-merchant-notifications/noxfile.py b/packages/google-shopping-merchant-notifications/noxfile.py index 7342a58c170b..469d1b1ee453 100644 --- a/packages/google-shopping-merchant-notifications/noxfile.py +++ b/packages/google-shopping-merchant-notifications/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-shopping-merchant-ordertracking/noxfile.py b/packages/google-shopping-merchant-ordertracking/noxfile.py index c853353fa5cc..8d7bfd0b33cb 100644 --- a/packages/google-shopping-merchant-ordertracking/noxfile.py +++ b/packages/google-shopping-merchant-ordertracking/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-shopping-merchant-products/noxfile.py b/packages/google-shopping-merchant-products/noxfile.py index 133dfa410bec..f4f76c8c8be5 100644 --- a/packages/google-shopping-merchant-products/noxfile.py +++ b/packages/google-shopping-merchant-products/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-shopping-merchant-productstudio/noxfile.py b/packages/google-shopping-merchant-productstudio/noxfile.py index bba0cbbf13ed..dbb49a1245ba 100644 --- a/packages/google-shopping-merchant-productstudio/noxfile.py +++ b/packages/google-shopping-merchant-productstudio/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-shopping-merchant-promotions/noxfile.py b/packages/google-shopping-merchant-promotions/noxfile.py index 7f673392b5d6..1202be8a0b25 100644 --- a/packages/google-shopping-merchant-promotions/noxfile.py +++ b/packages/google-shopping-merchant-promotions/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-shopping-merchant-quota/noxfile.py b/packages/google-shopping-merchant-quota/noxfile.py index 0bd9a74cef3a..a6fe68f6bdbc 100644 --- a/packages/google-shopping-merchant-quota/noxfile.py +++ b/packages/google-shopping-merchant-quota/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-shopping-merchant-reports/noxfile.py b/packages/google-shopping-merchant-reports/noxfile.py index 2776c5afe67e..2d85b52ed1b7 100644 --- a/packages/google-shopping-merchant-reports/noxfile.py +++ b/packages/google-shopping-merchant-reports/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-shopping-merchant-reviews/noxfile.py b/packages/google-shopping-merchant-reviews/noxfile.py index 7965d9402799..676575644598 100644 --- a/packages/google-shopping-merchant-reviews/noxfile.py +++ b/packages/google-shopping-merchant-reviews/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/google-shopping-type/noxfile.py b/packages/google-shopping-type/noxfile.py index efa0f6b56d2c..ca47d4a3725e 100644 --- a/packages/google-shopping-type/noxfile.py +++ b/packages/google-shopping-type/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/googleapis-common-protos/noxfile.py b/packages/googleapis-common-protos/noxfile.py index 5aaaef4e36d3..ce20cdcfcad8 100644 --- a/packages/googleapis-common-protos/noxfile.py +++ b/packages/googleapis-common-protos/noxfile.py @@ -85,7 +85,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -600,23 +599,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/grafeas/noxfile.py b/packages/grafeas/noxfile.py index c8d718b8cb48..d0d5199c2bd5 100644 --- a/packages/grafeas/noxfile.py +++ b/packages/grafeas/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,23 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "grafeas", - "--iterations", - "10", - ) diff --git a/packages/grpc-google-iam-v1/noxfile.py b/packages/grpc-google-iam-v1/noxfile.py index 7f36d938a092..6d0703ed100b 100644 --- a/packages/grpc-google-iam-v1/noxfile.py +++ b/packages/grpc-google-iam-v1/noxfile.py @@ -85,7 +85,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -585,23 +584,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/pandas-gbq/noxfile.py b/packages/pandas-gbq/noxfile.py index ac2c70e36407..8e58d09628bc 100644 --- a/packages/pandas-gbq/noxfile.py +++ b/packages/pandas-gbq/noxfile.py @@ -110,7 +110,6 @@ def wrapper(*args, **kwargs): "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -596,23 +595,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/proto-plus/noxfile.py b/packages/proto-plus/noxfile.py index ad4d80f2703e..4e07083cd49c 100644 --- a/packages/proto-plus/noxfile.py +++ b/packages/proto-plus/noxfile.py @@ -353,23 +353,3 @@ def format(session): "--line-length=88", *LINT_PATHS, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/sqlalchemy-bigquery/noxfile.py b/packages/sqlalchemy-bigquery/noxfile.py index 41e81fa1fff1..b1e6b068c872 100644 --- a/packages/sqlalchemy-bigquery/noxfile.py +++ b/packages/sqlalchemy-bigquery/noxfile.py @@ -40,7 +40,6 @@ "tests", "noxfile.py", "setup.py", - "import_profile", ] DEFAULT_PYTHON_VERSION = "3.14" @@ -743,23 +742,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) diff --git a/packages/sqlalchemy-spanner/noxfile.py b/packages/sqlalchemy-spanner/noxfile.py index 597d728dcf1b..187d4e7e8924 100644 --- a/packages/sqlalchemy-spanner/noxfile.py +++ b/packages/sqlalchemy-spanner/noxfile.py @@ -85,7 +85,6 @@ class = StreamHandler UNIT_TEST_STANDARD_DEPENDENCIES = [ "mock", "pytest", - "import_profile", ] UNIT_TEST_EXTERNAL_DEPENDENCIES = [ @@ -605,23 +604,3 @@ def format(session): "--line-length=88", *LINT_PATHS, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - "google", - "--iterations", - "10", - ) From a6491b579364fd8224c127b371070829608344e3 Mon Sep 17 00:00:00 2001 From: Heba Alazzeh Date: Wed, 8 Jul 2026 16:28:45 +0000 Subject: [PATCH 09/13] ci: run import_profile without nox templates --- ci/run_single_test.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ci/run_single_test.sh b/ci/run_single_test.sh index aa158c4d342c..bd3ab70ec3ac 100755 --- a/ci/run_single_test.sh +++ b/ci/run_single_test.sh @@ -105,6 +105,29 @@ case ${TEST_TYPE} in ;; esac ;; + import_profile) + python -m pip install . + PKG_NAME=$(python setup.py --name) + MODULE=$(python -c " +import sys, importlib.util +pkg = '${PKG_NAME}' +candidates = [ + pkg.replace('-', '.'), + '.'.join(pkg.split('-')[:-1]) + '_' + pkg.split('-')[-1] if '-' in pkg else pkg, + pkg.replace('-', '_') +] +for mod in candidates: + try: + if importlib.util.find_spec(mod): + print(mod) + sys.exit(0) + except Exception: + pass +print(candidates[0]) +") + python ${PROJECT_ROOT}/scripts/import_profiler/profiler.py --module "${MODULE}" --iterations 10 + retval=$? + ;; *) nox -s ${TEST_TYPE} retval=$? From 9472ab6b75c413a0bb805afa90f94910e10c44b2 Mon Sep 17 00:00:00 2001 From: Heba Alazzeh Date: Wed, 8 Jul 2026 23:00:37 +0000 Subject: [PATCH 10/13] address PR comments for import profiler CI --- .github/workflows/import-profiler.yml | 2 +- ci/run_single_test.sh | 28 +++--------- .../gapic/templates/noxfile.py.j2 | 27 ++++++++++++ packages/google-cloud-asset/noxfile.py | 23 ++++++++++ packages/google-cloud-asset/test_trigger.txt | 0 scripts/import_profiler/profiler.py | 43 ++++++++++++++++--- 6 files changed, 94 insertions(+), 29 deletions(-) create mode 100644 packages/google-cloud-asset/test_trigger.txt diff --git a/.github/workflows/import-profiler.yml b/.github/workflows/import-profiler.yml index 14671c5c878d..dc0821f67688 100644 --- a/.github/workflows/import-profiler.yml +++ b/.github/workflows/import-profiler.yml @@ -31,7 +31,7 @@ jobs: python -m pip install nox - name: Run import profiler env: - BUILD_TYPE: presubmit + BUILD_TYPE: ${{ contains(github.event.pull_request.labels.*.name, 'import_profile:all_packages') && 'all' || 'presubmit' }} TARGET_BRANCH: ${{ github.base_ref || github.event.merge_group.base_ref }} TEST_TYPE: import_profile PY_VERSION: "3.15" diff --git a/ci/run_single_test.sh b/ci/run_single_test.sh index bd3ab70ec3ac..0ca61bba6bf4 100755 --- a/ci/run_single_test.sh +++ b/ci/run_single_test.sh @@ -106,27 +106,13 @@ case ${TEST_TYPE} in esac ;; import_profile) - python -m pip install . - PKG_NAME=$(python setup.py --name) - MODULE=$(python -c " -import sys, importlib.util -pkg = '${PKG_NAME}' -candidates = [ - pkg.replace('-', '.'), - '.'.join(pkg.split('-')[:-1]) + '_' + pkg.split('-')[-1] if '-' in pkg else pkg, - pkg.replace('-', '_') -] -for mod in candidates: - try: - if importlib.util.find_spec(mod): - print(mod) - sys.exit(0) - except Exception: - pass -print(candidates[0]) -") - python ${PROJECT_ROOT}/scripts/import_profiler/profiler.py --module "${MODULE}" --iterations 10 - retval=$? + if nox --list-sessions | grep -q "import_profile"; then + nox -s import_profile + retval=$? + else + echo "Skipping import_profile as it is not supported by this package yet." + retval=0 + fi ;; *) nox -s ${TEST_TYPE} diff --git a/packages/gapic-generator/gapic/templates/noxfile.py.j2 b/packages/gapic-generator/gapic/templates/noxfile.py.j2 index 8db595319396..bf71ca487ba7 100644 --- a/packages/gapic-generator/gapic/templates/noxfile.py.j2 +++ b/packages/gapic-generator/gapic/templates/noxfile.py.j2 @@ -86,6 +86,7 @@ nox.options.sessions = [ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -641,4 +642,30 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + + session.install(".") + session.run( + "python", + str(profiler_script), + "--module", + {% if api.naming.module_namespace %} + "{{ api.naming.module_namespace[0] }}", + {% else %} + "{{ api.naming.versioned_module_name }}", + {% endif %} + "--iterations", + "10", + "--fail-threshold", + "5000", + ) {% endblock %} diff --git a/packages/google-cloud-asset/noxfile.py b/packages/google-cloud-asset/noxfile.py index b044cb25e9bd..080996a9fa45 100644 --- a/packages/google-cloud-asset/noxfile.py +++ b/packages/google-cloud-asset/noxfile.py @@ -88,6 +88,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -637,3 +638,25 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + + session.install(".") + session.run( + "python", + str(profiler_script), + "--package", + "google-cloud-asset", + "--iterations", + "10", + "--fail-threshold", + "5000", + ) diff --git a/packages/google-cloud-asset/test_trigger.txt b/packages/google-cloud-asset/test_trigger.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/scripts/import_profiler/profiler.py b/scripts/import_profiler/profiler.py index 8412aaf527b7..a1bb174a1de5 100644 --- a/scripts/import_profiler/profiler.py +++ b/scripts/import_profiler/profiler.py @@ -154,7 +154,7 @@ def _format_stats(title, data, p50, p90, p99, fmt): {_format_stats("Physical RSS RAM (MB)", rss_memories, p50_rss, p90_rss, p99_rss, ".4f")}""" print(final_output.strip()) -def run_master(iterations, target_module, cpu=0, csv_path=None, clear_cache=True): +def run_master(iterations, target_module, cpu=0, csv_path=None, clear_cache=True, fail_threshold=None): """Orchestrates the benchmark.""" if iterations < 1: raise ValueError("Number of iterations must be at least 1.") @@ -229,6 +229,14 @@ def run_master(iterations, target_module, cpu=0, csv_path=None, clear_cache=True rss_memories, p50_rss, p90_rss, p99_rss ) + if fail_threshold is not None: + if p99_time > fail_threshold: + print(f"\nFAILURE: P99 import time ({p99_time:.2f} ms) exceeds the failure threshold ({fail_threshold} ms).", file=sys.stderr) + sys.exit(1) + else: + print(f"\nSUCCESS: P99 import time ({p99_time:.2f} ms) is within the failure threshold ({fail_threshold} ms).") + + def run_trace(target_module): """Generates importtime trace log and writes it to a file.""" trace_file = f"import_trace_{target_module.replace('.', '_')}.log" @@ -307,8 +315,24 @@ def validate_module_name(module_name): raise argparse.ArgumentTypeError(f"'{module_name}' is not a valid Python module identifier.") return module_name + def find_module_from_package(pkg): + candidates = [ + pkg.replace('-', '.'), + '.'.join(pkg.split('-')[:-1]) + '_' + pkg.split('-')[-1] if '-' in pkg else pkg, + pkg.replace('-', '_') + ] + for mod in candidates: + try: + if importlib.util.find_spec(mod): + return mod + except Exception: + pass + return candidates[0] + parser = argparse.ArgumentParser(description="Python SDK Import Profiler") - parser.add_argument("--module", type=validate_module_name, default="google.cloud.compute_v1", help="Target module to profile") + group = parser.add_mutually_exclusive_group(required=True) + group.add_argument("--module", type=validate_module_name, help="Target module to profile") + group.add_argument("--package", help="Target package name to profile (auto-detects module)") parser.add_argument("--iterations", type=int, default=50, help="Number of iterations") default_cpu = 0 if sys.platform.startswith("linux") else NO_CPU_PINNING parser.add_argument("--cpu", type=int, default=default_cpu, help="CPU core to pin to (or -1 for no pinning)") @@ -317,20 +341,25 @@ def validate_module_name(module_name): parser.add_argument("--cprofile", action="store_true", help="Run cProfile") parser.add_argument("--mprofile", action="store_true", help="Run tracemalloc memory snapshot") parser.add_argument("--keep-pycache", action="store_true", help="Preserve __pycache__ and allow bytecode execution (Default: False, script automatically sweeps __pycache__ for true cold-starts)") + parser.add_argument("--fail-threshold", type=float, help="Fail the profiling if the P99 time exceeds this threshold (in ms).") parser.add_argument("--worker", action="store_true", help=argparse.SUPPRESS) args = parser.parse_args() + target_module = args.module + if args.package: + target_module = find_module_from_package(args.package) + if args.worker: - run_worker(args.module) + run_worker(target_module) elif args.trace: if not args.keep_pycache: clean_bytecode() - run_trace(args.module) + run_trace(target_module) elif args.cprofile: if not args.keep_pycache: clean_bytecode() - run_cprofile(args.module) + run_cprofile(target_module) elif args.mprofile: if not args.keep_pycache: clean_bytecode() - run_mprofile(args.module) + run_mprofile(target_module) else: - run_master(args.iterations, args.module, args.cpu, args.csv, not args.keep_pycache) \ No newline at end of file + run_master(args.iterations, target_module, args.cpu, args.csv, not args.keep_pycache, args.fail_threshold) \ No newline at end of file From 705b188a22ea0054a665b901284f54c1d5476fc0 Mon Sep 17 00:00:00 2001 From: Heba Alazzeh Date: Thu, 9 Jul 2026 02:39:03 +0000 Subject: [PATCH 11/13] fix: update goldens for gapic-generator integration tests --- .../integration/goldens/asset/noxfile.py | 23 +++++++++++++++++++ .../goldens/credentials/noxfile.py | 23 +++++++++++++++++++ .../integration/goldens/eventarc/noxfile.py | 23 +++++++++++++++++++ .../integration/goldens/logging/noxfile.py | 23 +++++++++++++++++++ .../goldens/logging_internal/noxfile.py | 23 +++++++++++++++++++ .../integration/goldens/redis/noxfile.py | 23 +++++++++++++++++++ .../goldens/redis_selective/noxfile.py | 23 +++++++++++++++++++ .../goldens/storagebatchoperations/noxfile.py | 23 +++++++++++++++++++ 8 files changed, 184 insertions(+) diff --git a/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py b/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py index 09d28712c73c..4c1b4e1db6bf 100755 --- a/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py @@ -93,6 +93,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -633,3 +634,25 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + + session.install(".") + session.run( + "python", + str(profiler_script), + "--package", + "google.cloud.asset", + "--fail-threshold", + "5000", + "--iterations", + "10", + ) diff --git a/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py b/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py index 65e26efe21d3..ad8ad207936b 100755 --- a/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py @@ -93,6 +93,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -633,3 +634,25 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + + session.install(".") + session.run( + "python", + str(profiler_script), + "--package", + "google.iam.credentials", + "--fail-threshold", + "5000", + "--iterations", + "10", + ) diff --git a/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py b/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py index 42b2349e2cc1..f4e4d64cb59e 100755 --- a/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py @@ -93,6 +93,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -633,3 +634,25 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + + session.install(".") + session.run( + "python", + str(profiler_script), + "--package", + "google.cloud.eventarc_v1", + "--fail-threshold", + "5000", + "--iterations", + "10", + ) diff --git a/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py b/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py index 09e4b345592a..5557f2abc5d5 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py @@ -93,6 +93,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -633,3 +634,25 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + + session.install(".") + session.run( + "python", + str(profiler_script), + "--package", + "google.cloud.logging", + "--fail-threshold", + "5000", + "--iterations", + "10", + ) diff --git a/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py b/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py index 09e4b345592a..5557f2abc5d5 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py @@ -93,6 +93,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -633,3 +634,25 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + + session.install(".") + session.run( + "python", + str(profiler_script), + "--package", + "google.cloud.logging", + "--fail-threshold", + "5000", + "--iterations", + "10", + ) diff --git a/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py b/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py index 9b3356dd1272..ea67e32e9225 100755 --- a/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py @@ -93,6 +93,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -633,3 +634,25 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + + session.install(".") + session.run( + "python", + str(profiler_script), + "--package", + "google.cloud.redis", + "--fail-threshold", + "5000", + "--iterations", + "10", + ) diff --git a/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py b/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py index 9b3356dd1272..ea67e32e9225 100755 --- a/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py @@ -93,6 +93,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -633,3 +634,25 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + + session.install(".") + session.run( + "python", + str(profiler_script), + "--package", + "google.cloud.redis", + "--fail-threshold", + "5000", + "--iterations", + "10", + ) diff --git a/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py b/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py index db370dd3dd0f..5e7d2e70b60b 100755 --- a/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py @@ -93,6 +93,7 @@ "lint_setup_py", "blacken", "docs", + "import_profile", ] # Error if a python version is missing @@ -633,3 +634,25 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) + + +@nox.session(python="3.15") +def import_profile(session): + """Ensure import times remain below defined thresholds.""" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + + session.install(".") + session.run( + "python", + str(profiler_script), + "--package", + "google.cloud.storagebatchoperations", + "--fail-threshold", + "5000", + "--iterations", + "10", + ) From 885de7fb754de846c56ac2707ed48edc5785ff1b Mon Sep 17 00:00:00 2001 From: Heba Alazzeh Date: Thu, 9 Jul 2026 02:58:16 +0000 Subject: [PATCH 12/13] feat: implement dynamic import profile diff check against baseline --- ci/run_single_test.sh | 22 ++++- .../gapic/templates/noxfile.py.j2 | 1 + patch_goldens.py | 87 +++++++++++++++++++ scripts/import_profiler/profiler.py | 45 ++++++++-- 4 files changed, 146 insertions(+), 9 deletions(-) create mode 100644 patch_goldens.py diff --git a/ci/run_single_test.sh b/ci/run_single_test.sh index 0ca61bba6bf4..8b11dedb6af1 100755 --- a/ci/run_single_test.sh +++ b/ci/run_single_test.sh @@ -107,7 +107,27 @@ case ${TEST_TYPE} in ;; import_profile) if nox --list-sessions | grep -q "import_profile"; then - nox -s import_profile + rm -f /tmp/baseline.csv + if [ -n "${TARGET_BRANCH}" ]; then + if git rev-parse HEAD^1 >/dev/null 2>&1; then + echo "Checking out HEAD^1 for baseline..." + git checkout HEAD^1 + if nox --list-sessions | grep -q "import_profile"; then + nox -s import_profile -- --csv /tmp/baseline.csv + else + echo "No import_profile session on baseline." + fi + git checkout - + else + echo "Could not find HEAD^1. Skipping baseline generation." + fi + fi + + if [ -f /tmp/baseline.csv ]; then + nox -s import_profile -- --diff-baseline /tmp/baseline.csv --diff-threshold 100 + else + nox -s import_profile + fi retval=$? else echo "Skipping import_profile as it is not supported by this package yet." diff --git a/packages/gapic-generator/gapic/templates/noxfile.py.j2 b/packages/gapic-generator/gapic/templates/noxfile.py.j2 index bf71ca487ba7..4cc2f64350d0 100644 --- a/packages/gapic-generator/gapic/templates/noxfile.py.j2 +++ b/packages/gapic-generator/gapic/templates/noxfile.py.j2 @@ -667,5 +667,6 @@ def import_profile(session): "10", "--fail-threshold", "5000", + *session.posargs, ) {% endblock %} diff --git a/patch_goldens.py b/patch_goldens.py new file mode 100644 index 000000000000..2e4cbdbd0663 --- /dev/null +++ b/patch_goldens.py @@ -0,0 +1,87 @@ +import os +import glob +import re + +def get_module_name(golden_dir): + setup_py = os.path.join(golden_dir, "setup.py") + if not os.path.exists(setup_py): + return "google" + + with open(setup_py, "r", encoding="utf-8") as f: + content = f.read() + + match = re.search(r"'(google/[^']+)/gapic_version.py'", content) + if match: + return match.group(1).replace("/", ".") + + match = re.search(r"\"(google/[^\"]+)/gapic_version.py\"", content) + if match: + return match.group(1).replace("/", ".") + + return "google" + +def patch_noxfile(golden_dir): + path = os.path.join(golden_dir, "noxfile.py") + if not os.path.exists(path): + return False + + try: + with open(path, 'r', encoding='utf-8') as f: + content = f.read() + except UnicodeDecodeError: + return False + + module_name = get_module_name(golden_dir) + + idx = content.find("@nox.session(python=\"3.15\")\ndef import_profile(session):") + if idx != -1: + content = content[:idx].strip() + "\n" + else: + idx = content.find("@nox.session\ndef import_profile") + if idx != -1: + content = content[:idx].strip() + "\n" + + if "nox.options.sessions =" in content and "\"import_profile\"" not in content: + content = re.sub( + r'(\n\s*"docs",\n)(\s*\])', + r'\1 "import_profile",\n\2', + content + ) + + session_text = f""" +@nox.session(python="3.15") +def import_profile(session): + \"\"\"Ensure import times remain below defined thresholds.\"\"\" + profiler_script = ( + CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" + ) + if not profiler_script.exists(): + session.skip("The import profiler script was not found.") + + session.install(".") + session.run( + "python", + str(profiler_script), + "--package", + "{module_name}", + "--fail-threshold", + "5000", + "--iterations", + "10", + *session.posargs, + ) +""" + + content += "\n" + session_text + + with open(path, 'w', encoding='utf-8') as f: + f.write(content) + return True + +count = 0 +for golden_dir in glob.glob('packages/gapic-generator/tests/integration/goldens/*'): + if os.path.isdir(golden_dir): + if patch_noxfile(golden_dir): + count += 1 + +print(f"Patched {count} goldens.") diff --git a/scripts/import_profiler/profiler.py b/scripts/import_profiler/profiler.py index a1bb174a1de5..965d62cb81a7 100644 --- a/scripts/import_profiler/profiler.py +++ b/scripts/import_profiler/profiler.py @@ -154,7 +154,7 @@ def _format_stats(title, data, p50, p90, p99, fmt): {_format_stats("Physical RSS RAM (MB)", rss_memories, p50_rss, p90_rss, p99_rss, ".4f")}""" print(final_output.strip()) -def run_master(iterations, target_module, cpu=0, csv_path=None, clear_cache=True, fail_threshold=None): +def run_master(iterations, target_module, cpu=0, csv_path=None, clear_cache=True, fail_threshold=None, diff_baseline=None, diff_threshold=None): """Orchestrates the benchmark.""" if iterations < 1: raise ValueError("Number of iterations must be at least 1.") @@ -229,12 +229,39 @@ def run_master(iterations, target_module, cpu=0, csv_path=None, clear_cache=True rss_memories, p50_rss, p90_rss, p99_rss ) - if fail_threshold is not None: - if p99_time > fail_threshold: - print(f"\nFAILURE: P99 import time ({p99_time:.2f} ms) exceeds the failure threshold ({fail_threshold} ms).", file=sys.stderr) - sys.exit(1) - else: - print(f"\nSUCCESS: P99 import time ({p99_time:.2f} ms) is within the failure threshold ({fail_threshold} ms).") +if fail_threshold is not None: + if p99_time > fail_threshold: + print(f" +FAILURE: P99 import time ({p99_time:.2f} ms) exceeds the failure threshold ({fail_threshold} ms).", file=sys.stderr) + sys.exit(1) + else: + print(f" +SUCCESS: P99 import time ({p99_time:.2f} ms) is within the failure threshold ({fail_threshold} ms).") + + if diff_baseline: + if os.path.exists(diff_baseline): + baseline_times = [] + with open(diff_baseline, "r", encoding="utf-8") as f: + reader = csv.reader(f) + next(reader) # skip header + for row in reader: + baseline_times.append(float(row[1])) + _, _, baseline_p99 = _calculate_percentiles(baseline_times) + diff = p99_time - baseline_p99 + + print(f" +--- Diff vs Baseline ---") + print(f"Baseline P99: {baseline_p99:.2f} ms") + print(f"Current P99: {p99_time:.2f} ms") + print(f"Difference: {diff:+.2f} ms") + + if diff > diff_threshold: + print(f"FAILURE: Import time regression of {diff:.2f} ms exceeds the allowed threshold of {diff_threshold} ms.", file=sys.stderr) + sys.exit(1) + else: + print("SUCCESS: Import time diff is within acceptable thresholds.") + else: + print(f"WARNING: Baseline CSV {diff_baseline} not found. Skipping diff check.") def run_trace(target_module): @@ -342,6 +369,8 @@ def find_module_from_package(pkg): parser.add_argument("--mprofile", action="store_true", help="Run tracemalloc memory snapshot") parser.add_argument("--keep-pycache", action="store_true", help="Preserve __pycache__ and allow bytecode execution (Default: False, script automatically sweeps __pycache__ for true cold-starts)") parser.add_argument("--fail-threshold", type=float, help="Fail the profiling if the P99 time exceeds this threshold (in ms).") + parser.add_argument("--diff-baseline", help="Path to a baseline CSV file to compare against.") + parser.add_argument("--diff-threshold", type=float, default=100.0, help="Fail if P99 time exceeds baseline P99 by this many ms.") parser.add_argument("--worker", action="store_true", help=argparse.SUPPRESS) args = parser.parse_args() @@ -362,4 +391,4 @@ def find_module_from_package(pkg): if not args.keep_pycache: clean_bytecode() run_mprofile(target_module) else: - run_master(args.iterations, target_module, args.cpu, args.csv, not args.keep_pycache, args.fail_threshold) \ No newline at end of file + run_master(args.iterations, target_module, args.cpu, args.csv, not args.keep_pycache, args.fail_threshold, args.diff_baseline, args.diff_threshold) \ No newline at end of file From a2bd6ec93c7fbc24bbac35eef67eadbe1109666c Mon Sep 17 00:00:00 2001 From: Heba Alazzeh Date: Thu, 9 Jul 2026 04:01:11 +0000 Subject: [PATCH 13/13] refactor: simplify CI without gapic-generator template changes and fix syntax errors --- ci/run_single_test.sh | 27 ++++-- .../gapic/templates/noxfile.py.j2 | 28 ------ .../integration/goldens/asset/noxfile.py | 23 ----- .../goldens/credentials/noxfile.py | 23 ----- .../integration/goldens/eventarc/noxfile.py | 23 ----- .../integration/goldens/logging/noxfile.py | 23 ----- .../goldens/logging_internal/noxfile.py | 23 ----- .../integration/goldens/redis/noxfile.py | 23 ----- .../goldens/redis_selective/noxfile.py | 23 ----- .../goldens/storagebatchoperations/noxfile.py | 23 ----- packages/google-cloud-asset/noxfile.py | 23 ----- packages/google-cloud-asset/test_trigger.txt | 0 patch_goldens.py | 87 ------------------- scripts/import_profiler/profiler.py | 58 ++++++------- 14 files changed, 47 insertions(+), 360 deletions(-) delete mode 100644 packages/google-cloud-asset/test_trigger.txt delete mode 100644 patch_goldens.py diff --git a/ci/run_single_test.sh b/ci/run_single_test.sh index 8b11dedb6af1..6436a9ba8dea 100755 --- a/ci/run_single_test.sh +++ b/ci/run_single_test.sh @@ -106,31 +106,44 @@ case ${TEST_TYPE} in esac ;; import_profile) - if nox --list-sessions | grep -q "import_profile"; then + if [ -f setup.py ]; then + echo "Creating temporary virtualenv for import profile..." + python3 -m venv .venv-profiler + source .venv-profiler/bin/activate + pip install -e . + + PACKAGE_NAME=$(basename $(pwd)) + PROFILER_SCRIPT="../../scripts/import_profiler/profiler.py" + rm -f /tmp/baseline.csv if [ -n "${TARGET_BRANCH}" ]; then if git rev-parse HEAD^1 >/dev/null 2>&1; then echo "Checking out HEAD^1 for baseline..." git checkout HEAD^1 - if nox --list-sessions | grep -q "import_profile"; then - nox -s import_profile -- --csv /tmp/baseline.csv + if [ -f setup.py ]; then + pip install -e . + python ${PROFILER_SCRIPT} --package ${PACKAGE_NAME} --iterations 10 --csv /tmp/baseline.csv else - echo "No import_profile session on baseline." + echo "setup.py not found on baseline. Skipping baseline generation." fi git checkout - + # Re-install the current branch to ensure we profile the latest code + pip install -e . else echo "Could not find HEAD^1. Skipping baseline generation." fi fi if [ -f /tmp/baseline.csv ]; then - nox -s import_profile -- --diff-baseline /tmp/baseline.csv --diff-threshold 100 + python ${PROFILER_SCRIPT} --package ${PACKAGE_NAME} --iterations 10 --fail-threshold 5000 --diff-baseline /tmp/baseline.csv --diff-threshold 100 else - nox -s import_profile + python ${PROFILER_SCRIPT} --package ${PACKAGE_NAME} --iterations 10 --fail-threshold 5000 fi retval=$? + deactivate + rm -rf .venv-profiler else - echo "Skipping import_profile as it is not supported by this package yet." + echo "Skipping import_profile as this does not appear to be a Python package (no setup.py)." retval=0 fi ;; diff --git a/packages/gapic-generator/gapic/templates/noxfile.py.j2 b/packages/gapic-generator/gapic/templates/noxfile.py.j2 index 4cc2f64350d0..8db595319396 100644 --- a/packages/gapic-generator/gapic/templates/noxfile.py.j2 +++ b/packages/gapic-generator/gapic/templates/noxfile.py.j2 @@ -86,7 +86,6 @@ nox.options.sessions = [ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -642,31 +641,4 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--module", - {% if api.naming.module_namespace %} - "{{ api.naming.module_namespace[0] }}", - {% else %} - "{{ api.naming.versioned_module_name }}", - {% endif %} - "--iterations", - "10", - "--fail-threshold", - "5000", - *session.posargs, - ) {% endblock %} diff --git a/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py b/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py index 4c1b4e1db6bf..09d28712c73c 100755 --- a/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py @@ -93,7 +93,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -634,25 +633,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--package", - "google.cloud.asset", - "--fail-threshold", - "5000", - "--iterations", - "10", - ) diff --git a/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py b/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py index ad8ad207936b..65e26efe21d3 100755 --- a/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py @@ -93,7 +93,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -634,25 +633,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--package", - "google.iam.credentials", - "--fail-threshold", - "5000", - "--iterations", - "10", - ) diff --git a/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py b/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py index f4e4d64cb59e..42b2349e2cc1 100755 --- a/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py @@ -93,7 +93,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -634,25 +633,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--package", - "google.cloud.eventarc_v1", - "--fail-threshold", - "5000", - "--iterations", - "10", - ) diff --git a/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py b/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py index 5557f2abc5d5..09e4b345592a 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py @@ -93,7 +93,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -634,25 +633,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--package", - "google.cloud.logging", - "--fail-threshold", - "5000", - "--iterations", - "10", - ) diff --git a/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py b/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py index 5557f2abc5d5..09e4b345592a 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py @@ -93,7 +93,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -634,25 +633,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--package", - "google.cloud.logging", - "--fail-threshold", - "5000", - "--iterations", - "10", - ) diff --git a/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py b/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py index ea67e32e9225..9b3356dd1272 100755 --- a/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py @@ -93,7 +93,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -634,25 +633,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--package", - "google.cloud.redis", - "--fail-threshold", - "5000", - "--iterations", - "10", - ) diff --git a/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py b/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py index ea67e32e9225..9b3356dd1272 100755 --- a/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py @@ -93,7 +93,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -634,25 +633,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--package", - "google.cloud.redis", - "--fail-threshold", - "5000", - "--iterations", - "10", - ) diff --git a/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py b/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py index 5e7d2e70b60b..db370dd3dd0f 100755 --- a/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py @@ -93,7 +93,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -634,25 +633,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--package", - "google.cloud.storagebatchoperations", - "--fail-threshold", - "5000", - "--iterations", - "10", - ) diff --git a/packages/google-cloud-asset/noxfile.py b/packages/google-cloud-asset/noxfile.py index 080996a9fa45..b044cb25e9bd 100644 --- a/packages/google-cloud-asset/noxfile.py +++ b/packages/google-cloud-asset/noxfile.py @@ -88,7 +88,6 @@ "lint_setup_py", "blacken", "docs", - "import_profile", ] # Error if a python version is missing @@ -638,25 +637,3 @@ def core_deps_from_source(session, protobuf_implementation): "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, }, ) - - -@nox.session(python="3.15") -def import_profile(session): - """Ensure import times remain below defined thresholds.""" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--package", - "google-cloud-asset", - "--iterations", - "10", - "--fail-threshold", - "5000", - ) diff --git a/packages/google-cloud-asset/test_trigger.txt b/packages/google-cloud-asset/test_trigger.txt deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/patch_goldens.py b/patch_goldens.py deleted file mode 100644 index 2e4cbdbd0663..000000000000 --- a/patch_goldens.py +++ /dev/null @@ -1,87 +0,0 @@ -import os -import glob -import re - -def get_module_name(golden_dir): - setup_py = os.path.join(golden_dir, "setup.py") - if not os.path.exists(setup_py): - return "google" - - with open(setup_py, "r", encoding="utf-8") as f: - content = f.read() - - match = re.search(r"'(google/[^']+)/gapic_version.py'", content) - if match: - return match.group(1).replace("/", ".") - - match = re.search(r"\"(google/[^\"]+)/gapic_version.py\"", content) - if match: - return match.group(1).replace("/", ".") - - return "google" - -def patch_noxfile(golden_dir): - path = os.path.join(golden_dir, "noxfile.py") - if not os.path.exists(path): - return False - - try: - with open(path, 'r', encoding='utf-8') as f: - content = f.read() - except UnicodeDecodeError: - return False - - module_name = get_module_name(golden_dir) - - idx = content.find("@nox.session(python=\"3.15\")\ndef import_profile(session):") - if idx != -1: - content = content[:idx].strip() + "\n" - else: - idx = content.find("@nox.session\ndef import_profile") - if idx != -1: - content = content[:idx].strip() + "\n" - - if "nox.options.sessions =" in content and "\"import_profile\"" not in content: - content = re.sub( - r'(\n\s*"docs",\n)(\s*\])', - r'\1 "import_profile",\n\2', - content - ) - - session_text = f""" -@nox.session(python="3.15") -def import_profile(session): - \"\"\"Ensure import times remain below defined thresholds.\"\"\" - profiler_script = ( - CURRENT_DIRECTORY.parent.parent / "scripts" / "import_profiler" / "profiler.py" - ) - if not profiler_script.exists(): - session.skip("The import profiler script was not found.") - - session.install(".") - session.run( - "python", - str(profiler_script), - "--package", - "{module_name}", - "--fail-threshold", - "5000", - "--iterations", - "10", - *session.posargs, - ) -""" - - content += "\n" + session_text - - with open(path, 'w', encoding='utf-8') as f: - f.write(content) - return True - -count = 0 -for golden_dir in glob.glob('packages/gapic-generator/tests/integration/goldens/*'): - if os.path.isdir(golden_dir): - if patch_noxfile(golden_dir): - count += 1 - -print(f"Patched {count} goldens.") diff --git a/scripts/import_profiler/profiler.py b/scripts/import_profiler/profiler.py index 965d62cb81a7..7791b5b1e54c 100644 --- a/scripts/import_profiler/profiler.py +++ b/scripts/import_profiler/profiler.py @@ -229,39 +229,35 @@ def run_master(iterations, target_module, cpu=0, csv_path=None, clear_cache=True rss_memories, p50_rss, p90_rss, p99_rss ) -if fail_threshold is not None: - if p99_time > fail_threshold: - print(f" -FAILURE: P99 import time ({p99_time:.2f} ms) exceeds the failure threshold ({fail_threshold} ms).", file=sys.stderr) - sys.exit(1) - else: - print(f" -SUCCESS: P99 import time ({p99_time:.2f} ms) is within the failure threshold ({fail_threshold} ms).") + if fail_threshold is not None: + if p99_time > fail_threshold: + print(f"\nFAILURE: P99 import time ({p99_time:.2f} ms) exceeds the failure threshold ({fail_threshold} ms).", file=sys.stderr) + sys.exit(1) + else: + print(f"\nSUCCESS: P99 import time ({p99_time:.2f} ms) is within the failure threshold ({fail_threshold} ms).") - if diff_baseline: - if os.path.exists(diff_baseline): - baseline_times = [] - with open(diff_baseline, "r", encoding="utf-8") as f: - reader = csv.reader(f) - next(reader) # skip header - for row in reader: - baseline_times.append(float(row[1])) - _, _, baseline_p99 = _calculate_percentiles(baseline_times) - diff = p99_time - baseline_p99 - - print(f" ---- Diff vs Baseline ---") - print(f"Baseline P99: {baseline_p99:.2f} ms") - print(f"Current P99: {p99_time:.2f} ms") - print(f"Difference: {diff:+.2f} ms") - - if diff > diff_threshold: - print(f"FAILURE: Import time regression of {diff:.2f} ms exceeds the allowed threshold of {diff_threshold} ms.", file=sys.stderr) - sys.exit(1) - else: - print("SUCCESS: Import time diff is within acceptable thresholds.") + if diff_baseline: + if os.path.exists(diff_baseline): + baseline_times = [] + with open(diff_baseline, "r", encoding="utf-8") as f: + reader = csv.reader(f) + next(reader) # skip header + for row in reader: + baseline_times.append(float(row[1])) + _, _, baseline_p99 = _calculate_percentiles(baseline_times) + diff = p99_time - baseline_p99 + print("\n--- Diff vs Baseline ---") + print(f"Baseline P99: {baseline_p99:.2f} ms") + print(f"Current P99: {p99_time:.2f} ms") + print(f"Difference: {diff:+.2f} ms") + + if diff > diff_threshold: + print(f"FAILURE: Import time regression of {diff:.2f} ms exceeds the allowed threshold of {diff_threshold} ms.", file=sys.stderr) + sys.exit(1) else: - print(f"WARNING: Baseline CSV {diff_baseline} not found. Skipping diff check.") + print("SUCCESS: Import time diff is within acceptable thresholds.") + else: + print(f"WARNING: Baseline CSV {diff_baseline} not found. Skipping diff check.") def run_trace(target_module):