-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-129754 / 24.10 / Update
api_key.py
to use the new API style (#1…
…3957) * api_key.do_create new api decorator * give update and delete new api decorator * type hints for easier integration * Finalize models, type hints * `privilege.py` still depends on `allowlist_item` schema * truthful type hints * remove unused imports * remove arbitrary class instance ability from `ApiKeyEntry` model * remove use of `NonEmptyString`
- Loading branch information
1 parent
5b61d3b
commit 4f3f403
Showing
5 changed files
with
96 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .api_key import * # noqa | ||
from .cloud_sync import * # noqa | ||
from .common import * # noqa | ||
from .user import * # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from datetime import datetime | ||
from typing import Literal, TypeAlias | ||
from typing_extensions import Annotated | ||
|
||
from pydantic import ConfigDict, StringConstraints | ||
|
||
from middlewared.api.base import BaseModel, Excluded, excluded_field, NonEmptyString, Private | ||
|
||
|
||
HttpVerb: TypeAlias = Literal["GET", "POST", "PUT", "DELETE", "CALL", "SUBSCRIBE", "*"] | ||
|
||
|
||
class AllowListItem(BaseModel): | ||
method: HttpVerb | ||
resource: NonEmptyString | ||
|
||
|
||
class ApiKeyEntry(BaseModel): | ||
"""Represents a record in the account.api_key table.""" | ||
|
||
id: int | ||
name: Annotated[NonEmptyString, StringConstraints(max_length=200)] | ||
key: Private[str] | ||
created_at: datetime | ||
allowlist: list[AllowListItem] | ||
|
||
|
||
class ApiKeyCreate(ApiKeyEntry): | ||
id: Excluded = excluded_field() | ||
key: Excluded = excluded_field() | ||
created_at: Excluded = excluded_field() | ||
|
||
|
||
class ApiKeyCreateArgs(BaseModel): | ||
api_key_create: ApiKeyCreate | ||
|
||
|
||
class ApiKeyCreateResult(BaseModel): | ||
result: ApiKeyEntry | ||
|
||
|
||
class ApiKeyUpdate(ApiKeyCreate): | ||
reset: bool | ||
|
||
|
||
class ApiKeyUpdateArgs(BaseModel): | ||
id: int | ||
api_key_update: ApiKeyUpdate | ||
|
||
|
||
class ApiKeyUpdateResult(BaseModel): | ||
result: ApiKeyEntry | ||
|
||
|
||
class ApiKeyDeleteArgs(BaseModel): | ||
id: int | ||
|
||
|
||
class ApiKeyDeleteResult(BaseModel): | ||
result: Literal[True] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters