1+ #! /bin/bash
2+
3+ # Copyright 2022 Google Inc. All Rights Reserved.
4+ #
5+ # Licensed under the Apache License, Version 2.0 (the "License");
6+ # you may not use this file except in compliance with the License.
7+ # You may obtain a copy of the License at
8+ #
9+ # http://www.apache.org/licenses/LICENSE-2.0
10+ #
11+ # Unless required by applicable law or agreed to in writing, software
12+ # distributed under the License is distributed on an "AS IS" BASIS,
13+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ # See the License for the specific language governing permissions and
15+ # limitations under the License.
16+
17+ # get the project_id from gcloud config
18+ project_id=$( gcloud config get-value project)
19+ echo $project_id
20+ timestamp=$( date +%s)
21+ echo $timestamp
22+ service_account_id=" service-acc-" $timestamp
23+
24+ # create service account (your project_id+timestamp)
25+ gcloud iam service-accounts create $service_account_id
26+
27+ # assign needed roles to your new service account
28+ for role in {retail.admin,storage.admin,bigquery.admin}
29+ do
30+ gcloud projects add-iam-policy-binding $project_id --member=" serviceAccount:" $service_account_id " @" $project_id " .iam.gserviceaccount.com" --role=" roles/${role} "
31+ done
32+
33+ # upload your service account key file
34+ service_acc_email=$service_account_id " @" $project_id " .iam.gserviceaccount.com"
35+ gcloud iam service-accounts keys create ~ /key.json --iam-account $service_acc_email
36+
37+ # activate the service account using the key
38+ gcloud auth activate-service-account --key-file ~ /key.json
39+
40+ # set the key as GOOGLE_APPLICATION_CREDENTIALS
41+ export GOOGLE_APPLICATION_CREDENTIALS=~ /key.json
42+
43+ # install needed Google client libraries
44+ virtualenv -p python3 myenv
45+ source myenv/bin/activate
46+
47+ pip install google
48+ pip install google-cloud-retail
49+ pip install google-cloud.storage
50+ pip install google-cloud.bigquery
51+
52+ echo " Your working environment is set up now!"
0 commit comments