diff --git a/retail/interactive-tutorials/user_environment_setup.sh b/retail/interactive-tutorials/user_environment_setup.sh index 46915b6f8be..2fa0efcfb3c 100644 --- a/retail/interactive-tutorials/user_environment_setup.sh +++ b/retail/interactive-tutorials/user_environment_setup.sh @@ -15,39 +15,60 @@ # limitations under the License. # set the Google Cloud Project ID -project_id=$1 -echo "Project ID: $project_id" -gcloud config set project "$project_id" +{ + project_id=$1 + echo "Project ID: $project_id" + gcloud config set project "$project_id" -timestamp=$(date +%s) +} && { -service_account_id="service-acc-$timestamp" -echo "Service Account: $service_account_id" + timestamp=$(date +%s) -# create service account (your service-acc-$timestamp) -gcloud iam service-accounts create "$service_account_id" + service_account_id="service-acc-$timestamp" + echo "Service Account: $service_account_id" -# assign necessary roles to your new service account -for role in {retail.admin,editor,bigquery.admin} - do - gcloud projects add-iam-policy-binding "$project_id" --member="serviceAccount:$service_account_id@$project_id.iam.gserviceaccount.com" --role=roles/"${role}" -done + # create service account (your service-acc-$timestamp) + gcloud iam service-accounts create "$service_account_id" -echo "Wait ~60 seconds to be sure the appropriate roles have been assigned to your service account" -sleep 60 +} && { -# upload your service account key file -service_acc_email="$service_account_id@$project_id.iam.gserviceaccount.com" -gcloud iam service-accounts keys create ~/key.json --iam-account "$service_acc_email" + # assign necessary roles to your new service account + for role in {retail.admin,editor,bigquery.admin} + do + gcloud projects add-iam-policy-binding "$project_id" --member="serviceAccount:$service_account_id@$project_id.iam.gserviceaccount.com" --role=roles/"${role}" + done -# activate the service account using the key -gcloud auth activate-service-account --key-file ~/key.json +} && { -# install needed Google client libraries -cd ~/cloudshell_open/java-retail/samples/interactive-tutorials || exit -mvn clean install -DskipTests + echo "Wait ~60 seconds to be sure the appropriate roles have been assigned to your service account" + sleep 60 -echo "========================================" -echo "The Google Cloud setup is completed." -echo "Please proceed with the Tutorial steps" -echo "========================================" + # upload your service account key file + service_acc_email="$service_account_id@$project_id.iam.gserviceaccount.com" + gcloud iam service-accounts keys create ~/key.json --iam-account "$service_acc_email" + + # activate the service account using the key + gcloud auth activate-service-account --key-file ~/key.json + +} && { + + # install needed Google client libraries + cd ~/cloudshell_open/java-retail/samples/interactive-tutorials || exit + mvn clean install -DskipTests + +} && { + + # Print success message + echo "========================================" + echo "The Google Cloud setup is completed." + echo "Please proceed with the Tutorial steps" + echo "========================================" + +} || { + + # Print error message + echo "========================================" + echo "The Google Cloud setup was not completed." + echo "Please fix the errors above!" + echo "========================================" +}