From d2e9011fd2133a84b249313f98cb0d752ef25c40 Mon Sep 17 00:00:00 2001 From: Alan Bishop Date: Mon, 17 Feb 2020 17:23:14 -0800 Subject: [PATCH] Improve upload-swift-artifacts handling of json data The "openstack container show" output changed, and the value of the properties field is json (meaning that specifying "-f value" doesn't eliminate the json formatting). This patch replaces sed to parse the output with a jq expression that knows how to handle json. Misc notes: - Using "jq -r" tells jq not to quote the value of the Temp-URL-Key - In the jq expression, "Temp-URL-Key" must be quoted or else the jq parser stumbles on the '-' dashes Change-Id: Ife347f754ca9129580c092bb271bacdc032ae14b (cherry picked from commit c97180ce00e91673990311276c8dcb59af379a1f) --- scripts/upload-swift-artifacts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/upload-swift-artifacts b/scripts/upload-swift-artifacts index 17ed768de..065193736 100755 --- a/scripts/upload-swift-artifacts +++ b/scripts/upload-swift-artifacts @@ -127,14 +127,13 @@ if [ -z "$SWIFT_INTERNAL_URL" ]; then fi # Does the Temp-URL-Key exist on this container? +# jq will output "null" if it doesn't # If not set it... -KEY_SET=$(openstack container show $CONTAINER_NAME -c properties -f value 2>/dev/null | tr ',' '\n' | grep Temp-Url-Key || true) -if [ -z $KEY_SET ]; then +SWIFT_TEMP_URL_KEY=$(openstack container show $CONTAINER_NAME -f json 2>/dev/null | jq -r '.properties."Temp-URL-Key"' || true) +if [ "$SWIFT_TEMP_URL_KEY" != "null" ]; then echo "Creating new Swift Temp-URL-Key for container: $CONTAINER_NAME" SWIFT_TEMP_URL_KEY=$(uuidgen | sha1sum | awk '{print $1}') openstack container set --property "Temp-URL-Key=$SWIFT_TEMP_URL_KEY" "${CONTAINER_NAME}" -else - SWIFT_TEMP_URL_KEY=$(echo -n $KEY_SET | sed -rn "s/[[:space:]]*Temp-Url-Key='([[:alnum:]]+)'.*/\1/p") fi if [ -n "${ENVIRONMENT_FILE:-}" ]; then