← back to Secrets Manager

alias-content-token.py

31 lines

#!/usr/bin/env python3
"""
alias-content-token.py — give the DW content-capable Shopify token a name that
reflects its REAL scope. The token currently stored as SHOPIFY_DRAFT_TOKEN (…a43b,
DW-Write-Content app) actually carries read_content + write_content, so a future
session shouldn't have to probe to rediscover that.

Adds SHOPIFY_CONTENT_TOKEN = (same value) to the canonical .env with a scope comment,
keeping SHOPIFY_DRAFT_TOKEN intact for backward-compat. Then run `node cli.js sync`
to fan the new key out to the registered destinations.
Run:  ! python3 ~/Projects/secrets-manager/alias-content-token.py
"""
import re
ENV = "/Users/macstudio3/Projects/secrets-manager/.env"
env = open(ENV).read()

m = re.search(r'^SHOPIFY_DRAFT_TOKEN=(.+)$', env, re.M)
if not m:
    print("SHOPIFY_DRAFT_TOKEN not found — nothing to alias"); raise SystemExit(1)
val = m.group(1).strip()

if re.search(r'^SHOPIFY_CONTENT_TOKEN=', env, re.M):
    print("SHOPIFY_CONTENT_TOKEN already exists — no change")
else:
    with open(ENV, "a") as f:
        f.write(f"\n# DW-Write-Content app (…{val.strip(chr(34)+chr(39))[-4:]}); "
                f"products + read_content/write_content. Alias of SHOPIFY_DRAFT_TOKEN.\n")
        f.write(f"SHOPIFY_CONTENT_TOKEN={val}\n")
    print(f"added SHOPIFY_CONTENT_TOKEN (…{val.strip(chr(34)+chr(39))[-4:]}) to canonical .env")
print("next: run  node ~/Projects/secrets-manager/cli.js sync   to fan out to registered .env/MCP dests")