Repository navigation
Expand file tree
/
Copy pathdeploy-cloud-logging.sh
More file actions
executable file
·73 lines (60 loc) · 2.49 KB
/
Copy pathdeploy-cloud-logging.sh
File metadata and controls
executable file
·73 lines (60 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
# Copyright 2023-2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
SA_BASE="example-cloudlogger-sa-"
# shellcheck disable=SC2034
PROXY_NAME="sample-cloud-logging"
# shellcheck disable=SC2034
scriptid="deploy-cloud-logging"
source ./lib/utils.sh
# ====================================================================
check_shell_variables
# shellcheck disable=SC2034
TOKEN=$(gcloud auth print-access-token)
# check and maybe enable services
SERVICES_OF_INTEREST=("logging.googleapis.com")
for svc in "${SERVICES_OF_INTEREST[@]}"; do
if gcloud services list --enabled --project "$PROJECT" --format="value(config.name)" --filter="config.name=$svc" >/dev/null; then
printf "%s is already enabled in the project...\n" "$svc"
else
printf "Attempting to enable %s...\n" "$svc"
if gcloud services enable logging --project="$PROJECT"; then
printf " done.\n"
else
printf "%s is not enabled, and the attempt to enable it failed. Cannot proceed.\n" "$svc"
exit 1
fi
fi
done
# Creating and deleting an SA by the same name, repeatedly, can cause problems.
# This uses a random factor to uniquify the SA name.
# shellcheck disable=SC2002
rand_string=$(cat /dev/urandom | LC_CTYPE=C tr -cd '[:alnum:]' | head -c 6)
SA_NAME="${SA_BASE}${rand_string}"
create_service_account_and_grant_logWriter_role "$SA_NAME"
# the above implicitly sets SA_EMAIL
maybe_install_apigeecli
printf "Creating and Deploying Apigee sample-cloud-logging proxy...\n"
maybe_import_and_deploy ./apiproxy "$SA_EMAIL" "force"
# wait outside of the fn, in case there were multiple deploys
# shellcheck disable=SC2154
if [[ $need_wait -eq 1 ]]; then
printf "Waiting...\n"
wait
fi
printf "\nAll the Apigee artifacts are successfully deployed!\n\n"
printf "Generate some calls with:\n"
printf " curl -i https://%s/v1/samples/cloud-logging\n\n" "$APIGEE_HOST"
printf "After that, make sure you read the logs from Cloud Logging with\n"
printf " gcloud logging read \"logName=projects/%s/logs/apigee\"\n" "$PROJECT"