File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ set -euo pipefail
3+
4+ INPUT=$( cat)
5+ REGION=$( echo " $INPUT " | jq -r ' .REGION' )
6+ RESOURCE_GROUP_ID=$( echo " $INPUT " | jq -r ' .RESOURCE_GROUP_ID' )
7+ IBMCLOUD_API_KEY=$( echo " $INPUT " | jq -r ' .IBMCLOUD_API_KEY' )
8+ export IBMCLOUD_API_KEY
9+
10+ if [[ -z " ${IBMCLOUD_API_KEY} " || " ${IBMCLOUD_API_KEY} " == " null" ]]; then
11+ echo ' {"error": "IBMCLOUD_API_KEY is required"}'
12+ exit 0
13+ fi
14+
15+ if [[ -z " ${RESOURCE_GROUP_ID} " || " ${RESOURCE_GROUP_ID} " == " null" ]]; then
16+ echo ' {"error": "RESOURCE_GROUP_ID is required"}'
17+ exit 0
18+ fi
19+
20+ if [[ -z " ${REGION} " || " ${REGION} " == " null" ]]; then
21+ echo ' {"error": "REGION is required"}'
22+ exit 0
23+ fi
24+
25+ if ! ibmcloud login -r " ${REGION} " -g " ${RESOURCE_GROUP_ID} " --quiet > /dev/null 2>&1 ; then
26+ printf ' {"error": "Failed to login using: ibmcloud login -r %s -g %s"}' " $REGION " " $RESOURCE_GROUP_ID "
27+ exit 0
28+ fi
29+
30+ # extract registry value from text "You are targeting region 'us-south', the registry is 'us.icr.io'."
31+ registry=$( ibmcloud cr region 2> /dev/null | grep registry | sed -E " s/.*registry is '([^']+)'.*/\1/" )
32+
33+ # Validate registry value
34+ if [[ -z " $registry " ]]; then
35+ echo ' {"error": "Failed to parse registry region from ibmcloud cr region"}'
36+ exit 0
37+ fi
38+
39+ echo " {\" registry\" : \" ${registry} \" }"
You can’t perform that action at this time.
0 commit comments