-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.sh
executable file
·84 lines (67 loc) · 2.61 KB
/
setup.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
#!/bin/bash
BASEDIR=$(dirname $0)
config=${BASEDIR}/config.yaml
usage() {
echo "Usage assumes setup for Apigee X. You may need to edit this for hybrid and definitely for legacy/opdk" 1>&2
echo "Usage: $0 [-h] [-a <path-to-ax-sa-json>] [-u <user-email: an email address for the account>] [-o <organiztion> ] [-e <environment>] [-t <token>] [-r <remote url>] [-c <config-file-path]" 1>&2
exit 1;
}
while getopts "a::e:o:t:r:c:u:h" o; do
case "${o}" in
h)
usage
;;
a)
analytics=${OPTARG}
;;
u)
email=${OPTARG}
;;
e)
env=${OPTARG}
;;
o)
org=${OPTARG}
;;
t)
token=${OPTARG}
;;
r)
remoteurl=${OPTARG}
;;
c)
config=${OPTARG}
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "${env}" ] || [ -z "${org}" ] || [ -t "${token}" ] || [ -z "${remoteurl}" ] || [ -z "${email}" ]; then
usage
fi
BASEURL=https://apigee.googleapis.com/v1/organizations/${org}
OS=$(uname -s)
case $OS in
"Linux")
arch="linux"
;;
"Darwin")
arch="macOS"
;;
esac
wget "https://github.com/apigee/apigee-remote-service-cli/releases/download/v2.0.2/apigee-remote-service-cli_2.0.2_${arch}_64-bit.tar.gz" -O apigee-remote-service-cli.tar.gz
wget "https://github.com/apigee/apigee-remote-service-envoy/releases/download/v2.0.2/apigee-remote-service-envoy_2.0.2_linux_64-bit.tar.gz" -O apigee-remote-service-envoy.tar.gz
tar xf apigee-remote-service-cli.tar.gz apigee-remote-service-cli
tar xf apigee-remote-service-envoy.tar.gz apigee-remote-service-envoy
cp apigee-remote-service-envoy envoy_adapter
${BASEDIR}/apigee-remote-service-cli provision -f -o $org -e $env -t $token --runtime $remoteurl --analytics-sa ${analytics} > $config
# Our api product
cat $BASEDIR/apigee-jsons/apiproduct.json | sed -e "s/@@ENV@@/${env}/" | curl -X POST "${BASEURL}/apiproducts" -H "Authorization: Bearer $token" -H "Content-Type: application/json" -d @- > ${BASEDIR}/my_apiproduct.json
# Our developer
user=$(echo [email protected] | sed -e 's/\(.*\)@.*/\1/')
cat $BASEDIR/apigee-jsons/developer.json | sed -e "s/@@EMAIL@@/${email}/" -e "s/@@USER@@/${user}/" | curl -X POST "${BASEURL}/developers" -H "Authorization: Bearer $token" -H "Content-Type: application/json" -d @- > ${BASEDIR}/my_developer.json
# Our app
curl -X POST "${BASEURL}/developers/${email}/apps" -H "Authorization: Bearer $token" -H "Content-Type: application/json" -d @${BASEDIR}/apigee-jsons/app.json > ${BASEDIR}/my_app.json
rm apigee-remote-service-*