From a5fc77075e75a07c1ef391b501c874be820a53f1 Mon Sep 17 00:00:00 2001 From: dfirova <93149631+dfirova@users.noreply.github.com> Date: Tue, 9 Aug 2022 19:02:11 +0300 Subject: [PATCH] chore (samples) Warn user about fails on user_environment_setup.sh. (#490) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added error message on user setup. * Divided sh script into steps for error handling. * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- .../user_environment_setup.sh | 75 ++++++++++++------- 1 file changed, 48 insertions(+), 27 deletions(-) diff --git a/samples/interactive-tutorials/user_environment_setup.sh b/samples/interactive-tutorials/user_environment_setup.sh index 46915b6f..2fa0efcf 100644 --- a/samples/interactive-tutorials/user_environment_setup.sh +++ b/samples/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 "========================================" +}