|
15 | 15 | # limitations under the License.
|
16 | 16 |
|
17 | 17 | # set the Google Cloud Project ID
|
18 |
| -project_id=$1 |
19 |
| -echo "Project ID: $project_id" |
20 |
| -gcloud config set project "$project_id" |
| 18 | +{ |
| 19 | + project_id=$1 |
| 20 | + echo "Project ID: $project_id" |
| 21 | + gcloud config set project "$project_id" |
21 | 22 |
|
22 |
| -timestamp=$(date +%s) |
| 23 | +} && { |
23 | 24 |
|
24 |
| -service_account_id="service-acc-$timestamp" |
25 |
| -echo "Service Account: $service_account_id" |
| 25 | + timestamp=$(date +%s) |
26 | 26 |
|
27 |
| -# create service account (your service-acc-$timestamp) |
28 |
| -gcloud iam service-accounts create "$service_account_id" |
| 27 | + service_account_id="service-acc-$timestamp" |
| 28 | + echo "Service Account: $service_account_id" |
29 | 29 |
|
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 |
| 30 | + # create service account (your service-acc-$timestamp) |
| 31 | + gcloud iam service-accounts create "$service_account_id" |
35 | 32 |
|
36 |
| -echo "Wait ~60 seconds to be sure the appropriate roles have been assigned to your service account" |
37 |
| -sleep 60 |
| 33 | +} && { |
38 | 34 |
|
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" |
| 35 | + # assign necessary roles to your new service account |
| 36 | + for role in {retail.admin,editor,bigquery.admin} |
| 37 | + do |
| 38 | + gcloud projects add-iam-policy-binding "$project_id" --member="serviceAccount:$service_account_id@$project_id.iam.gserviceaccount.com" --role=roles/"${role}" |
| 39 | + done |
42 | 40 |
|
43 |
| -# activate the service account using the key |
44 |
| -gcloud auth activate-service-account --key-file ~/key.json |
| 41 | +} && { |
45 | 42 |
|
46 |
| -# install needed Google client libraries |
47 |
| -cd ~/cloudshell_open/java-retail/samples/interactive-tutorials || exit |
48 |
| -mvn clean install -DskipTests |
| 43 | + echo "Wait ~60 seconds to be sure the appropriate roles have been assigned to your service account" |
| 44 | + sleep 60 |
49 | 45 |
|
50 |
| -echo "========================================" |
51 |
| -echo "The Google Cloud setup is completed." |
52 |
| -echo "Please proceed with the Tutorial steps" |
53 |
| -echo "========================================" |
| 46 | + # upload your service account key file |
| 47 | + service_acc_email="$service_account_id@$project_id.iam.gserviceaccount.com" |
| 48 | + gcloud iam service-accounts keys create ~/key.json --iam-account "$service_acc_email" |
| 49 | + |
| 50 | + # activate the service account using the key |
| 51 | + gcloud auth activate-service-account --key-file ~/key.json |
| 52 | + |
| 53 | +} && { |
| 54 | + |
| 55 | + # install needed Google client libraries |
| 56 | + cd ~/cloudshell_open/java-retail/samples/interactive-tutorials || exit |
| 57 | + mvn clean install -DskipTests |
| 58 | + |
| 59 | +} && { |
| 60 | + |
| 61 | + # Print success message |
| 62 | + echo "========================================" |
| 63 | + echo "The Google Cloud setup is completed." |
| 64 | + echo "Please proceed with the Tutorial steps" |
| 65 | + echo "========================================" |
| 66 | + |
| 67 | +} || { |
| 68 | + |
| 69 | + # Print error message |
| 70 | + echo "========================================" |
| 71 | + echo "The Google Cloud setup was not completed." |
| 72 | + echo "Please fix the errors above!" |
| 73 | + echo "========================================" |
| 74 | +} |
0 commit comments