onecli-sdk 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
onecli/types/_base.py ADDED
@@ -0,0 +1,42 @@
1
+ """The base of every model the SDK reads from or sends to the API."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, ClassVar
6
+
7
+ from pydantic import (
8
+ BaseModel,
9
+ ConfigDict,
10
+ ValidationError,
11
+ ValidatorFunctionWrapHandler,
12
+ WrapValidator,
13
+ )
14
+
15
+ __all__ = ["Model", "OpenEnum"]
16
+
17
+
18
+ class Model(BaseModel):
19
+ """A shape of the OneCLI API.
20
+
21
+ Attributes have Python names (``vault_id``); ``model_dump(by_alias=True)``
22
+ gives the API's own names (``vaultId``). A field the SDK does not know yet
23
+ is kept: read it with ``model_extra``.
24
+ """
25
+
26
+ model_config: ClassVar[ConfigDict] = ConfigDict(
27
+ extra="allow", validate_by_name=True, validate_by_alias=True
28
+ )
29
+
30
+
31
+ def _open_enum(value: Any, handler: ValidatorFunctionWrapHandler) -> Any: # noqa: ANN401
32
+ """Keep a text value the enum does not list: a newer server may send one."""
33
+ try:
34
+ return handler(value)
35
+ except ValidationError:
36
+ if isinstance(value, str):
37
+ return value
38
+ raise
39
+
40
+
41
+ OpenEnum = WrapValidator(_open_enum)
42
+ """Read an enum open: a value it does not list is kept as text, never refused."""