Skip to content

Commit

Permalink
Trim spaces around API key in install script (#192)
Browse files Browse the repository at this point in the history
Signed-off-by: John Starich <[email protected]>
  • Loading branch information
JohnStarich authored Sep 2, 2020
1 parent 2b9afb2 commit 2db01a6
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions hack/configure-operator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@
#

#
# install-operator.sh [ACTION]
# configure-operator.sh
#
# This script installs the IBM Cloud Operator from the latest release.
# By default, this script installs the IBM Cloud Operator from the latest release.
# It attempts to pick up as much as it can from the 'ibmcloud' CLI target context when configuring the operator.
# If an API key is not provided, one is generated.
#
# For full usage information, run with the -h flag provided.

# Exit if any statement has a non-zero exit code
set -e
# Fail a pipe if any of the commands fail
set -o pipefail
# Enable advanced pattern matching. Used in trim()
shopt -s extglob

TMPDIR=$(mktemp -d)
trap "set -x; rm -rf '$TMPDIR'" EXIT
Expand All @@ -53,6 +56,17 @@ Usage: $(basename "$0") [-h] [-v VERSION] [ACTION]
EOT
}

# trim trims whitespace characters from both ends of the passed args. If no args, uses stdin.
trim() {
local s="$*"
if [[ -z "$s" ]]; then
s=$(cat -) # if no args, read from stdin
fi
s="${s##*( )}"
s="${s%%*( )}"
printf '%s' "$s"
}

# json_grep assumes stdin is an indented JSON blob, then looks for a matching JSON key for $1.
# The value must be a string type.
#
Expand Down Expand Up @@ -149,6 +163,7 @@ store_creds() {
local key_output=$(ibmcloud iam api-key-create ibmcloud-operator-key -d "Key for IBM Cloud Operator" --output json)
IBMCLOUD_API_KEY=$(json_grep apikey <<<"$key_output")
fi
IBMCLOUD_API_KEY=$(trim "$IBMCLOUD_API_KEY")
local target=$(ibmcloud target --output json)
local region=$(json_grep_after region name <<<"$target")
if [[ -z "$region" ]]; then
Expand Down

0 comments on commit 2db01a6

Please sign in to comment.