@@ -30,7 +30,7 @@ DEFAULT_GIT_SOURCE_NAME="default-git-source"
3030
3131# Params:
3232check_required_param " namespace" " ${NAMESPACE} "
33- check_required_param " csdp token" " ${CSDP_TOKEN } "
33+ check_required_param " csdp runtime token" " ${CSDP_RUNTIME_TOKEN } "
3434check_required_param " runtime repo" " ${CSDP_RUNTIME_REPO} "
3535check_required_param " git token" " ${CSDP_RUNTIME_GIT_TOKEN} "
3636check_required_param " runtime cluster" " ${CSDP_RUNTIME_CLUSTER} "
@@ -66,38 +66,41 @@ create_codefresh_secret() {
6666 COMPONENTS=` echo $COMPONENTS | tr ' ' ' ,' `
6767 COMPONENTS=" [${COMPONENTS} ]"
6868
69- RUNTIME_CREATE_ARGS=" {
70- \" repo\" : \" ${CSDP_RUNTIME_REPO} \" ,
71- \" runtimeName\" :\" ${CSDP_RUNTIME_NAME} \" ,
72- \" cluster\" :\" ${CSDP_RUNTIME_CLUSTER} \" ,
73- \" ingressHost\" :\" ${CSDP_RUNTIME_INGRESS_URL} \" ,
74- \" ingressClass\" :\" ${CSDP_INGRESS_CLASS_NAME} \" ,
75- \" ingressController\" :\" ${CSDP_INGRESS_CONTROLLER} \" ,
76- \" componentNames\" :${COMPONENTS} ,
77- \" runtimeVersion\" :\" v0.0.0\" ,
78- \" managed\" :${CSDP_MANAGED_RUNTIME}
79- }"
80-
81- RUNTIME_CREATE_DATA=" {\" operationName\" :\" CreateRuntime\" ,\" variables\" :{\" args\" :$RUNTIME_CREATE_ARGS }"
82- RUNTIME_CREATE_DATA+=$' ,"query":"mutation CreateRuntime($args: RuntimeInstallationArgs\u0021) {\\ n createRuntime(installationArgs: $args) {\\ n name\\ n newAccessToken\\ n }\\ n}\\ n"}'
83- echo " --> Creating runtime with args:"
84- echo " $RUNTIME_CREATE_ARGS "
85-
86- RUNTIME_CREATE_RESPONSE=` curl " ${CSDP_URL} /2.0/api/graphql" \
87- -SsfL \
88- -H " Authorization: ${CSDP_TOKEN} " \
89- -H ' content-type: application/json' \
90- --compressed \
91- --insecure \
92- --data-raw " $RUNTIME_CREATE_DATA " `
69+ if [ -z " $CSDP_RUNTIME_TOKEN " ] ; then
70+ RUNTIME_CREATE_ARGS=" {
71+ \" repo\" : \" ${CSDP_RUNTIME_REPO} \" ,
72+ \" runtimeName\" :\" ${CSDP_RUNTIME_NAME} \" ,
73+ \" cluster\" :\" ${CSDP_RUNTIME_CLUSTER} \" ,
74+ \" ingressHost\" :\" ${CSDP_RUNTIME_INGRESS_URL} \" ,
75+ \" ingressClass\" :\" ${CSDP_INGRESS_CLASS_NAME} \" ,
76+ \" ingressController\" :\" ${CSDP_INGRESS_CONTROLLER} \" ,
77+ \" componentNames\" :${COMPONENTS} ,
78+ \" runtimeVersion\" :\" v0.0.0\" ,
79+ \" managed\" :${CSDP_MANAGED_RUNTIME}
80+ }"
81+
82+ RUNTIME_CREATE_DATA=" {\" operationName\" :\" CreateRuntime\" ,\" variables\" :{\" args\" :$RUNTIME_CREATE_ARGS }"
83+ RUNTIME_CREATE_DATA+=$' ,"query":"mutation CreateRuntime($args: RuntimeInstallationArgs\u0021) {\\ n createRuntime(installationArgs: $args) {\\ n name\\ n newAccessToken\\ n }\\ n}\\ n"}'
84+ echo " --> Creating runtime with args:"
85+ echo " $RUNTIME_CREATE_ARGS "
86+
87+ RUNTIME_CREATE_RESPONSE=` curl " ${CSDP_URL} /2.0/api/graphql" \
88+ -SsfL \
89+ -H " Authorization: ${CSDP_TOKEN} " \
90+ -H ' content-type: application/json' \
91+ --compressed \
92+ --insecure \
93+ --data-raw " $RUNTIME_CREATE_DATA " `
94+
95+ if ` echo " $RUNTIME_CREATE_RESPONSE " | jq -e ' has("errors")' ` ; then
96+ echo " Failed to create runtime"
97+ echo ${RUNTIME_CREATE_RESPONSE}
98+ exit 1
99+ fi
93100
94- if ` echo " $RUNTIME_CREATE_RESPONSE " | jq -e ' has("errors")' ` ; then
95- echo " Failed to create runtime"
96- echo ${RUNTIME_CREATE_RESPONSE}
97- exit 1
101+ CSDP_RUNTIME_TOKEN=` echo $RUNTIME_CREATE_RESPONSE | jq ' .data.createRuntime.newAccessToken' `
98102 fi
99103
100- RUNTIME_ACCESS_TOKEN=` echo $RUNTIME_CREATE_RESPONSE | jq ' .data.createRuntime.newAccessToken' `
101104 RUNTIME_ENCRYPTION_IV=` hexdump -n 16 -e ' 4/4 "%08x" 1 "\n"' /dev/urandom`
102105 echo " --> Runtime created!"
103106 echo " "
@@ -110,7 +113,7 @@ create_codefresh_secret() {
110113 name: $CODEFRESH_SECRET_NAME
111114 namespace: $NAMESPACE
112115 stringData:
113- token: $RUNTIME_ACCESS_TOKEN
116+ token: $CSDP_RUNTIME_TOKEN
114117 encryptionIV: $RUNTIME_ENCRYPTION_IV
115118 " | kubectl apply -f -
116119
0 commit comments