mreg-cli 1.0.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.
Files changed (53) hide show
  1. mreg_cli/__about__.py +7 -0
  2. mreg_cli/__init__.py +5 -0
  3. mreg_cli/__main__.py +8 -0
  4. mreg_cli/_version.py +16 -0
  5. mreg_cli/api/__init__.py +7 -0
  6. mreg_cli/api/abstracts.py +486 -0
  7. mreg_cli/api/endpoints.py +130 -0
  8. mreg_cli/api/fields.py +104 -0
  9. mreg_cli/api/history.py +152 -0
  10. mreg_cli/api/models.py +3416 -0
  11. mreg_cli/cli.py +382 -0
  12. mreg_cli/commands/__init__.py +1 -0
  13. mreg_cli/commands/base.py +62 -0
  14. mreg_cli/commands/dhcp.py +136 -0
  15. mreg_cli/commands/group.py +326 -0
  16. mreg_cli/commands/help.py +77 -0
  17. mreg_cli/commands/host.py +54 -0
  18. mreg_cli/commands/host_submodules/__init__.py +28 -0
  19. mreg_cli/commands/host_submodules/a_aaaa.py +452 -0
  20. mreg_cli/commands/host_submodules/bacnet.py +126 -0
  21. mreg_cli/commands/host_submodules/cname.py +166 -0
  22. mreg_cli/commands/host_submodules/core.py +507 -0
  23. mreg_cli/commands/host_submodules/rr.py +973 -0
  24. mreg_cli/commands/label.py +146 -0
  25. mreg_cli/commands/logging.py +112 -0
  26. mreg_cli/commands/network.py +516 -0
  27. mreg_cli/commands/permission.py +202 -0
  28. mreg_cli/commands/policy.py +519 -0
  29. mreg_cli/commands/recording.py +59 -0
  30. mreg_cli/commands/registry.py +56 -0
  31. mreg_cli/commands/root.py +58 -0
  32. mreg_cli/commands/zone.py +288 -0
  33. mreg_cli/config.py +253 -0
  34. mreg_cli/errorbuilder.py +193 -0
  35. mreg_cli/exceptions.py +237 -0
  36. mreg_cli/help_formatter.py +38 -0
  37. mreg_cli/main.py +238 -0
  38. mreg_cli/outputmanager.py +466 -0
  39. mreg_cli/py.typed +0 -0
  40. mreg_cli/tags.txt +55 -0
  41. mreg_cli/tokenfile.py +89 -0
  42. mreg_cli/types.py +160 -0
  43. mreg_cli/utilities/__init__.py +5 -0
  44. mreg_cli/utilities/api.py +595 -0
  45. mreg_cli/utilities/shared.py +65 -0
  46. mreg_cli/utilities/validators.py +19 -0
  47. mreg_cli-1.0.0.dist-info/AUTHORS +12 -0
  48. mreg_cli-1.0.0.dist-info/LICENSE +674 -0
  49. mreg_cli-1.0.0.dist-info/METADATA +1079 -0
  50. mreg_cli-1.0.0.dist-info/RECORD +53 -0
  51. mreg_cli-1.0.0.dist-info/WHEEL +5 -0
  52. mreg_cli-1.0.0.dist-info/entry_points.txt +2 -0
  53. mreg_cli-1.0.0.dist-info/top_level.txt +1 -0
mreg_cli/types.py ADDED
@@ -0,0 +1,160 @@
1
+ """Typing definitions for mreg_cli."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import ipaddress
7
+ from collections.abc import Callable
8
+ from enum import StrEnum
9
+ from typing import (
10
+ Annotated,
11
+ Any,
12
+ Literal,
13
+ Mapping,
14
+ MutableMapping,
15
+ NamedTuple,
16
+ Sequence,
17
+ TypeAlias,
18
+ TypedDict,
19
+ TypeVar,
20
+ Union,
21
+ )
22
+
23
+ from pydantic import (
24
+ ValidationError,
25
+ ValidationInfo,
26
+ ValidatorFunctionWrapHandler,
27
+ WrapValidator,
28
+ )
29
+ from pydantic_core import PydanticCustomError
30
+ from typing_extensions import TypeAliasType
31
+
32
+ CommandFunc = Callable[[argparse.Namespace], None]
33
+
34
+
35
+ class TimeInfo(TypedDict):
36
+ """Type definition for time-related information in the recording entry."""
37
+
38
+ timestamp: str
39
+ timestamp_as_epoch: int
40
+ runtime_in_ms: int
41
+
42
+
43
+ class RecordingEntry(TypedDict):
44
+ """Type definition for a recording entry."""
45
+
46
+ command: str
47
+ command_filter: str | None
48
+ command_filter_negate: bool
49
+ command_issued: str
50
+ ok: list[str]
51
+ warning: list[str]
52
+ error: list[str]
53
+ output: list[str]
54
+ api_requests: list[dict[str, Any]]
55
+ time: TimeInfo | None
56
+
57
+
58
+ IP_Version: TypeAlias = Literal[4, 6]
59
+ IP_AddressT = ipaddress.IPv4Address | ipaddress.IPv6Address
60
+ IP_NetworkT = ipaddress.IPv4Network | ipaddress.IPv6Network
61
+
62
+ IP_networkTV = TypeVar("IP_networkTV", ipaddress.IPv4Network, ipaddress.IPv6Network)
63
+
64
+
65
+ # https://github.com/python/typeshed/blob/16933b838eef7be92ee02f66b87aa1a7532cee63/stdlib/argparse.pyi#L40-L43
66
+ NargsStr = Literal["?", "*", "+", "...", "A...", "==SUPPRESS=="]
67
+ NargsType = int | NargsStr
68
+
69
+
70
+ # Source: https://docs.pydantic.dev/2.7/concepts/types/#named-recursive-types
71
+ def json_custom_error_validator(
72
+ value: Any, handler: ValidatorFunctionWrapHandler, _info: ValidationInfo
73
+ ) -> Any:
74
+ """Simplify the error message to avoid a gross error stemming from
75
+ exhaustive checking of all union options.
76
+ """ # noqa: D205
77
+ try:
78
+ return handler(value)
79
+ except ValidationError:
80
+ raise PydanticCustomError(
81
+ "invalid_json",
82
+ "Input is not valid json",
83
+ ) from None
84
+
85
+
86
+ Json = TypeAliasType(
87
+ "Json",
88
+ Annotated[
89
+ Union[Mapping[str, "Json"], Sequence["Json"], str, int, float, bool, None],
90
+ WrapValidator(json_custom_error_validator),
91
+ ],
92
+ )
93
+ JsonMapping = Mapping[str, Json]
94
+ QueryParams = MutableMapping[str, str | int | None]
95
+
96
+
97
+ class Flag:
98
+ """Class for flag information available to commands in the CLI."""
99
+
100
+ def __init__(
101
+ self,
102
+ name: str,
103
+ description: str = "",
104
+ short_desc: str = "",
105
+ nargs: NargsType | None = None,
106
+ default: Any = None,
107
+ flag_type: Any = None,
108
+ choices: Sequence[str] | None = None,
109
+ required: bool = False,
110
+ metavar: str | None = None,
111
+ action: str | None = None,
112
+ ):
113
+ """Initialize a Flag object."""
114
+ self.name = name
115
+ self.short_desc = short_desc
116
+ self.description = description
117
+ self.nargs = nargs
118
+ self.default = default
119
+ self.type = flag_type
120
+ self.choices = choices
121
+ self.required = required
122
+ self.metavar = metavar
123
+ self.action = action
124
+
125
+
126
+ class Command(NamedTuple):
127
+ """A command that can be registered with the CLI."""
128
+
129
+ prog: str
130
+ description: str
131
+ short_desc: str
132
+ callback: CommandFunc
133
+ flags: list[Flag] | None = None
134
+
135
+
136
+ # Config
137
+ DefaultType = TypeVar("DefaultType")
138
+
139
+
140
+ class LogLevel(StrEnum):
141
+ """Enum for log levels."""
142
+
143
+ DEBUG = "DEBUG"
144
+ INFO = "INFO"
145
+ WARNING = "WARNING"
146
+ ERROR = "ERROR"
147
+ CRITICAL = "CRITICAL"
148
+
149
+ @classmethod
150
+ def _missing_(cls, value: Any) -> LogLevel:
151
+ """Case-insensitive lookup when normal lookup fails."""
152
+ try:
153
+ return LogLevel(value.upper())
154
+ except (ValueError, TypeError):
155
+ raise ValueError(f"Invalid log level: {value}") from None
156
+
157
+ @classmethod
158
+ def choices(cls) -> list[str]:
159
+ """Return a list of all log levels as strings."""
160
+ return [str(c) for c in list(cls)]
@@ -0,0 +1,5 @@
1
+ """Utility modules for mreg_cli.
2
+
3
+ These modules are somewhat logically split based on the scope they typically
4
+ apply to.
5
+ """