secrets (backward-compatible secrets endpoint export)
What it is
- A compatibility shim module that re-exports the FastAPI secrets router and related schema types.
- Provides thin wrapper functions around secrets crypto/utilities and an async helper to resolve a secret value via the secrets service backed by Postgres.
Public API
Re-exports
router: FastAPI router for secrets endpoints (imported from the primary FastAPI adapter).SecretCreate: request model/schema for creating a secret.SecretUpdate: request model/schema for updating a secret.SecretResponse: response model/schema for secret operations.SecretBulkImport: request model/schema for bulk import.
Functions
deprecated_encrypt(value: str) -> str- Encrypts a plaintext secret value using
encrypt_secret_value.
- Encrypts a plaintext secret value using
_encrypt(value: str) -> str- Backward-compatible alias for
deprecated_encrypt.
- Backward-compatible alias for
_decrypt(encrypted_value: str) -> str- Decrypts an encrypted secret value using
decrypt_secret_value.
- Decrypts an encrypted secret value using
_try_decrypt(encrypted_value: str) -> str | None- Attempts to decrypt using
try_decrypt_secret_value; returnsNoneon failure.
- Attempts to decrypt using
_mask_value(value: str) -> str- Masks a secret value using
mask_secret_value.
- Masks a secret value using
_infer_category(key: str) -> str- Infers a secret category from a key using
infer_secret_category.
- Infers a secret category from a key using
resolve_secret_async(db: AsyncSession, workspace_id: str, key: str) -> str | None- Resolves (fetches and decrypts as needed) a secret value for a workspace/key using:
SecretsServiceSecretsSecondaryAdapterPostgres(db=db)- A system
RequestContextwithTokenData(user_id="system", scopes={"*"}, is_authenticated=True)
- Resolves (fetches and decrypts as needed) a secret value for a workspace/key using:
Configuration/Dependencies
- Requires an SQLAlchemy async database session:
sqlalchemy.ext.asyncio.AsyncSession
- Depends on internal services/adapters:
SecretsServiceSecretsSecondaryAdapterPostgres- IAM context models:
RequestContext,TokenData
- Crypto/utilities:
encrypt_secret_value,decrypt_secret_value,try_decrypt_secret_valuemask_secret_value,infer_secret_category
Usage
Include the router in a FastAPI app
from fastapi import FastAPI
from naas_abi.apps.nexus.apps.api.app.api.endpoints import secrets
app = FastAPI()
app.include_router(secrets.router)
Resolve a secret value (async)
from sqlalchemy.ext.asyncio import AsyncSession
from naas_abi.apps.nexus.apps.api.app.api.endpoints.secrets import resolve_secret_async
async def get_api_key(db: AsyncSession, workspace_id: str) -> str | None:
return await resolve_secret_async(db, workspace_id=workspace_id, key="API_KEY")
Caveats
resolve_secret_asyncuses a hardcoded system context (user_id="system", scopes{"*"}); authorization behavior is delegated to the underlying service.- This module is explicitly “backward-compatible”; functions like
_encrypt/deprecated_encryptare aliases rather than new implementations.