Skip to content

Commit

Permalink
fix: don't fail the server if api key already in the secret manager (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
shahargl authored Sep 15, 2024
1 parent c83ec96 commit c9dc74a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions keep/api/core/db_on_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,17 @@ def try_create_single_tenant(tenant_id: str) -> None:
secret_manager = SecretManagerFactory.get_secret_manager(
context_manager
)
secret_manager.write_secret(
secret_name=f"{tenant_id}-{api_key_name}",
secret_value=api_key_secret,
)
try:
secret_manager.write_secret(
secret_name=f"{tenant_id}-{api_key_name}",
secret_value=api_key_secret,
)
# probably 409 if the secret already exists, but we don't want to fail on that
except Exception:
logger.exception(
f"Failed to write secret for api key {api_key_name}"
)
pass
logger.info(f"Api key {api_key_name} provisioned")
logger.info("Api keys provisioned")
# commit the changes
Expand All @@ -162,7 +169,7 @@ def migrate_db():
if os.environ.get("SKIP_DB_CREATION", "false") == "true":
logger.info("Skipping running migrations...")
return None

logger.info("Running migrations...")
config_path = os.path.dirname(os.path.abspath(__file__)) + "/../../" + "alembic.ini"
config = alembic.config.Config(file_=config_path)
Expand Down

0 comments on commit c9dc74a

Please sign in to comment.