NaasSecret
What it is
- A secondary
ISecretAdapterimplementation that manages secrets via the Naas API (https://api.naas.aiby default). - Uses
requeststoGET/POST/DELETEsecrets and logs errors vianaas_abi_core.logger.
Public API
class NaasSecret(ISecretAdapter)__init__(naas_api_key: str, naas_api_url: str | None = None)- Creates an adapter using the provided API key and optional base URL.
get(key: str, default: Any = None) -> str | Any | None- Fetches a secret value by name.
- Returns the secret value as
stron success; returnsdefaulton non-auth errors/404. - Raises
SecretAuthenticationErroron HTTP 401.
set(key: str, value: str) -> None- Creates/updates a secret.
- Logs an error and returns on HTTP error.
remove(key: str) -> None- Deletes a secret by name.
- Logs an error and returns on HTTP error.
list() -> Dict[str, str | None]- Lists secrets (name → value) from the API.
- Returns
{}on HTTP error (with specific debug log on 404).
Configuration/Dependencies
- Requires:
requestsnaas_abi_core.loggernaas_abi_core.services.secret.SecretPorts:ISecretAdapterSecretAuthenticationError
- Configuration:
naas_api_key(required): used asAuthorization: Bearer <key>.naas_api_url(optional): defaults tohttps://api.naas.ai.
Usage
from naas_abi_core.services.secret.adaptors.secondary.NaasSecret import NaasSecret
adapter = NaasSecret(naas_api_key="YOUR_NAAS_API_KEY")
adapter.set("MY_SECRET", "hello")
value = adapter.get("MY_SECRET", default=None)
print(value)
print(adapter.list())
adapter.remove("MY_SECRET")
Caveats
get()returnsdefaultfor missing secrets (404) and most other HTTP errors, but raisesSecretAuthenticationErrorfor 401 responses.list()sends pagination parameters in the JSON body of aGETrequest (as implemented), and returns{}on errors.- All returned secret values are coerced to
str.