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