-
Notifications
You must be signed in to change notification settings - Fork 25
/
upgrade.sh
executable file
·189 lines (166 loc) · 5.86 KB
/
upgrade.sh
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/bash -eu
#
# Copyright 2019-2021 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.
if [ "$#" -lt 7 ]; then
echo "Usage: $0 [ --project-id ] [ --oauth-client-id ] [ --fqdn ] [ --data-producers ] [ --region ] [ --zone] [ --tag ] [ --marketplace-enabled ] [ --secret-name-prefix ]" >&2
exit 1
fi
DIR=`dirname "$BASH_SOURCE"`
pushd $DIR
function finish {
popd
}
trap finish EXIT
export MARKETPLACE_INTEGRATION_ENABLED="false";
export SERVICE_ACCOUNT_NAME=ds-api-mgr;
for i in "$@"; do
case $i in
--project-id=*)
export PROJECT_ID="${i#*=}"
shift # past argument=value
;;
--oauth-client-id=*)
export OAUTH_CLIENT_ID="${i#*=}"
shift # past argument=value
;;
--api-key=*)
export API_KEY="${i#*=}"
shift # past argument=value
;;
--auth-domain=*)
export AUTH_DOMAIN="${i#*=}"
shift # past argument=value
;;
--tenant-id=*)
export TENANT_ID="${i#*=}"
shift # past argument=value
;;
--fqdn=*)
export FQDN="${i#*=}"
shift # past argument=value
;;
--data-producers=*)
export DATA_PRODUCERS="${i#*=}"
shift # past argument=value
;;
--region=*)
export REGION="${i#*=}"
shift # past argument=value
;;
--zone=*)
export ZONE="${i#*=}"
shift # past argument=value
;;
--tag=*)
export TAG="${i#*=}"
shift # past argument=value
;;
--marketplace-enabled)
export MARKETPLACE_INTEGRATION_ENABLED="true"
shift # past argument=value
;;
--secret-name-prefix=*)
export SECRET_NAME_PREFIX="${i#*=}"
shift # past argument=value
;;
*)
# unknown option
echo "Unknown option ${i}"
;;
esac
done
if [ -z "$PROJECT_ID" ]; then
export PROJECT_ID=`gcloud config list --format 'value(core.project)'`;
echo "--project-id not supplied, using current gcloud config projectId of $PROJECT_ID"
else
gcloud config set project "$PROJECT_ID"
fi
if [[ -z "${SECRET_NAME_PREFIX:=}" ]]; then
export SECRET_NAME_PREFIX=$PROJECT_ID
echo "Defaulted SECRET_NAME_PREFIX to '${PROJECT_ID}'"
fi
if [ -z "$OAUTH_CLIENT_ID" ]; then
echo "--oauth-client-id must be supplied"
exit 2
fi
if [ -z "$API_KEY" ]; then
echo "--api-key must be supplied"
exit 3
fi
if [ -z "$AUTH_DOMAIN" ]; then
echo "--auth-domain must be supplied"
exit 4
fi
if [[ -z "${TENANT_ID:=}" ]]; then
echo "--tenant-id must be supplied"
exit 5
fi
if [ -z "$FQDN" ]; then
echo "--fqdn must be supplied"
exit 6
fi
if [ -z "$DATA_PRODUCERS" ]; then
echo "--data-producers must be supplied"
exit 7
fi
cd api/v1
echo "Starting upgrade for $PROJECT_ID";
npm run deploy
cd ..
EXIT_CODE=0
gcloud iam roles describe custom.ds.api.mgr --project ${PROJECT_ID} || EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
gcloud iam roles delete custom.ds.api.mgr --project ${PROJECT_ID} || EXIT_CODE=$?
fi
EXIT_CODE=0
gcloud iam roles describe datashare.api.manager --project ${PROJECT_ID} || EXIT_CODE=$?
if [ $EXIT_CODE -eq 1 ]; then
gcloud iam roles create datashare.api.manager --project ${PROJECT_ID} --file config/ds-api-mgr-role-definition.yaml --quiet
# https://cloud.google.com/sdk/gcloud/reference/projects/add-iam-policy-binding
gcloud projects add-iam-policy-binding ${PROJECT_ID} \
--member serviceAccount:${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com \
--role="projects/${PROJECT_ID}/roles/datashare.api.manager"
# https://cloud.google.com/sdk/gcloud/reference/projects/remove-iam-policy-binding
gcloud projects remove-iam-policy-binding ${PROJECT_ID} \
--member serviceAccount:${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com \
--role="projects/${PROJECT_ID}/roles/custom.ds.api.mgr" || EXIT_CODE=$?
else
gcloud iam roles update datashare.api.manager --project ${PROJECT_ID} --file config/ds-api-mgr-role-definition.yaml --quiet
fi
EXIT_CODE=0
# Subscriber custom roles
gcloud iam roles describe datashare.bigquery.dataViewer --project ${PROJECT_ID} || EXIT_CODE=$?
if [ $EXIT_CODE -eq 1 ]; then
gcloud iam roles create datashare.bigquery.dataViewer --project ${PROJECT_ID} --file config/ds-bigquery-data-viewer-definition.yaml --quiet
else
gcloud iam roles update datashare.bigquery.dataViewer --project ${PROJECT_ID} --file config/ds-bigquery-data-viewer-definition.yaml --quiet
fi
EXIT_CODE=0
gcloud iam roles describe datashare.storage.objectViewer --project ${PROJECT_ID} || EXIT_CODE=$?
if [ $EXIT_CODE -eq 1 ]; then
gcloud iam roles create datashare.storage.objectViewer --project ${PROJECT_ID} --file config/ds-storage-object-viewer-definition.yaml --quiet
else
gcloud iam roles update datashare.storage.objectViewer --project ${PROJECT_ID} --file config/ds-storage-object-viewer-definition.yaml --quiet
fi
EXIT_CODE=0
gcloud iam roles describe datashare.pubsub.subscriber --project ${PROJECT_ID} || EXIT_CODE=$?
if [ $EXIT_CODE -eq 1 ]; then
gcloud iam roles create datashare.pubsub.subscriber --project ${PROJECT_ID} --file config/ds-pubsub-subscriber-definition.yaml --quiet
else
gcloud iam roles update datashare.pubsub.subscriber --project ${PROJECT_ID} --file config/ds-pubsub-subscriber-definition.yaml --quiet
fi
cd ../frontend
npm run deploy
echo "Completed upgrade for $PROJECT_ID";