From dcb43a19dc3ae0f7f5a523d1a490f057edcdb398 Mon Sep 17 00:00:00 2001 From: tetiana-karasova <62887365+tetiana-karasova@users.noreply.github.com> Date: Fri, 25 Feb 2022 15:56:15 +0100 Subject: [PATCH] chore: additional replacements to read the project id from google.auth (#166) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: events samples: get project_id from auth.default * lint fix * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Anthonios Partheniou Co-authored-by: Owl Bot --- .../events/import_user_events_big_query.py | 5 +++-- .../interactive-tutorials/events/import_user_events_gcs.py | 3 ++- .../events/import_user_events_inline.py | 6 ++++-- .../interactive-tutorials/events/purge_user_event.py | 4 ++-- .../interactive-tutorials/events/rejoin_user_event.py | 4 ++-- .../events/setup_events/events_create_gcs_bucket.py | 4 +++- .../events/setup_events/setup_cleanup.py | 5 +++-- .../interactive-tutorials/events/write_user_event.py | 6 ++++-- 8 files changed, 23 insertions(+), 14 deletions(-) diff --git a/generated_samples/interactive-tutorials/events/import_user_events_big_query.py b/generated_samples/interactive-tutorials/events/import_user_events_big_query.py index 40821f8a78bf..42261f623399 100644 --- a/generated_samples/interactive-tutorials/events/import_user_events_big_query.py +++ b/generated_samples/interactive-tutorials/events/import_user_events_big_query.py @@ -13,9 +13,10 @@ # limitations under the License. import argparse -import os -project_id = os.environ["GOOGLE_CLOUD_PROJECT"] +import google.auth + +project_id = google.auth.default()[1] def main(project_id, dataset_id, table_id): diff --git a/generated_samples/interactive-tutorials/events/import_user_events_gcs.py b/generated_samples/interactive-tutorials/events/import_user_events_gcs.py index c9da3f85d05e..0c56987f305a 100644 --- a/generated_samples/interactive-tutorials/events/import_user_events_gcs.py +++ b/generated_samples/interactive-tutorials/events/import_user_events_gcs.py @@ -21,6 +21,7 @@ def main(bucket_name): # Import user events into a catalog from GCS using Retail API import time + import google.auth from google.cloud.retail import ( GcsSource, @@ -31,7 +32,7 @@ def main(bucket_name): ) # Read the project number from the environment variable - project_id = os.getenv("GOOGLE_CLOUD_PROJECT") + project_id = google.auth.default()[1] # Read bucket name from the environment variable bucket_name = os.getenv("EVENTS_BUCKET_NAME") diff --git a/generated_samples/interactive-tutorials/events/import_user_events_inline.py b/generated_samples/interactive-tutorials/events/import_user_events_inline.py index 7c165a8d9b50..bdbaa72a3bfc 100644 --- a/generated_samples/interactive-tutorials/events/import_user_events_inline.py +++ b/generated_samples/interactive-tutorials/events/import_user_events_inline.py @@ -17,11 +17,12 @@ # Import user events into a catalog from inline source using Retail API # import datetime -import os import random import string import time +import google.auth + from google.cloud.retail import ( ImportUserEventsRequest, UserEvent, @@ -29,9 +30,10 @@ UserEventInputConfig, UserEventServiceClient, ) + from google.protobuf.timestamp_pb2 import Timestamp -project_id = os.getenv("GOOGLE_CLOUD_PROJECT") +project_id = google.auth.default()[1] default_catalog = "projects/{0}/locations/global/catalogs/default_catalog".format( project_id diff --git a/generated_samples/interactive-tutorials/events/purge_user_event.py b/generated_samples/interactive-tutorials/events/purge_user_event.py index 31fef6f5906c..256ecde1e3a5 100644 --- a/generated_samples/interactive-tutorials/events/purge_user_event.py +++ b/generated_samples/interactive-tutorials/events/purge_user_event.py @@ -16,13 +16,13 @@ # [START retail_purge_user_event] # Import user events into a catalog from inline source using Retail API # -import os +import google.auth from google.cloud.retail import PurgeUserEventsRequest, UserEventServiceClient from setup_events.setup_cleanup import write_user_event -project_id = os.getenv("GOOGLE_CLOUD_PROJECT") +project_id = google.auth.default()[1] default_catalog = "projects/{0}/locations/global/catalogs/default_catalog".format( project_id diff --git a/generated_samples/interactive-tutorials/events/rejoin_user_event.py b/generated_samples/interactive-tutorials/events/rejoin_user_event.py index 586c5ec813de..67e4caa585be 100644 --- a/generated_samples/interactive-tutorials/events/rejoin_user_event.py +++ b/generated_samples/interactive-tutorials/events/rejoin_user_event.py @@ -16,13 +16,13 @@ # [START retail_rejoin_user_event] # Import user events into a catalog from inline source using Retail API # -import os +import google.auth from google.cloud.retail import RejoinUserEventsRequest, UserEventServiceClient from setup_events.setup_cleanup import purge_user_event, write_user_event -project_id = os.getenv("GOOGLE_CLOUD_PROJECT") +project_id = google.auth.default()[1] default_catalog = "projects/{0}/locations/global/catalogs/default_catalog".format( project_id diff --git a/generated_samples/interactive-tutorials/events/setup_events/events_create_gcs_bucket.py b/generated_samples/interactive-tutorials/events/setup_events/events_create_gcs_bucket.py index e1ccf829979c..00ff31a823e3 100644 --- a/generated_samples/interactive-tutorials/events/setup_events/events_create_gcs_bucket.py +++ b/generated_samples/interactive-tutorials/events/setup_events/events_create_gcs_bucket.py @@ -15,9 +15,11 @@ import datetime import os +import google.auth + from setup_cleanup import create_bucket, upload_blob -project_id = os.environ["GOOGLE_CLOUD_PROJECT"] +project_id = google.auth.default()[1] timestamp_ = datetime.datetime.now().timestamp().__round__() bucket_name = os.environ["EVENTS_BUCKET_NAME"] diff --git a/generated_samples/interactive-tutorials/events/setup_events/setup_cleanup.py b/generated_samples/interactive-tutorials/events/setup_events/setup_cleanup.py index 6fa29ecd6b58..53dd775cb692 100644 --- a/generated_samples/interactive-tutorials/events/setup_events/setup_cleanup.py +++ b/generated_samples/interactive-tutorials/events/setup_events/setup_cleanup.py @@ -15,21 +15,22 @@ import datetime import json -import os import re import shlex import subprocess from google.api_core.exceptions import NotFound +import google.auth from google.cloud import bigquery from google.cloud import storage from google.cloud.retail import ProductDetail, PurgeUserEventsRequest, \ UserEvent, UserEventServiceClient, WriteUserEventRequest from google.cloud.retail_v2 import Product + from google.protobuf.timestamp_pb2 import Timestamp -project_id = os.getenv('GOOGLE_CLOUD_PROJECT') +project_id = google.auth.default()[1] default_catalog = "projects/{0}/locations/global/catalogs/default_catalog".format( project_id) diff --git a/generated_samples/interactive-tutorials/events/write_user_event.py b/generated_samples/interactive-tutorials/events/write_user_event.py index 729848024d0d..cd02d7c9fb56 100644 --- a/generated_samples/interactive-tutorials/events/write_user_event.py +++ b/generated_samples/interactive-tutorials/events/write_user_event.py @@ -17,14 +17,16 @@ # Import user events into a catalog from inline source using Retail API # import datetime -import os + +import google.auth from google.cloud.retail import UserEvent, UserEventServiceClient, WriteUserEventRequest + from google.protobuf.timestamp_pb2 import Timestamp from setup_events.setup_cleanup import purge_user_event -project_id = os.getenv("GOOGLE_CLOUD_PROJECT") +project_id = google.auth.default()[1] default_catalog = "projects/{0}/locations/global/catalogs/default_catalog".format( project_id