14
14
# See the License for the specific language governing permissions and
15
15
# limitations under the License.
16
16
17
- # set the Google Cloud Project ID
18
- project_id=$1
19
- echo " Project ID: $project_id "
20
- gcloud config set project " $project_id "
17
+ {
18
+ # set the Google Cloud Project ID
19
+ project_id=$1
20
+ echo " Project ID: $project_id "
21
+ gcloud config set project " $project_id "
22
+ } && {
23
+ timestamp=$( date +%s)
21
24
22
- timestamp=$( date +%s)
25
+ service_account_id=" service-acc-$timestamp "
26
+ echo " Service Account: $service_account_id "
23
27
24
- service_account_id=" service-acc-$timestamp "
25
- echo " Service Account: $service_account_id "
28
+ # create service account
29
+ gcloud iam service-accounts create " $service_account_id "
30
+ } && {
31
+ # assign necessary roles to your new service account
32
+ for role in {retail.admin,editor,bigquery.admin}
33
+ do
34
+ gcloud projects add-iam-policy-binding " $project_id " --member=" serviceAccount:$service_account_id @$project_id .iam.gserviceaccount.com" --role=roles/" ${role} "
35
+ done
36
+ } && {
37
+ echo " Wait ~60 seconds to be sure the appropriate roles have been assigned to your service account"
38
+ sleep 60
26
39
27
- # create service account
28
- gcloud iam service-accounts create " $service_account_id "
40
+ # upload your service account key file
41
+ service_acc_email=" $service_account_id @$project_id .iam.gserviceaccount.com"
42
+ gcloud iam service-accounts keys create ~ /key.json --iam-account " $service_acc_email "
43
+ } && {
44
+ # activate the service account using the key
45
+ gcloud auth activate-service-account --key-file ~ /key.json
46
+ } && {
47
+ # install necessary Google client libraries
48
+ virtualenv -p python3 myenv
49
+ source myenv/bin/activate
50
+ sleep 2
29
51
30
- # assign necessary roles to your new service account
31
- for role in {retail.admin,editor,bigquery.admin}
32
- do
33
- gcloud projects add-iam-policy-binding " $project_id " --member=" serviceAccount:$service_account_id @$project_id .iam.gserviceaccount.com" --role=roles/" ${role} "
34
- done
35
-
36
- echo " Wait ~60 seconds to be sure the appropriate roles have been assigned to your service account"
37
- sleep 60
38
-
39
- # upload your service account key file
40
- service_acc_email=" $service_account_id @$project_id .iam.gserviceaccount.com"
41
- gcloud iam service-accounts keys create ~ /key.json --iam-account " $service_acc_email "
42
-
43
- # activate the service account using the key
44
- gcloud auth activate-service-account --key-file ~ /key.json
45
-
46
- # install necessary Google client libraries
47
- virtualenv -p python3 myenv
48
- source myenv/bin/activate
49
- sleep 2
50
-
51
- pip install google
52
- pip install google-cloud-retail
53
- pip install google-cloud.storage
54
- pip install google-cloud.bigquery
55
-
56
- echo " ======================================="
57
- echo " The Google Cloud setup is completed."
58
- echo " Please proceed with the Tutorial steps"
59
- echo " ======================================="
52
+ pip install google &&
53
+ pip install google-cloud-retail &&
54
+ pip install google-cloud.storage &&
55
+ pip install google-cloud.bigquery
56
+ } && {
57
+ echo " ======================================="
58
+ echo " The Google Cloud setup is completed."
59
+ echo " Please proceed with the Tutorial steps"
60
+ echo " ======================================="
61
+ } || {
62
+ echo " ======================================="
63
+ echo " The Google Cloud setup was not completed."
64
+ echo " Please fix the errors above!"
65
+ echo " ======================================="
66
+ }
0 commit comments