Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim spaces around API key in install script #192

Merged
merged 2 commits into from
Sep 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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