mirror of
https://github.com/reconurge/flowsint.git
synced 2026-07-20 09:32:23 -05:00
28 lines
935 B
Python
28 lines
935 B
Python
from typing import Protocol, Optional
|
|
import uuid
|
|
from sqlalchemy.orm import Session
|
|
from sqlalchemy import select
|
|
from app.models.models import Key
|
|
|
|
class VaultProtocol(Protocol):
|
|
def get_secret(self, vault_ref: str) -> Optional[str]:
|
|
...
|
|
|
|
class Vault(VaultProtocol):
|
|
def __init__(self, db: Session, owner_id: uuid.UUID):
|
|
if not owner_id:
|
|
raise ValueError("owner_id is required to use the vault.")
|
|
self.db = db
|
|
self.owner_id = owner_id
|
|
|
|
def get_secret(self, vault_ref: str) -> Optional[str]:
|
|
try:
|
|
ref_uuid = uuid.UUID(vault_ref)
|
|
stmt = select(Key).where(Key.id == ref_uuid)
|
|
except ValueError:
|
|
stmt = select(Key).where(Key.name == vault_ref)
|
|
stmt = stmt.where(Key.owner_id == self.owner_id)
|
|
result = self.db.execute(stmt)
|
|
row = result.scalars().first()
|
|
return row.encrypted_key if row else None
|