-
Notifications
You must be signed in to change notification settings - Fork 162
/
pipeline.sh
executable file
·144 lines (128 loc) · 4.95 KB
/
pipeline.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
#!/bin/sh
# Copyright 2022 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.
set -e
SCRIPTPATH="$( cd "$(dirname "$0")" || exit >/dev/null 2>&1 ; pwd -P )"
proxyName="auth-schemes-v0"
developerEmail="[email protected]"
appName="AuthApp"
productName="APIAuthExamples"
rm -f "$SCRIPTPATH"/jwt.key.pem "$SCRIPTPATH"/jwt.key.pub.pem
openssl genrsa -out "$SCRIPTPATH"/jwt.key.pem 2048
openssl rsa -in "$SCRIPTPATH"/jwt.key.pem -pubout -out "$SCRIPTPATH"/jwt.key.pub.pem
_JWT_PRIVATE_KEY=$(cat "$SCRIPTPATH"/jwt.key.pem)
_JWT_PUBLIC_KEY=$(cat "$SCRIPTPATH"/jwt.key.pub.pem)
export _JWT_PRIVATE_KEY
export _JWT_PUBLIC_KEY
envsubst < "$SCRIPTPATH"/templates/AssignMessage.SetPrivateKey.xml.tmpl > "$SCRIPTPATH"/apiproxy/policies/AssignMessage.SetPrivateKey.xml
envsubst < "$SCRIPTPATH"/templates//JWT.Verify.xml.tmpl > "$SCRIPTPATH"/apiproxy/policies/JWT.Verify.xml
rm -f "$SCRIPTPATH"/edge.json
cat <<EOF >> "$SCRIPTPATH/edge.json"
{
"version": "1.0",
"envConfig": {
"$APIGEE_X_ENV": {
"targetServers": [],
"virtualHosts": [],
"caches": [],
"kvms": []
}
},
"orgConfig": {
"apiProducts": [
{
"name": "$productName",
"approvalType": "auto",
"attributes": [
{
"name": "access",
"value": "public"
}
],
"description": "Used by apigee/devrel/references/$proxyName",
"displayName": "API Auth Examples",
"environments": [
"$APIGEE_X_ENV"
],
"operationGroup": {
"operationConfigs": [
{
"apiSource": "$proxyName",
"operations": [
{
"resource": "/**",
"methods": [
"GET"
]
}
],
"quota": {}
}
],
"operationConfigType": "proxy"
}
}
],
"developers": [
{
"email": "$developerEmail",
"firstName": "Ally",
"lastName": "Alien",
"userName": "allythealien",
"attributes": []
}
],
"developerApps": {
"$developerEmail": [
{
"name": "$appName",
"attributes": [],
"apiProducts": [
"$productName"
],
"callbackUrl": "",
"scopes": []
}
]
}
}
}
EOF
googleToken="$(gcloud config config-helper --force-auth-refresh --format json | jq -r '.credential.access_token')";
export PATH="$PATH:$SCRIPTPATH/../../tools/apigee-sackmesser/bin"
# deploy Apigee artifacts: proxy, developer, app, product
sackmesser deploy --googleapi -n "$proxyName" -o "$APIGEE_X_ORG" -e "$APIGEE_X_ENV" -t "$googleToken" -h "$APIGEE_X_HOSTNAME" -d "$SCRIPTPATH"
# fetch newly created app
appId=$(sackmesser list --googleapi -t "$googleToken" "organizations/$APIGEE_X_ORG/developers/$developerEmail/apps/$appName" | jq -r '.appId')
appJson=$(sackmesser list --googleapi -t "$googleToken" "organizations/$APIGEE_X_ORG/apps/$appId" | jq '.credentials[0]')
# extract client id and secret from newly created app
APP_CLIENT_ID=$(echo "$appJson" | jq -r '.consumerKey')
export APP_CLIENT_ID
APP_CLIENT_SECRET=$(echo "$appJson" | jq -r '.consumerSecret')
export APP_CLIENT_SECRET
# var is expected by integration test (apickli)
export PROXY_URL="$APIGEE_X_HOSTNAME/auth-schemes/v0"
# integration tests
npm install
npm run test
# clean up
if [ "$APIGEE_AUTH_SCHEMES_CLEAN_UP" = "true" ]; then
echo "Cleaning up KMS records..."
sackmesser clean app "$appId" --googleapi -t "$googleToken" -o "$APIGEE_X_ORG" --quiet
sackmesser clean developer "$developerEmail" --googleapi -t "$googleToken" -o "$APIGEE_X_ORG" --quiet
sackmesser clean product "$productName" --googleapi -t "$googleToken" -o "$APIGEE_X_ORG" --quiet
rm -f "$SCRIPTPATH"/edge.json
echo "Deleting API proxy..."
sackmesser clean proxy "$proxyName" --googleapi -t "$googleToken" -o "$APIGEE_X_ORG" --quiet
fi