Skip to content

Commit e29a2ed

Browse files
fix: remove gcloud_project env variable (#156)
Co-authored-by: Karl Weinmeister <11586922+kweinmeister@users.noreply.github.com>
1 parent d34d524 commit e29a2ed

38 files changed

+260
-228
lines changed

retail/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 = {

retail/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 = {

retail/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 = {

retail/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 = {

retail/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 = {

retail/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 = {

retail/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 = {

retail/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 = {

retail/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

retail/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 = {

0 commit comments

Comments
 (0)