-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_exports.sh
executable file
·51 lines (32 loc) · 2.56 KB
/
get_exports.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
#!/bin/bash
echo "#!/bin/bash" > gen_exports.sh
chmod u+x gen_exports.sh
NAMESPACE="$(oc project -q)"
# namespace with 3scale
SCALE_NAMESPACE="$(oc project -q)"
if [ $# -gt 0 ]; then
SCALE_NAMESPACE=$1
fi
# Tenant
SEC_NAME="threescale-provider-account-${RANDOM}"
DOMAIN="https://$(oc get route --namespace=${SCALE_NAMESPACE} | grep 3scale-admin | awk '{print $2}')"
TOKEN="$(oc get secret system-seed --namespace=${SCALE_NAMESPACE} -o go-template --template="{{.data.ADMIN_ACCESS_TOKEN|base64decode}}")"
echo "curl -X POST "${DOMAIN}/admin/api/personal/access_tokens.json" -d 'name=hu&permission=rw&scopes%5B%5D=finance&scopes%5B%5D=stats&scopes%5B%5D=account_management&scopes%5B%5D=policy_registry&access_token=${TOKEN}' -k | jq -r .access_token.value"
ACCESS_TOKEN="$(curl -X POST "${DOMAIN}/admin/api/personal/access_tokens.json" -d "name=hu&permission=rw&scopes%5B%5D=finance&scopes%5B%5D=stats&scopes%5B%5D=account_management&scopes%5B%5D=policy_registry&access_token=${TOKEN}" -k | jq -r .access_token.value)"
echo "Create secret with ${DOMAIN} ${ACCESS_TOKEN}"
oc create secret --namespace=${NAMESPACE} generic ${SEC_NAME} --from-literal="adminURL=${DOMAIN}" --from-literal="token=${ACCESS_TOKEN}"
oc label secret/${SEC_NAME} capabilities=''
echo "export THREESCALE_PROVIDER_URL=\"${DOMAIN}\"" >> gen_exports.sh
echo "export THREESCALE_PROVIDER_TOKEN=\"${ACCESS_TOKEN}\"" >> gen_exports.sh
echo "export OCP_PROVIDER_ACCOUNT_REF=\"${SEC_NAME}\"" >> gen_exports.sh
# Master
SEC_NAME="threescale-master-account-${RANDOM}"
DOMAIN="https://$(oc get route --namespace=${SCALE_NAMESPACE} | grep master | awk '{print $2}')"
TOKEN="$(oc get secret system-seed --namespace=${SCALE_NAMESPACE} -o go-template --template="{{.data.MASTER_ACCESS_TOKEN|base64decode}}")"
echo "curl -X POST "${DOMAIN}/admin/api/personal/access_tokens.json" -d 'name=hu&permission=rw&scopes%5B%5D=stats&scopes%5B%5D=account_management&scopes%5B%5D=policy_registry&access_token=${TOKEN}' -k | jq -r .access_token.value"
ACCESS_TOKEN="$(curl -X POST "${DOMAIN}/admin/api/personal/access_tokens.json" -d "name=hu&permission=rw&scopes%5B%5D=stats&scopes%5B%5D=account_management&scopes%5B%5D=policy_registry&access_token=${TOKEN}" -k | jq -r .access_token.value)"
echo "Create master secret with ${DOMAIN} ${ACCESS_TOKEN}"
oc create secret --namespace=${NAMESPACE} generic ${SEC_NAME} --from-literal="MASTER_ACCESS_TOKEN=${ACCESS_TOKEN}"
oc label secret/${SEC_NAME} capabilities=''
echo "export THREESCALE_MASTER_URL=\"${DOMAIN}\"" >> gen_exports.sh
echo "export THREESCALE_MASTER_TOKEN=\"${ACCESS_TOKEN}\"" >> gen_exports.sh