Files
CIAgent/apps/api/app/repositories/system_secret_repository.py
T
saksham 1a4c80958f Initial commit: CI Agent competitive-intelligence monitoring app
FastAPI + Celery + Next.js + Postgres/Redis app with company monitoring,
source collection, LLM-based change analysis, enrichment, and account
security (Turnstile, escalating lockout, email verification).
2026-08-05 10:48:20 -04:00

38 lines
1.3 KiB
Python

from __future__ import annotations
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from app.models.enums import SystemSecretKey
from app.models.system_secret import SystemSecret
class SystemSecretRepository:
def __init__(self, db: AsyncSession) -> None:
self.db = db
async def list_all(self) -> list[SystemSecret]:
result = await self.db.execute(select(SystemSecret))
return list(result.scalars().all())
async def get(self, key: SystemSecretKey) -> SystemSecret | None:
result = await self.db.execute(select(SystemSecret).where(SystemSecret.key == key))
return result.scalar_one_or_none()
async def upsert(self, key: SystemSecretKey, encrypted_value: str) -> SystemSecret:
existing = await self.get(key)
if existing is not None:
existing.encrypted_value = encrypted_value
await self.db.flush()
return existing
record = SystemSecret(key=key, encrypted_value=encrypted_value)
self.db.add(record)
await self.db.flush()
return record
async def delete(self, key: SystemSecretKey) -> None:
existing = await self.get(key)
if existing is not None:
await self.db.delete(existing)
await self.db.flush()