diff --git a/generated_samples/interactive-tutorials/user_environment_setup.sh b/generated_samples/interactive-tutorials/user_environment_setup.sh index e5a181b90c76..2d4fe02b791f 100644 --- a/generated_samples/interactive-tutorials/user_environment_setup.sh +++ b/generated_samples/interactive-tutorials/user_environment_setup.sh @@ -14,46 +14,53 @@ # See the License for the specific language governing permissions and # limitations under the License. -# set the Google Cloud Project ID -project_id=$1 -echo "Project ID: $project_id" -gcloud config set project "$project_id" +{ + # set the Google Cloud Project ID + project_id=$1 + echo "Project ID: $project_id" + gcloud config set project "$project_id" +} && { + timestamp=$(date +%s) -timestamp=$(date +%s) + service_account_id="service-acc-$timestamp" + echo "Service Account: $service_account_id" -service_account_id="service-acc-$timestamp" -echo "Service Account: $service_account_id" + # create service account + gcloud iam service-accounts create "$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 +} && { + echo "Wait ~60 seconds to be sure the appropriate roles have been assigned to your service account" + sleep 60 -# create service account -gcloud iam service-accounts create "$service_account_id" + # 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 necessary Google client libraries + virtualenv -p python3 myenv + source myenv/bin/activate + sleep 2 -# 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 - -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" - -# activate the service account using the key -gcloud auth activate-service-account --key-file ~/key.json - -# install necessary Google client libraries -virtualenv -p python3 myenv -source myenv/bin/activate -sleep 2 - -pip install google -pip install google-cloud-retail -pip install google-cloud.storage -pip install google-cloud.bigquery - -echo "=======================================" -echo "The Google Cloud setup is completed." -echo "Please proceed with the Tutorial steps" -echo "=======================================" \ No newline at end of file + pip install google && + pip install google-cloud-retail && + pip install google-cloud.storage && + pip install google-cloud.bigquery +} && { + echo "=======================================" + echo "The Google Cloud setup is completed." + echo "Please proceed with the Tutorial steps" + echo "=======================================" +} || { + echo "=======================================" + echo "The Google Cloud setup was not completed." + echo "Please fix the errors above!" + echo "=======================================" +}