From bf6dd4edf25f690dab76bced4bcca5bc496f9710 Mon Sep 17 00:00:00 2001 From: Roy Osherove <575051+royosherove@users.noreply.github.com> Date: Sun, 3 May 2026 12:24:13 +0000 Subject: [PATCH] fix(rename): only strip 'Loki-' prefix when hyphen separator present #29 broadened _account_already_prefixed to match any 'loki*' name (case-insensitive) to cover names like 'LOKI-Foo', but the first-install SSM write path still blindly did ${current_name:5} to derive the stored /loki/original-account-name. For names like 'loki1-MyAccount' or 'LokiDev-SomeAccount' that produced corrupt values ('-MyAccount', 'ev-SomeAccount'). Only strip when the lowercase 5-char prefix is exactly 'loki-'; otherwise fall back to ACCOUNT_ID, matching the existing fallback for empty results. Addresses Codex P2 on PR #29 (post-merge follow-up). --- install.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index f99c62a..6e1f365 100755 --- a/install.sh +++ b/install.sh @@ -2766,11 +2766,17 @@ _account_already_prefixed() { display_name=$(printf '%s' "$current_name" | tr -d '\000-\037') ok "Account already named for Loki: $(printf '%s' "$display_name")" # Write SSM params if they don't exist yet (first install with pre-existing prefix). - # Note: stripped_original is a best-guess — if account was manually named - # "LOKI-Foo", we store "Foo" but the true pre-Loki original is unknown. + # Note: stripped_original is a best-guess — only strip when the name + # has a real "Loki-" / "loki-" separator. For freeform "loki*" matches + # (e.g. "LokiDev-Foo", "loki1-Bar") there is no reliable way to recover + # the pre-Loki name, so fall back to ACCOUNT_ID. if ! aws ssm get-parameter --name "/loki/original-account-name" \ --region "${DEPLOY_REGION:-$REGION}" --output text >/dev/null 2>&1; then - local stripped_original="${current_name:5}" # strip 5-char prefix (Loki-) + local stripped_original="" + local lower_prefix="${lower_name:0:5}" + if [[ "$lower_prefix" == "loki-" ]]; then + stripped_original="${current_name:5}" # strip exact 5-char "Loki-" prefix + fi [[ -n "$stripped_original" ]] || stripped_original="$ACCOUNT_ID" aws ssm put-parameter --name "/loki/original-account-name" \ --value "$stripped_original" --type String --overwrite \