Repository navigation
feat: GSM Secrets - Keep new secrets in an optional store #474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
64f54dd
f5c64e0
18a021a
dbeb0eb
ca09d2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import dataclasses | ||
| import datetime | ||
| from typing import Any, Protocol | ||
|
|
||
|
|
||
| @dataclasses.dataclass(frozen=True, kw_only=True) | ||
| class StoredSecret: | ||
| """A secret as a `SecretStore` keeps it; `value` is None when not loaded, and never shown by repr, str or logs.""" | ||
|
|
||
| user_id: str | ||
| secret_name: str | ||
| value: str | None = dataclasses.field(default=None, repr=False) | ||
| description: str | None = None | ||
| created_at: datetime.datetime | ||
| updated_at: datetime.datetime | ||
| extra_data: dict[str, Any] | None = None | ||
|
|
||
|
|
||
| class SecretStore(Protocol): | ||
| """Keeps secrets outside the database, for example in a cloud secret manager. | ||
|
|
||
| With a store, new secrets go to the store; a secret still in the `secret` table stays there until moved. | ||
| """ | ||
|
|
||
| def create(self, *, secret: StoredSecret) -> StoredSecret: | ||
| """Saves a new secret and returns it without its value; raises `errors.ItemAlreadyExistsError` if it exists.""" | ||
| ... | ||
|
|
||
|
|
||
| def update(self, *, secret: StoredSecret) -> StoredSecret: | ||
| """Saves a new value for an existing secret and returns it without its value. | ||
|
|
||
| Keeps the stored `created_at` and name, and the stored description when `description` is None. | ||
| Raises `errors.ItemNotFoundError` when there is no such secret. | ||
| """ | ||
| ... | ||
|
|
||
|
|
||
| def get(self, *, user_id: str, secret_name: str) -> str | None: | ||
| """Returns the secret's latest value, or None when there is no such secret.""" | ||
| ... | ||
|
|
||
|
|
||
| def list_secrets(self, *, user_id: str) -> list[StoredSecret]: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Naming consistency: This is the only method with |
||
| """Returns the user's secrets, without values.""" | ||
| ... | ||
|
|
||
|
|
||
| def delete(self, *, user_id: str, secret_name: str) -> None: | ||
| """Deletes the secret and all its values; raises `errors.ItemNotFoundError` when there is none.""" | ||
| ... | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe,
secret_interfaces.py? I already see problematic cases in the code:secret_store: secret_store.SecretStore