From 47e5dc47b1a1d74da800cf9384db3b859c121bda Mon Sep 17 00:00:00 2001 From: tetiana-karasova Date: Thu, 17 Feb 2022 14:43:31 +0100 Subject: [PATCH] replace the project_number with project_id --- samples/interactive-tutorials/README.md | 8 ++------ .../interactive-tutorials/TEST_RESOURCES_SETUP_CLEANUP.md | 1 - .../product/import_products_big_query_table.py | 3 +-- .../interactive-tutorials/product/import_products_gcs.py | 3 +-- .../product/import_products_inline_source.py | 4 ++-- .../interactive-tutorials/product/setup/setup_cleanup.py | 5 ++--- .../interactive-tutorials/search/search_simple_query.py | 4 ++-- .../search/search_with_boost_spec.py | 4 ++-- .../search/search_with_facet_spec.py | 4 ++-- .../interactive-tutorials/search/search_with_filtering.py | 4 ++-- .../interactive-tutorials/search/search_with_ordering.py | 4 ++-- .../search/search_with_pagination.py | 4 ++-- .../search/search_with_query_expansion_spec.py | 4 ++-- .../test_resources_recovery/create_test_resources.py | 4 ++-- .../test_resources_recovery/remove_test_resources.py | 4 ++-- 15 files changed, 26 insertions(+), 34 deletions(-) diff --git a/samples/interactive-tutorials/README.md b/samples/interactive-tutorials/README.md index ca7204f7..5faeb748 100644 --- a/samples/interactive-tutorials/README.md +++ b/samples/interactive-tutorials/README.md @@ -72,16 +72,12 @@ To run a code sample from the Cloud Shell, you need to be authenticated using th export GOOGLE_APPLICATION_CREDENTIALS=~/key.json ``` -### Set the GOOGLE_CLOUD_PROJECT_NUMBER and GOOGLE_CLOUD_PROJECT environment variables +### Set the GOOGLE_CLOUD_PROJECT environment variable -You will run the code samples in your own Google Cloud project. To use the **project_number** and **project_id** in every request to the Retail API, you should first specify them as environment variables. +You will run the code samples in your own Google Cloud project. To use the **project_id** in every request to the Retail API, you should first specify them as environment variables. 1. Find the project number and project ID in the Project Info card displayed on **Home/Dashboard**. -1. Set the **project_number** with the following command: - ```bash - export GOOGLE_CLOUD_PROJECT_NUMBER= - ``` 1. Set the **project_id** with the following command: ```bash export GOOGLE_CLOUD_PROJECT= diff --git a/samples/interactive-tutorials/TEST_RESOURCES_SETUP_CLEANUP.md b/samples/interactive-tutorials/TEST_RESOURCES_SETUP_CLEANUP.md index 89b1cf13..772257f8 100644 --- a/samples/interactive-tutorials/TEST_RESOURCES_SETUP_CLEANUP.md +++ b/samples/interactive-tutorials/TEST_RESOURCES_SETUP_CLEANUP.md @@ -3,7 +3,6 @@ ## Required environment variables To successfully import the catalog data for tests, the following environment variables should be set: - - GOOGLE_CLOUD_PROJECT_NUMBER - GOOGLE_CLOUD_PROJECT - BUCKET_NAME - EVENTS_BUCKET_NAME diff --git a/samples/interactive-tutorials/product/import_products_big_query_table.py b/samples/interactive-tutorials/product/import_products_big_query_table.py index 39b0d6f6..c5fc03fb 100644 --- a/samples/interactive-tutorials/product/import_products_big_query_table.py +++ b/samples/interactive-tutorials/product/import_products_big_query_table.py @@ -25,10 +25,9 @@ ProductServiceClient, ) -project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"] project_id = os.environ["GOOGLE_CLOUD_PROJECT"] -default_catalog = f"projects/{project_number}/locations/global/catalogs/default_catalog/branches/default_branch" +default_catalog = f"projects/{project_id}/locations/global/catalogs/default_catalog/branches/default_branch" dataset_id = "products" table_id = "products" diff --git a/samples/interactive-tutorials/product/import_products_gcs.py b/samples/interactive-tutorials/product/import_products_gcs.py index 1a865604..1ca5f3e8 100644 --- a/samples/interactive-tutorials/product/import_products_gcs.py +++ b/samples/interactive-tutorials/product/import_products_gcs.py @@ -28,12 +28,11 @@ # Read the project number from the environment variable -project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"] project_id = os.environ["GOOGLE_CLOUD_PROJECT"] bucket_name = os.environ["BUCKET_NAME"] # You can change the branch here. The "default_branch" is set to point to the branch "0" -default_catalog = f"projects/{project_number}/locations/global/catalogs/default_catalog/branches/default_branch" +default_catalog = f"projects/{project_id}/locations/global/catalogs/default_catalog/branches/default_branch" gcs_bucket = f"gs://{bucket_name}" gcs_errors_bucket = f"{gcs_bucket}/error" diff --git a/samples/interactive-tutorials/product/import_products_inline_source.py b/samples/interactive-tutorials/product/import_products_inline_source.py index 23e89930..5d6434d9 100644 --- a/samples/interactive-tutorials/product/import_products_inline_source.py +++ b/samples/interactive-tutorials/product/import_products_inline_source.py @@ -33,9 +33,9 @@ from google.protobuf.field_mask_pb2 import FieldMask # Read the project number from the environment variable -project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"] +project_id = os.environ["GOOGLE_CLOUD_PROJECT"] -default_catalog = f"projects/{project_number}/locations/global/catalogs/default_catalog/branches/default_branch" +default_catalog = f"projects/{project_id}/locations/global/catalogs/default_catalog/branches/default_branch" # prepare product to import as inline source diff --git a/samples/interactive-tutorials/product/setup/setup_cleanup.py b/samples/interactive-tutorials/product/setup/setup_cleanup.py index 11027b9c..6ff2f09d 100644 --- a/samples/interactive-tutorials/product/setup/setup_cleanup.py +++ b/samples/interactive-tutorials/product/setup/setup_cleanup.py @@ -23,10 +23,9 @@ from google.cloud.retail_v2 import CreateProductRequest, DeleteProductRequest, \ FulfillmentInfo, GetProductRequest, PriceInfo, Product, ProductServiceClient -project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"] project_id = os.environ["GOOGLE_CLOUD_PROJECT"] -default_catalog = f"projects/{project_number}/locations/global/catalogs/default_catalog" -default_branch_name = f"projects/{project_number}/locations/global/catalogs/default_catalog/branches/default_branch" +default_catalog = f"projects/{project_id}/locations/global/catalogs/default_catalog" +default_branch_name = f"projects/{project_id}/locations/global/catalogs/default_catalog/branches/default_branch" def generate_product() -> Product: diff --git a/samples/interactive-tutorials/search/search_simple_query.py b/samples/interactive-tutorials/search/search_simple_query.py index 78889209..77d99e17 100644 --- a/samples/interactive-tutorials/search/search_simple_query.py +++ b/samples/interactive-tutorials/search/search_simple_query.py @@ -19,14 +19,14 @@ from google.cloud.retail import SearchRequest, SearchServiceClient -project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"] +project_id = os.environ["GOOGLE_CLOUD_PROJECT"] # get search service request: def get_search_request(query: str): default_search_placement = ( "projects/" - + project_number + + project_id + "/locations/global/catalogs/default_catalog/placements/default_search" ) diff --git a/samples/interactive-tutorials/search/search_with_boost_spec.py b/samples/interactive-tutorials/search/search_with_boost_spec.py index 7b2995d8..b68c28fb 100644 --- a/samples/interactive-tutorials/search/search_with_boost_spec.py +++ b/samples/interactive-tutorials/search/search_with_boost_spec.py @@ -20,14 +20,14 @@ from google.cloud.retail import SearchRequest, SearchServiceClient -project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"] +project_id = os.environ["GOOGLE_CLOUD_PROJECT"] # get search service request: def get_search_request(query: str, condition: str, boost_strength: float): default_search_placement = ( "projects/" - + project_number + + project_id + "/locations/global/catalogs/default_catalog/placements/default_search" ) diff --git a/samples/interactive-tutorials/search/search_with_facet_spec.py b/samples/interactive-tutorials/search/search_with_facet_spec.py index 50a8fb7f..cb730802 100644 --- a/samples/interactive-tutorials/search/search_with_facet_spec.py +++ b/samples/interactive-tutorials/search/search_with_facet_spec.py @@ -18,14 +18,14 @@ from google.cloud.retail import SearchRequest, SearchServiceClient -project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"] +project_id = os.environ["GOOGLE_CLOUD_PROJECT"] # get search service request: def get_search_request(query: str, facet_key_param: str): default_search_placement = ( "projects/" - + project_number + + project_id + "/locations/global/catalogs/default_catalog/placements/default_search" ) # PUT THE INTERVALS HERE: diff --git a/samples/interactive-tutorials/search/search_with_filtering.py b/samples/interactive-tutorials/search/search_with_filtering.py index e7a8a31d..b673cbe3 100644 --- a/samples/interactive-tutorials/search/search_with_filtering.py +++ b/samples/interactive-tutorials/search/search_with_filtering.py @@ -19,14 +19,14 @@ from google.cloud.retail import SearchRequest, SearchServiceClient -project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"] +project_id = os.environ["GOOGLE_CLOUD_PROJECT"] # get search service request: def get_search_request(query: str, _filter: str): default_search_placement = ( "projects/" - + project_number + + project_id + "/locations/global/catalogs/default_catalog/placements/default_search" ) diff --git a/samples/interactive-tutorials/search/search_with_ordering.py b/samples/interactive-tutorials/search/search_with_ordering.py index 118d4202..d79b6783 100644 --- a/samples/interactive-tutorials/search/search_with_ordering.py +++ b/samples/interactive-tutorials/search/search_with_ordering.py @@ -19,14 +19,14 @@ from google.cloud.retail import SearchRequest, SearchServiceClient -project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"] +project_id = os.environ["GOOGLE_CLOUD_PROJECT"] # get search service request: def get_search_request(query: str, order: str): default_search_placement = ( "projects/" - + project_number + + project_id + "/locations/global/catalogs/default_catalog/placements/default_search" ) diff --git a/samples/interactive-tutorials/search/search_with_pagination.py b/samples/interactive-tutorials/search/search_with_pagination.py index 727227c2..27188f67 100644 --- a/samples/interactive-tutorials/search/search_with_pagination.py +++ b/samples/interactive-tutorials/search/search_with_pagination.py @@ -21,14 +21,14 @@ from google.cloud.retail import SearchRequest, SearchServiceClient -project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"] +project_id = os.environ["GOOGLE_CLOUD_PROJECT"] # get search service request: def get_search_request(query: str, page_size: int, offset: int, next_page_token: str): default_search_placement = ( "projects/" - + project_number + + project_id + "/locations/global/catalogs/default_catalog/placements/default_search" ) diff --git a/samples/interactive-tutorials/search/search_with_query_expansion_spec.py b/samples/interactive-tutorials/search/search_with_query_expansion_spec.py index 9455e900..b520cc1a 100644 --- a/samples/interactive-tutorials/search/search_with_query_expansion_spec.py +++ b/samples/interactive-tutorials/search/search_with_query_expansion_spec.py @@ -20,7 +20,7 @@ from google.cloud.retail import SearchRequest, SearchServiceClient -project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"] +project_id = os.environ["GOOGLE_CLOUD_PROJECT"] # get search service request: @@ -29,7 +29,7 @@ def get_search_request( ): default_search_placement = ( "projects/" - + project_number + + project_id + "/locations/global/catalogs/default_catalog/placements/default_search" ) diff --git a/samples/interactive-tutorials/test_resources_recovery/create_test_resources.py b/samples/interactive-tutorials/test_resources_recovery/create_test_resources.py index 36807af3..8ea24a18 100644 --- a/samples/interactive-tutorials/test_resources_recovery/create_test_resources.py +++ b/samples/interactive-tutorials/test_resources_recovery/create_test_resources.py @@ -25,7 +25,7 @@ ImportProductsRequest, ProductInputConfig from google.cloud.retail_v2 import ProductServiceClient -project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"] +project_id = os.environ["GOOGLE_CLOUD_PROJECT"] products_bucket_name = os.environ['BUCKET_NAME'] events_bucket_name = os.environ['EVENTS_BUCKET_NAME'] project_id = os.environ["GOOGLE_CLOUD_PROJECT"] @@ -41,7 +41,7 @@ events_schema = "../resources/events_schema.json" object_name = re.search('resources/(.*?)$', product_resource_file).group(1) -default_catalog = f"projects/{project_number}/locations/global/catalogs/default_catalog/branches/default_branch" +default_catalog = f"projects/{project_id}/locations/global/catalogs/default_catalog/branches/default_branch" storage_client = storage.Client() diff --git a/samples/interactive-tutorials/test_resources_recovery/remove_test_resources.py b/samples/interactive-tutorials/test_resources_recovery/remove_test_resources.py index 0877b4bc..e69f70d9 100644 --- a/samples/interactive-tutorials/test_resources_recovery/remove_test_resources.py +++ b/samples/interactive-tutorials/test_resources_recovery/remove_test_resources.py @@ -23,7 +23,7 @@ from google.cloud.retail import DeleteProductRequest, ListProductsRequest, \ ProductServiceClient -project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"] +project_id = os.environ["GOOGLE_CLOUD_PROJECT"] project_id = os.environ["GOOGLE_CLOUD_PROJECT"] product_bucket_name = os.environ['BUCKET_NAME'] events_bucket_name = os.environ['EVENTS_BUCKET_NAME'] @@ -31,7 +31,7 @@ product_dataset = "products" events_dataset = "user_events" -default_catalog = f"projects/{project_number}/locations/global/catalogs/default_catalog/branches/default_branch" +default_catalog = f"projects/{project_id}/locations/global/catalogs/default_catalog/branches/default_branch" storage_client = storage.Client()