36
36
appengineHostname=$( gcloud app describe --project $PROJECT_ID | grep defaultHostname | cut -d" :" -f2 | awk ' {$1=$1};1' )
37
37
if [[ -z " $appengineHostname " ]]; then
38
38
echo " App Engine is not enabled in $PROJECT_ID .
39
- To do this, please enable it with \" gcloud app create [--region=REGION]\" ,
40
- and then deploy a simple \" Hello World\" default service to enable App Engine."
39
+ As a pre-req for this, as for all App Engine services, please
40
+ (1) Create the app with \" gcloud app create [--region=REGION]\" ,
41
+ (2) and then deploy a simple \" Hello World\" default-service."
41
42
exit 1
42
43
fi
43
44
44
45
appengine_sa_has_editor_role=$( gcloud projects get-iam-policy ${PROJECT_ID} \
45
46
--flatten=" bindings[].members" \
46
- --format=' table(bindings.role)' \
47
+ --format=' table[no-heading] (bindings.role)' \
47
48
--filter=" bindings.members:${PROJECT_ID} @appspot.gserviceaccount.com" | grep " roles/editor" || true)
48
49
50
+
49
51
if [ -z " $appengine_sa_has_editor_role " ]; then
50
52
echo " Must bind role Project Editor for project ${PROJECT_ID} to service account ${PROJECT_ID} @appspot.gserviceaccount.com.
51
53
(The binding exists by default but is missing.)"
@@ -79,10 +81,35 @@ required_svcs=(
79
81
)
80
82
for svc in " ${required_svcs[@]} " ; do
81
83
if ! [ ${enabled_services["$svc"]+_} ]; then
82
- gcloud services enable " $svc "
84
+ gcloud services enable " $svc " --project $PROJECT_ID
83
85
fi
84
86
done
85
87
88
+
89
+ # Extract service account from sink configuration.
90
+ # This is the service account that publishes to PubSub.
91
+ sink_svc_account=$( gcloud logging sinks describe --organization=" $ORGID " " $LOG_SINK " |
92
+ grep writerIdentity | awk ' {print $2}' )
93
+
94
+ if [[ " $SKIP_ADDING_IAM_BINDINGS " != " true" ]]; then
95
+ # Assign a publisher role to the extracted service account.
96
+ gcloud projects add-iam-policy-binding " $PROJECT_ID " \
97
+ --member=" $sink_svc_account " --role=roles/pubsub.publisher --quiet > /dev/null
98
+ else
99
+ # Check to avoid situation where a test does SKIP_ADDING_IAM_BINDINGS and they don't at all exist
100
+ already_have_binding=$( gcloud projects get-iam-policy $PROJECT_ID \
101
+ --flatten=" bindings[].members" \
102
+ --format=' table[no-heading](bindings.role)' \
103
+ --filter=" bindings.members:${sink_svc_account} " | grep " pubsub.publisher" || true)
104
+
105
+ if [ -z $already_have_binding ]; then
106
+ echo " SKIP_ADDING_IAM_BINDINGS is meant for tests
107
+ (to avoid overloading the quotas when you repeated run the tests).
108
+ First deploy the usual way before running the tests."
109
+ exit 1
110
+ fi
111
+ fi
112
+
86
113
# Create PubSub topic for receiving commands from the /schedule handler that is triggered from cron
87
114
gcloud pubsub topics describe " $SCHEDULELABELING_TOPIC " --project=" $PROJECT_ID " & > /dev/null ||
88
115
gcloud pubsub topics create " $SCHEDULELABELING_TOPIC " --project=" $PROJECT_ID " --quiet > /dev/null
@@ -99,21 +126,21 @@ if gcloud pubsub subscriptions describe "$DEADLETTER_SUB" --project="$PROJECT_ID
99
126
gcloud pubsub subscriptions update $DEADLETTER_SUB \
100
127
--project=" $PROJECT_ID " \
101
128
--message-retention-duration=2d \
102
- --quiet > /dev/null 2>&1
129
+ --quiet > /dev/null
103
130
104
131
else
105
132
gcloud pubsub subscriptions create $DEADLETTER_SUB \
106
133
--project=" $PROJECT_ID " \
107
134
--topic $DEADLETTER_TOPIC \
108
135
--message-retention-duration=2d \
109
- --quiet > /dev/null 2>&1
136
+ --quiet > /dev/null
110
137
fi
111
138
112
139
project_number=$( gcloud projects describe $PROJECT_ID --format json | jq -r ' .projectNumber' )
113
140
PUBSUB_SERVICE_ACCOUNT=" service-${project_number} @gcp-sa-pubsub.iam.gserviceaccount.com"
114
141
# The following line is only needed on first deployment, and so slows things
115
142
# down unnecessarily otherwise. But most users do not install Iris repeatedly.
116
- gcloud beta services identity create --project $PROJECT_ID --service pubsub > /dev/null 2>&1
143
+ gcloud beta services identity create --project $PROJECT_ID --service pubsub > /dev/null
117
144
118
145
if ! gcloud iam service-accounts describe iris-msg-sender@${PROJECT_ID} .iam.gserviceaccount.com --project $PROJECT_ID > /dev/null ;
119
146
then
139
166
--dead-letter-topic=$DEADLETTER_TOPIC \
140
167
--min-retry-delay=$MIN_RETRY \
141
168
--max-retry-delay=$MAX_RETRY \
142
- --quiet > /dev/null 2>&1
169
+ --quiet > /dev/null
143
170
else
144
171
gcloud pubsub subscriptions create " $DO_LABEL_SUBSCRIPTION " \
145
172
--topic " $SCHEDULELABELING_TOPIC " --project=" $PROJECT_ID " \
150
177
--dead-letter-topic=$DEADLETTER_TOPIC \
151
178
--min-retry-delay=$MIN_RETRY \
152
179
--max-retry-delay=$MAX_RETRY \
153
- --quiet > /dev/null 2>&1
180
+ --quiet > /dev/null
154
181
fi
155
182
156
183
if [[ " $LABEL_ON_CREATION_EVENT " != " true" ]];
160
187
else
161
188
# Create PubSub topic for receiving logs about new GCP objects
162
189
gcloud pubsub topics describe " $LOGS_TOPIC " --project=" $PROJECT_ID " & > /dev/null ||
163
- gcloud pubsub topics create $LOGS_TOPIC --project=" $PROJECT_ID " --quiet > /dev/null 2>&1
190
+ gcloud pubsub topics create $LOGS_TOPIC --project=" $PROJECT_ID " --quiet > /dev/null
164
191
165
192
# Create or update PubSub subscription for receiving log about new GCP objects
166
193
if gcloud pubsub subscriptions describe " $LABEL_ONE_SUBSCRIPTION " --project=" $PROJECT_ID " & > /dev/null ;
173
200
--dead-letter-topic=$DEADLETTER_TOPIC \
174
201
--min-retry-delay=$MIN_RETRY \
175
202
--max-retry-delay=$MAX_RETRY \
176
- --quiet > /dev/null 2>&1
203
+ --quiet > /dev/null
177
204
else
178
205
gcloud pubsub subscriptions create " $LABEL_ONE_SUBSCRIPTION " \
179
206
--topic " $LOGS_TOPIC " --project=" $PROJECT_ID " \
@@ -184,15 +211,14 @@ else
184
211
--dead-letter-topic=$DEADLETTER_TOPIC \
185
212
--min-retry-delay=$MIN_RETRY \
186
213
--max-retry-delay=$MAX_RETRY \
187
- --quiet > /dev/null 2>&1
214
+ --quiet > /dev/null
188
215
fi
189
216
190
217
fi
191
218
192
219
gcloud pubsub topics describe " $LABEL_ALL_TOPIC " --project=" $PROJECT_ID " & > /dev/null ||
193
220
gcloud pubsub topics create $LABEL_ALL_TOPIC --project=" $PROJECT_ID " --quiet > /dev/null
194
221
195
-
196
222
if gcloud pubsub subscriptions describe " $LABEL_ALL_SUBSCRIPTION " --project=" $PROJECT_ID " & > /dev/null; then
197
223
gcloud pubsub subscriptions update " $LABEL_ALL_SUBSCRIPTION " \
198
224
--project=" $PROJECT_ID " \
@@ -203,7 +229,7 @@ if gcloud pubsub subscriptions describe "$LABEL_ALL_SUBSCRIPTION" --project="$PR
203
229
--dead-letter-topic=$DEADLETTER_TOPIC \
204
230
--min-retry-delay=$MIN_RETRY \
205
231
--max-retry-delay=$MAX_RETRY \
206
- --quiet > /dev/null 2>&1
232
+ --quiet > /dev/null
207
233
else
208
234
gcloud pubsub subscriptions create " $LABEL_ALL_SUBSCRIPTION " \
209
235
--topic " $LABEL_ALL_TOPIC " --project=" $PROJECT_ID " \
@@ -221,28 +247,28 @@ if [[ "$LABEL_ON_CREATION_EVENT" == "true" ]]; then
221
247
# Allow Pubsub to delete failed message from this sub
222
248
gcloud pubsub subscriptions add-iam-policy-binding $DO_LABEL_SUBSCRIPTION \
223
249
--member=" serviceAccount:$PUBSUB_SERVICE_ACCOUNT " \
224
- --role=" roles/pubsub.subscriber" --project $PROJECT_ID > /dev/null 2>&1
250
+ --role=" roles/pubsub.subscriber" --project $PROJECT_ID > /dev/null
225
251
226
252
fi
227
253
228
254
gcloud pubsub subscriptions add-iam-policy-binding $LABEL_ALL_SUBSCRIPTION \
229
255
--member=" serviceAccount:$PUBSUB_SERVICE_ACCOUNT " \
230
- --role=" roles/pubsub.subscriber" --project $PROJECT_ID > /dev/null 2>&1
256
+ --role=" roles/pubsub.subscriber" --project $PROJECT_ID > /dev/null
231
257
232
258
# Allow Pubsub to delete failed message from this sub
233
259
gcloud pubsub subscriptions add-iam-policy-binding $LABEL_ONE_SUBSCRIPTION \
234
260
--member=" serviceAccount:$PUBSUB_SERVICE_ACCOUNT " \
235
- --role=" roles/pubsub.subscriber" --project $PROJECT_ID > /dev/null 2>&1
261
+ --role=" roles/pubsub.subscriber" --project $PROJECT_ID > /dev/null
236
262
237
263
# Allow Pubsub to publish into the deadletter topic
238
264
gcloud pubsub topics add-iam-policy-binding $DEADLETTER_TOPIC \
239
265
--member=" serviceAccount:$PUBSUB_SERVICE_ACCOUNT " \
240
- --role=" roles/pubsub.publisher" --project " $PROJECT_ID " > /dev/null 2>&1
266
+ --role=" roles/pubsub.publisher" --project " $PROJECT_ID " > /dev/null
241
267
242
268
if [[ " $SKIP_ADDING_IAM_BINDINGS " != " true" ]]; then
243
269
gcloud projects add-iam-policy-binding " ${PROJECT_ID} " \
244
270
--member=" serviceAccount:${PUBSUB_SERVICE_ACCOUNT} " \
245
- --role=' roles/iam.serviceAccountTokenCreator' > /dev/null 2>&1
271
+ --role=' roles/iam.serviceAccountTokenCreator' > /dev/null
246
272
fi
247
273
248
274
if [[ " $LABEL_ON_CRON " == " true" ]]; then
0 commit comments