Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
chore (samples) Warn user about fails on user_environment_setup.sh. (#…
Browse files Browse the repository at this point in the history
…490)

* 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 <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
dfirova and gcf-owl-bot[bot] authored Aug 9, 2022
1 parent 5e76166 commit a5fc770
Showing 1 changed file with 48 additions and 27 deletions.
75 changes: 48 additions & 27 deletions samples/interactive-tutorials/user_environment_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "========================================"
}

0 comments on commit a5fc770

Please sign in to comment.