1
1
#! /bin/bash
2
-
3
2
# Copyright 2022 Google Inc. All Rights Reserved.
4
3
#
5
4
# Licensed under the Apache License, Version 2.0 (the "License");
14
13
# See the License for the specific language governing permissions and
15
14
# limitations under the License.
16
15
16
+ success () {
17
+ echo " ========================================="
18
+ echo " The Google Cloud setup is completed."
19
+ echo " Please proceed with the Tutorial steps"
20
+ echo " ========================================="
21
+ exit 0
22
+ }
23
+
24
+ failure () {
25
+ echo " ========================================="
26
+ echo " The Google Cloud setup was not completed."
27
+ echo " Please fix the errors above!"
28
+ echo " ========================================="
29
+ exit 1
30
+ }
31
+
32
+ # catch any error that happened during execution
33
+ trap ' failure' ERR
34
+
17
35
# set the Google Cloud Project ID
18
36
project_id=$1
19
37
echo " Project ID: $project_id "
20
38
gcloud config set project " $project_id "
21
39
22
40
timestamp=$( date +%s)
23
-
24
41
service_account_id=" service-acc-$timestamp "
25
42
echo " Service Account: $service_account_id "
26
-
27
43
# create service account (your service-acc-$timestamp)
28
44
gcloud iam service-accounts create " $service_account_id "
29
45
30
46
# assign necessary roles to your new service account
31
47
for role in {retail.admin,editor,bigquery.admin}
32
- do
48
+ do
33
49
gcloud projects add-iam-policy-binding " $project_id " --member=" serviceAccount:$service_account_id @$project_id .iam.gserviceaccount.com" --role=roles/" ${role} "
34
50
done
35
51
36
52
echo " Wait ~60 seconds to be sure the appropriate roles have been assigned to your service account"
37
53
sleep 60
38
-
39
54
# upload your service account key file
40
55
service_acc_email=" $service_account_id @$project_id .iam.gserviceaccount.com"
41
56
gcloud iam service-accounts keys create ~ /key.json --iam-account " $service_acc_email "
@@ -44,10 +59,5 @@ gcloud iam service-accounts keys create ~/key.json --iam-account "$service_acc_e
44
59
gcloud auth activate-service-account --key-file ~ /key.json
45
60
46
61
# install needed Google client libraries
47
- cd ~ /cloudshell_open/nodejs-retail/samples || exit
62
+ cd ~ /cloudshell_open/nodejs-retail/samples
48
63
npm install
49
-
50
- echo " ======================================="
51
- echo " The Google Cloud setup is completed."
52
- echo " Please proceed with the Tutorial steps"
53
- echo " ======================================="
0 commit comments