Fix leading-whitespace bug in garage key create output parsing

Garage's real CLI output pads labels with extra spaces for column
alignment ("Key ID:              GKxxxx"), not a single space like the
mocked test used ("Key ID: GKxxxx") — the fixed ": " field separator left
that padding stuck to the parsed value, so .env ended up with access
key/secret strings carrying leading whitespace inside the quotes.
Confirmed live by the user right after install. This would have broken S3
auth outright once actually used, since access keys have to match exactly.

Switched to ':[[:space:]]+' as a regex field separator, which consumes
however many spaces are actually there instead of assuming exactly one.
Verified against both the single-space and padded/aligned formats — both
now produce the identical clean value with no leading whitespace.
This commit is contained in:
Claude
2026-08-15 12:25:08 +00:00
parent 129a97f34b
commit 01ca0a7b09
+9 -2
View File
@@ -277,8 +277,15 @@ ENV
local _key_out
_key_out="$(docker exec garage /garage key create "$KEY_NAME" 2>&1)"
local ACCESS_KEY_ID ACCESS_KEY_SECRET
ACCESS_KEY_ID="$(echo "$_key_out" | awk -F': ' '/^Key ID:/{print $2}')"
ACCESS_KEY_SECRET="$(echo "$_key_out" | awk -F': ' '/^Secret key:/{print $2}')"
# Garage's real CLI output pads labels with extra spaces for column
# alignment (e.g. "Key ID: GKxxxx", not just "Key ID: GKxxxx")
# — a fixed ": " separator leaves that padding stuck to the value.
# ':[[:space:]]+' as a regex field separator consumes ALL of it,
# however many spaces there actually are. Confirmed live: the fixed
# single-space version left leading spaces baked into .env, which
# would have broken S3 auth (access keys have to match exactly).
ACCESS_KEY_ID="$(echo "$_key_out" | awk -F':[[:space:]]+' '/^Key ID:/{print $2}')"
ACCESS_KEY_SECRET="$(echo "$_key_out" | awk -F':[[:space:]]+' '/^Secret key:/{print $2}')"
if [ -z "$ACCESS_KEY_ID" ] || [ -z "$ACCESS_KEY_SECRET" ]; then
log_error "Couldn't parse the access key from 'garage key create' output:"