Skip to content

Commit 83c2029

Browse files
tetiana-karasovagcf-owl-bot[bot]parthea
authored andcommitted
docs(samples): read the project id from google.auth (#160)
* feat: read the project id from gcloud config * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * replace os.getenv(GOOGLE_CLOUD_PROJECT) with google.auth.default()[1] Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent 81cc97f commit 83c2029

24 files changed

+47
-56
lines changed

generated_samples/interactive-tutorials/README.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,6 @@ To run a code sample from the Cloud Shell, you need to be authenticated using th
7272
export GOOGLE_APPLICATION_CREDENTIALS=~/key.json
7373
```
7474

75-
### Set the GOOGLE_CLOUD_PROJECT environment variable
76-
77-
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.
78-
79-
1. Find the project ID in the Project Info card displayed on **Home/Dashboard**.
80-
81-
1. Set the **project_id** with the following command:
82-
```bash
83-
export GOOGLE_CLOUD_PROJECT=<YOUR_PROJECT_ID>
84-
```
85-
8675
### Install Google Cloud Retail libraries
8776

8877
To run Python code samples for the Retail API tutorial, you need to set up your virtual environment.

generated_samples/interactive-tutorials/TEST_RESOURCES_SETUP_CLEANUP.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
## Required environment variables
44

55
To successfully import the catalog data for tests, the following environment variables should be set:
6-
- GOOGLE_CLOUD_PROJECT
76
- BUCKET_NAME
87
- EVENTS_BUCKET_NAME
98
These values are stored in the Secret Manager and will be submitted as

generated_samples/interactive-tutorials/product/add_fulfillment_places.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414

1515
# [START retail_add_fulfillment_places]
1616
import datetime
17-
import os
1817
import random
1918
import string
2019
import time
2120

21+
import google.auth
2222
from google.cloud.retail import AddFulfillmentPlacesRequest, ProductServiceClient
2323

2424
from setup_product.setup_cleanup import create_product, delete_product, get_product
2525

26-
project_id = os.getenv("GOOGLE_CLOUD_PROJECT")
26+
project_id = google.auth.default()[1]
2727
product_id = "".join(random.sample(string.ascii_lowercase, 8))
2828
product_name = (
2929
"projects/"

generated_samples/interactive-tutorials/product/create_product.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
# [START retail_create_product]
1717
# Create product in a catalog using Retail API
1818
#
19-
import os
2019
import random
2120
import string
2221

22+
import google.auth
2323
from google.cloud.retail import CreateProductRequest, Product, ProductServiceClient
2424
from google.cloud.retail import PriceInfo
2525
from google.cloud.retail_v2.types import product
2626

2727
from setup_product.setup_cleanup import delete_product
2828

29-
project_id = os.getenv("GOOGLE_CLOUD_PROJECT")
29+
project_id = google.auth.default()[1]
3030
default_branch_name = (
3131
"projects/"
3232
+ project_id

generated_samples/interactive-tutorials/product/crud_product.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
# [START retail_crud_product]
1717
# Create product in a catalog using Retail API
1818
#
19-
import os
2019
import random
2120
import string
2221

22+
import google.auth
2323
from google.cloud.retail import (
2424
CreateProductRequest,
2525
DeleteProductRequest,
@@ -31,7 +31,7 @@
3131
from google.cloud.retail import PriceInfo
3232
from google.cloud.retail_v2.types import product
3333

34-
project_id = os.getenv("GOOGLE_CLOUD_PROJECT")
34+
project_id = google.auth.default()[1]
3535
default_branch_name = (
3636
"projects/"
3737
+ project_id

generated_samples/interactive-tutorials/product/delete_product.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
# [START retail_delete_product]
1717
# Delete product from a catalog using Retail API
1818
#
19-
import os
2019
import random
2120
import string
2221

22+
import google.auth
2323
from google.cloud.retail import DeleteProductRequest, ProductServiceClient
2424

2525
from setup_product.setup_cleanup import create_product
2626

27-
project_id = os.getenv("GOOGLE_CLOUD_PROJECT")
27+
project_id = google.auth.default()[1]
2828
default_branch_name = (
2929
"projects/"
3030
+ project_id

generated_samples/interactive-tutorials/product/get_product.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
# [START retail_get_product]
1717
# Get product from a catalog using Retail API
1818
#
19-
import os
2019
import random
2120
import string
2221

22+
import google.auth
2323
from google.cloud.retail import GetProductRequest, ProductServiceClient
2424

2525
from setup_product.setup_cleanup import create_product, delete_product
2626

27-
project_id = os.getenv("GOOGLE_CLOUD_PROJECT")
27+
project_id = google.auth.default()[1]
2828
product_id = "".join(random.sample(string.ascii_lowercase, 8))
2929

3030

generated_samples/interactive-tutorials/product/import_products_big_query_table.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
# limitations under the License.
1414

1515
import argparse
16-
import os
1716

18-
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]
17+
import google.auth
18+
19+
project_id = google.auth.default()[1]
1920

2021

2122
def main(project_id, dataset_id, table_id):

generated_samples/interactive-tutorials/product/import_products_gcs.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
def main(bucket_name):
2020
# [START retail_import_products_from_gcs]
2121

22-
import os
2322
import time
2423

24+
import google.auth
2525
from google.cloud.retail import (
2626
GcsSource,
2727
ImportErrorsConfig,
@@ -30,8 +30,7 @@ def main(bucket_name):
3030
ProductServiceClient,
3131
)
3232

33-
# Read the project id from the environment variable
34-
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]
33+
project_id = google.auth.default()[1]
3534

3635
# TODO: Developer set the bucket_name
3736
# bucket_name = os.environ["BUCKET_NAME"]

generated_samples/interactive-tutorials/product/import_products_inline_source.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
# [START retail_import_products_from_inline_source]
1616
# Import products into a catalog from inline source using Retail API
1717
#
18-
import os
1918
import random
2019
import string
2120
import time
2221

22+
import google.auth
2323
from google.cloud.retail import (
2424
ColorInfo,
2525
FulfillmentInfo,
@@ -32,8 +32,7 @@
3232
)
3333
from google.protobuf.field_mask_pb2 import FieldMask
3434

35-
# Read the project ID from the environment variable
36-
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]
35+
project_id = google.auth.default()[1]
3736

3837
default_catalog = f"projects/{project_id}/locations/global/catalogs/default_catalog/branches/default_branch"
3938

0 commit comments

Comments
 (0)