validate unsandbox keys on save, reject invalid/expired

This commit is contained in:
russell@unturf.com 2026-02-18 06:01:11 -05:00
parent be40ab432b
commit c8b9dd310a

View file

@ -793,15 +793,23 @@ def shop_settings(request):
else:
request.session.flash(("Unsandbox secret key must start with 'unsb-sk-'.", "error"))
# Backfill existing catalog when both keys are now present
# Validate keys against unsandbox API and backfill if valid
if keys_changed and shop.unsandbox_public_key and shop.unsandbox_secret_key:
from ..lib.karaoke import backfill_karaoke_async
backfill_karaoke_async(
shop.id,
request.registry["dbsession_factory"],
request.app,
)
request.session.flash(("Backfilling vocal isolation for existing catalog in background.", "success"))
from ..lib.un import validate_keys
try:
validate_keys(shop.unsandbox_public_key, shop.unsandbox_secret_key)
except Exception as e:
shop.unsandbox_public_key = None
shop.unsandbox_secret_key = None
request.session.flash((f"Unsandbox API keys are invalid or expired: {e}", "error"))
else:
from ..lib.karaoke import backfill_karaoke_async
backfill_karaoke_async(
shop.id,
request.registry["dbsession_factory"],
request.app,
)
request.session.flash(("Backfilling vocal isolation for existing catalog in background.", "success"))
# Handle maintenance settings form
if form_section == "maintenance-settings":