Skip to content
This repository was archived by the owner on Jul 20, 2023. It is now read-only.

Commit 16cefb4

Browse files
fix: remove gcloud_project env variable (#156)
Co-authored-by: Karl Weinmeister <[email protected]>
1 parent 27f7cc4 commit 16cefb4

38 files changed

+260
-228
lines changed

samples/interactive-tutorials/events/purge-user-events.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ async function main() {
2121
const {UserEventServiceClient} = require('@google-cloud/retail').v2;
2222
const utils = require('../setup/setup-cleanup');
2323

24-
const projectNumber = process.env['GCLOUD_PROJECT'];
24+
// Instantiates a client.
25+
const retailClient = new UserEventServiceClient();
26+
27+
const projectId = await retailClient.getProjectId();
2528
const visitorId = 'test_visitor_id';
2629

2730
// Placement
28-
const parent = `projects/${projectNumber}/locations/global/catalogs/default_catalog`;
31+
const parent = `projects/${projectId}/locations/global/catalogs/default_catalog`;
2932

3033
// The filter string to specify the events to be deleted with a
3134
// length limit of 5,000 characters.
@@ -34,9 +37,6 @@ async function main() {
3437
// Actually perform the purge.
3538
const force = true;
3639

37-
// Instantiates a client.
38-
const retailClient = new UserEventServiceClient();
39-
4040
const callPurgeUserEvents = async () => {
4141
// Construct request
4242
const request = {

samples/interactive-tutorials/events/rejoin-user-events.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ async function main() {
2121
const {UserEventServiceClient} = require('@google-cloud/retail').v2;
2222
const utils = require('../setup/setup-cleanup');
2323

24-
const projectNumber = process.env['GCLOUD_PROJECT'];
24+
// Instantiates a client.
25+
const retailClient = new UserEventServiceClient();
26+
27+
const projectId = await retailClient.getProjectId();
2528
const visitorId = 'test_visitor_id';
2629

2730
// Placement
28-
const parent = `projects/${projectNumber}/locations/global/catalogs/default_catalog`; // TO CHECK ERROR HANDLING PASTE THE INVALID CATALOG NAME HERE
31+
const parent = `projects/${projectId}/locations/global/catalogs/default_catalog`; // TO CHECK ERROR HANDLING PASTE THE INVALID CATALOG NAME HERE
2932

3033
const UserEventRejoinScope = {
3134
USER_EVENT_REJOIN_SCOPE_UNSPECIFIED: 0,
@@ -36,9 +39,6 @@ async function main() {
3639
// events to be rejoined with the latest product catalog
3740
const userEventRejoinScope = UserEventRejoinScope.UNJOINED_EVENTS;
3841

39-
// Instantiates a client.
40-
const retailClient = new UserEventServiceClient();
41-
4242
const callRejoinUserEvents = async () => {
4343
// Construct request
4444
const request = {

samples/interactive-tutorials/events/write-user-event.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ async function main() {
2121
const {UserEventServiceClient} = require('@google-cloud/retail').v2;
2222
const utils = require('../setup/setup-cleanup');
2323

24-
const projectNumber = process.env['GCLOUD_PROJECT'];
24+
// Instantiates a client.
25+
const retailClient = new UserEventServiceClient();
26+
27+
const projectId = await retailClient.getProjectId();
2528
const visitorId = 'test_visitor_id';
2629

2730
// Placement
28-
const parent = `projects/${projectNumber}/locations/global/catalogs/default_catalog`; // TO CHECK ERROR HANDLING PASTE THE INVALID CATALOG NAME HERE
31+
const parent = `projects/${projectId}/locations/global/catalogs/default_catalog`; // TO CHECK ERROR HANDLING PASTE THE INVALID CATALOG NAME HERE
2932

3033
// User event to write
3134
const userEvent = {
@@ -36,9 +39,6 @@ async function main() {
3639
},
3740
};
3841

39-
// Instantiates a client.
40-
const retailClient = new UserEventServiceClient();
41-
4242
const callWriteUserEvent = async () => {
4343
// Construct request
4444
const request = {

samples/interactive-tutorials/product/add-fulfillment-places.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ async function main(generatedProductId) {
2121
const {ProductServiceClient} = require('@google-cloud/retail').v2;
2222
const utils = require('../setup/setup-cleanup');
2323

24-
const projectNumber = process.env['GCLOUD_PROJECT'];
24+
// Instantiates a client.
25+
const retailClient = new ProductServiceClient();
26+
27+
const projectId = await retailClient.getProjectId();
2528

2629
// Create product
2730
const createdProduct = await utils.createProduct(
28-
projectNumber,
31+
projectId,
2932
generatedProductId
3033
);
3134

@@ -50,9 +53,6 @@ async function main(generatedProductId) {
5053
// at most 1 day and processed once the product is created
5154
const allowMissing = true;
5255

53-
// Instantiates a client.
54-
const retailClient = new ProductServiceClient();
55-
5656
const calladdFulfillmentPlaces = async () => {
5757
// Construct request
5858
const request = {

samples/interactive-tutorials/product/create-product.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ async function main(generatedProductId) {
2121
const {ProductServiceClient} = require('@google-cloud/retail').v2;
2222
const utils = require('../setup/setup-cleanup');
2323

24-
const projectNumber = process.env['GCLOUD_PROJECT'];
24+
// Instantiates a client.
25+
const retailClient = new ProductServiceClient();
26+
27+
const projectId = await retailClient.getProjectId();
2528

2629
// The parent catalog resource name
27-
const parent = `projects/${projectNumber}/locations/global/catalogs/default_catalog/branches/default_branch`;
30+
const parent = `projects/${projectId}/locations/global/catalogs/default_catalog/branches/default_branch`;
2831

2932
// The ID to use for the product
3033
const productId = generatedProductId
@@ -45,9 +48,6 @@ async function main(generatedProductId) {
4548
availability: 'IN_STOCK',
4649
};
4750

48-
// Instantiates a client.
49-
const retailClient = new ProductServiceClient();
50-
5151
const callCreateProduct = async () => {
5252
// Construct request
5353
const request = {

samples/interactive-tutorials/product/crud-product.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ async function main(generatedProductId) {
2020
// Imports the Google Cloud client library.
2121
const {ProductServiceClient} = require('@google-cloud/retail').v2;
2222

23-
const projectNumber = process.env['GCLOUD_PROJECT'];
23+
// Instantiates a client.
24+
const retailClient = new ProductServiceClient();
25+
26+
const projectId = await retailClient.getProjectId();
2427

2528
// The parent catalog resource name
26-
const parent = `projects/${projectNumber}/locations/global/catalogs/default_catalog/branches/default_branch`;
29+
const parent = `projects/${projectId}/locations/global/catalogs/default_catalog/branches/default_branch`;
2730

2831
// The ID to use for the product
2932
const productId = generatedProductId
@@ -63,9 +66,6 @@ async function main(generatedProductId) {
6366
availability: 'OUT_OF_STOCK',
6467
};
6568

66-
// Instantiates a client.
67-
const retailClient = new ProductServiceClient();
68-
6969
const callCreateProduct = async () => {
7070
// Construct request
7171
const request = {

samples/interactive-tutorials/product/delete-product.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ async function main(generatedProductId) {
2121
const {ProductServiceClient} = require('@google-cloud/retail').v2;
2222
const utils = require('../setup/setup-cleanup');
2323

24-
const projectNumber = process.env['GCLOUD_PROJECT'];
24+
// Instantiates a client.
25+
const retailClient = new ProductServiceClient();
26+
27+
const projectId = await retailClient.getProjectId();
2528

2629
// Create product
27-
const product = await utils.createProduct(projectNumber, generatedProductId);
30+
const product = await utils.createProduct(projectId, generatedProductId);
2831

2932
// Full resource name of Product
3033
const name = product.name;
3134

32-
// Instantiates a client.
33-
const retailClient = new ProductServiceClient();
34-
3535
const callDeleteProduct = async () => {
3636
// Construct request
3737
const request = {

samples/interactive-tutorials/product/get-product.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ async function main(generatedProductId) {
2121
const {ProductServiceClient} = require('@google-cloud/retail').v2;
2222
const utils = require('../setup/setup-cleanup');
2323

24-
const projectNumber = process.env['GCLOUD_PROJECT'];
24+
// Instantiates a client.
25+
const retailClient = new ProductServiceClient();
26+
27+
const projectId = await retailClient.getProjectId();
2528

2629
// Create product
27-
const product = await utils.createProduct(projectNumber, generatedProductId);
30+
const product = await utils.createProduct(projectId, generatedProductId);
2831

2932
// Full resource name of Product
3033
const name = product.name;
3134

32-
// Instantiates a client.
33-
const retailClient = new ProductServiceClient();
34-
3535
const callGetProduct = async () => {
3636
// Construct request
3737
const request = {

samples/interactive-tutorials/product/get-products-list.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ async function main() {
2020
// Imports the Google Cloud client library.
2121
const {ProductServiceClient} = require('@google-cloud/retail').v2;
2222

23-
const projectNumber = process.env['GCLOUD_PROJECT'];
24-
25-
// Placement
26-
const parent = `projects/${projectNumber}/locations/global/catalogs/default_catalog/branches/default_branch`;
27-
2823
// Instantiates a client.
2924
const retailClient = new ProductServiceClient();
3025

26+
const projectId = await retailClient.getProjectId();
27+
28+
// Placement
29+
const parent = `projects/${projectId}/locations/global/catalogs/default_catalog/branches/default_branch`;
30+
3131
async function callListProducts() {
3232
console.log('Start get products list');
3333
// Construct request

samples/interactive-tutorials/product/import-products-big-query-table.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ async function main() {
2020
// Imports the Google Cloud client library.
2121
const {ProductServiceClient} = require('@google-cloud/retail').v2;
2222

23-
const projectNumber = process.env['GCLOUD_PROJECT'];
24-
const projectId = process.env['PROJECT_ID'];
23+
// Instantiates a client.
24+
const retailClient = new ProductServiceClient();
25+
26+
const projectId = await retailClient.getProjectId();
2527

2628
const datasetId = 'products';
2729
const tableId = 'products'; // TO CHECK ERROR HANDLING USE THE TABLE WITH INVALID PRODUCTS
2830
const dataSchema = 'product';
2931

3032
// Placement
31-
const parent = `projects/${projectNumber}/locations/global/catalogs/default_catalog/branches/default_branch`; // TO CHECK ERROR HANDLING PASTE THE INVALID CATALOG NAME HERE
33+
const parent = `projects/${projectId}/locations/global/catalogs/default_catalog/branches/default_branch`; // TO CHECK ERROR HANDLING PASTE THE INVALID CATALOG NAME HERE
3234

3335
// The desired input location of the data.
3436
const inputConfig = {
@@ -55,9 +57,6 @@ async function main() {
5557
// The mode of reconciliation between existing products and the products to be imported.
5658
const reconciliationMode = reconciliationModes.INCREMENTAL;
5759

58-
// Instantiates a client.
59-
const retailClient = new ProductServiceClient();
60-
6160
const callImportProducts = async () => {
6261
// Construct request
6362
const request = {

samples/interactive-tutorials/product/import-products-gcs.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@ async function main(bucketName) {
2020
// Imports the Google Cloud client library.
2121
const {ProductServiceClient} = require('@google-cloud/retail').v2;
2222

23-
const projectNumber = process.env['GCLOUD_PROJECT'];
23+
// Instantiates a client.
24+
const retailClient = new ProductServiceClient();
25+
26+
const projectId = await retailClient.getProjectId();
2427

2528
const gcsBucket = `gs://${bucketName}`;
2629
const gcsErrorsBucket = `gs://${bucketName}/error`;
2730
const gcsProductsObject = 'products.json'; // TO CHECK ERROR HANDLING USE THE JSON WITH INVALID PRODUCT
2831

2932
// Placement
30-
const parent = `projects/${projectNumber}/locations/global/catalogs/default_catalog/branches/default_branch`; //TO CHECK ERROR HANDLING PASTE THE INVALID CATALOG NAME HERE
33+
const parent = `projects/${projectId}/locations/global/catalogs/default_catalog/branches/default_branch`; //TO CHECK ERROR HANDLING PASTE THE INVALID CATALOG NAME HERE
3134

3235
// The desired input location of the data.
3336
const inputConfig = {
@@ -48,9 +51,6 @@ async function main(bucketName) {
4851
IOperation: 2,
4952
};
5053

51-
// Instantiates a client.
52-
const retailClient = new ProductServiceClient();
53-
5454
const callImportProducts = async () => {
5555
// Construct request
5656
const request = {

samples/interactive-tutorials/product/import-products-inline-source.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ async function main(id1, id2) {
2121
const {ProductServiceClient} = require('@google-cloud/retail').v2;
2222
const utils = require('../setup/setup-cleanup');
2323

24-
const projectNumber = process.env['GCLOUD_PROJECT'];
24+
// Instantiates a client.
25+
const retailClient = new ProductServiceClient();
26+
27+
const projectId = await retailClient.getProjectId();
2528

2629
// Placement
27-
const parent = `projects/${projectNumber}/locations/global/catalogs/default_catalog/branches/default_branch`;
30+
const parent = `projects/${projectId}/locations/global/catalogs/default_catalog/branches/default_branch`;
2831

2932
const product1 = {
3033
id: id1 ? id1 : Math.random().toString(36).slice(2).toUpperCase(),
@@ -89,9 +92,6 @@ async function main(id1, id2) {
8992
IOperation: 2,
9093
};
9194

92-
// Instantiates a client.
93-
const retailClient = new ProductServiceClient();
94-
9595
const callImportProducts = async () => {
9696
// Construct request
9797
const request = {
@@ -118,7 +118,7 @@ async function main(id1, id2) {
118118
console.log('Import products finished');
119119

120120
// Delete imported products
121-
await utils.deleteProductsByIds(projectNumber, [product1.id, product2.id]);
121+
await utils.deleteProductsByIds(projectId, [product1.id, product2.id]);
122122
console.log('Products deleted');
123123
// [END retail_import_products_from_inline_source]
124124
}

samples/interactive-tutorials/product/remove-fulfillment-places.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ async function main(generatedProductId) {
2121
const {ProductServiceClient} = require('@google-cloud/retail').v2;
2222
const utils = require('../setup/setup-cleanup');
2323

24-
const projectNumber = process.env['GCLOUD_PROJECT'];
24+
// Instantiates a client.
25+
const retailClient = new ProductServiceClient();
26+
27+
const projectId = await retailClient.getProjectId();
2528

2629
// Create product
2730
const createdProduct = await utils.createProduct(
28-
projectNumber,
31+
projectId,
2932
generatedProductId,
3033
true
3134
);
@@ -47,9 +50,6 @@ async function main(generatedProductId) {
4750
seconds: Math.round(Date.now() / 1000),
4851
};
4952

50-
// Instantiates a client.
51-
const retailClient = new ProductServiceClient();
52-
5353
const callRemoveFulfillmentPlaces = async () => {
5454
// Construct request
5555
const request = {

samples/interactive-tutorials/product/set-inventory.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ async function main(generatedProductId) {
2121
const {ProductServiceClient} = require('@google-cloud/retail').v2;
2222
const utils = require('../setup/setup-cleanup');
2323

24-
const projectNumber = process.env['GCLOUD_PROJECT'];
24+
// Instantiates a client.
25+
const retailClient = new ProductServiceClient();
26+
27+
const projectId = await retailClient.getProjectId();
2528

2629
// Create product
2730
const createdProduct = await utils.createProduct(
28-
projectNumber,
31+
projectId,
2932
generatedProductId
3033
);
3134

@@ -61,9 +64,6 @@ async function main(generatedProductId) {
6164
// inventory update will still be processed and retained for at most 1 day until the product is created
6265
const allowMissing = true;
6366

64-
// Instantiates a client.
65-
const retailClient = new ProductServiceClient();
66-
6767
const callSetInventory = async () => {
6868
// Construct request
6969
const request = {

0 commit comments

Comments
 (0)