Skip to content

Commit 6d0af84

Browse files
chore (samples) Warn user about fails on user_environment_setup.sh. (#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>
1 parent c03bc2c commit 6d0af84

File tree

1 file changed

+48
-27
lines changed

1 file changed

+48
-27
lines changed

java-retail/samples/interactive-tutorials/user_environment_setup.sh

+48-27
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,60 @@
1515
# limitations under the License.
1616

1717
# 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"
2122

22-
timestamp=$(date +%s)
23+
} && {
2324

24-
service_account_id="service-acc-$timestamp"
25-
echo "Service Account: $service_account_id"
25+
timestamp=$(date +%s)
2626

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"
2929

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"
3532

36-
echo "Wait ~60 seconds to be sure the appropriate roles have been assigned to your service account"
37-
sleep 60
33+
} && {
3834

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
4240

43-
# activate the service account using the key
44-
gcloud auth activate-service-account --key-file ~/key.json
41+
} && {
4542

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
4945

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

Comments
 (0)