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 c97180ce00)
This commit is contained in:
Alan Bishop 2020-02-17 17:23:14 -08:00
parent 6266ccbfc2
commit d2e9011fd2
1 changed files with 3 additions and 4 deletions

View File

@ -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