Skip to content

Instantly share code, notes, and snippets.

@chmouel
Created November 7, 2018 13:26
Show Gist options
  • Save chmouel/f001bed9fe5aa70a1e74077b3977c363 to your computer and use it in GitHub Desktop.
Save chmouel/f001bed9fe5aa70a1e74077b3977c363 to your computer and use it in GitHub Desktop.
#!/usr/bin/env zsh
# using zsh cause quoting sucks on bash
AUTH_URL=http://auth-fabric8-build.devtools-dev.ext.devshift.net
ENV_URL=http://f8env-fabric8-build.devtools-dev.ext.devshift.net
TOKEN=$(curl -s -L ${AUTH_URL}/api/token/generate -H 'content-type: application/json' | jq -r '.[0].token.access_token')
SPACE_ID=$(uuidgen)
function createENV() {
local name=$1
local namespaceName=$2
local type=$3
local clusterURL=$4
local JSON=$(printf '{
"data": {
"attributes": {
"cluster-url": "%s",
"name": "%s",
"namespaceName": "%s",
"type": "%s"
},
"type": "environments"
}
}' "${clusterURL}" "${name}" "${namespaceName}" "${type}")
curl -sLH "Authorization: Bearer ${TOKEN}" \
${ENV_URL}/api/spaces/${SPACE_ID}/environments -d ${JSON} | jq -r '.data.id'
}
STAGE_ID=$(createENV "stage" "build-stage" "stage" "http://cluster1")
PROD_ID=$(createENV "prod" "build-prod" "prod" "http://cluster2")
curl -sLH "Authorization: Bearer ${TOKEN}" \
${ENV_URL}/api/environments/${STAGE_ID} >&2
curl -sLH "Authorization: Bearer ${TOKEN}" \
${ENV_URL}/api/environments/${PROD_ID} >&2
echo STAGE_ID=${STAGE_ID}
echo PROD_ID=${PROD_ID}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment