From 7b77c1ba0185dc5cbf292dd99e00735d0cd73b8d Mon Sep 17 00:00:00 2001 From: John Starich Date: Tue, 1 Sep 2020 20:05:02 -0500 Subject: [PATCH 1/2] Update install docs Signed-off-by: John Starich --- hack/configure-operator.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hack/configure-operator.sh b/hack/configure-operator.sh index e3bb3f23..bd6590ce 100755 --- a/hack/configure-operator.sh +++ b/hack/configure-operator.sh @@ -16,12 +16,13 @@ # # -# 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 From 68643454790b63ec8e68df30a6a9cae8cd69dc7c Mon Sep 17 00:00:00 2001 From: John Starich Date: Tue, 1 Sep 2020 20:37:47 -0500 Subject: [PATCH 2/2] Trim spaces around API key env var Signed-off-by: John Starich --- hack/configure-operator.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hack/configure-operator.sh b/hack/configure-operator.sh index bd6590ce..640cac60 100755 --- a/hack/configure-operator.sh +++ b/hack/configure-operator.sh @@ -28,6 +28,8 @@ 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 @@ -54,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. # @@ -150,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