UGOS 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.
- ugos/__about__.py +6 -0
- ugos/__init__.py +92 -0
- ugos/_auth.py +293 -0
- ugos/_client_base.py +52 -0
- ugos/_client_calls.py +200 -0
- ugos/_client_helpers.py +217 -0
- ugos/_client_lifecycle.py +144 -0
- ugos/_client_resources.py +192 -0
- ugos/_client_transfer.py +501 -0
- ugos/_codec.py +528 -0
- ugos/_config.py +183 -0
- ugos/_data/__init__.py +1 -0
- ugos/_data/action_contracts.json +325 -0
- ugos/_data/catalog.json +1256 -0
- ugos/_dynamic.py +221 -0
- ugos/_encoding.py +159 -0
- ugos/_pagination.py +158 -0
- ugos/_redaction.py +158 -0
- ugos/_transport.py +446 -0
- ugos/catalog.py +184 -0
- ugos/client.py +113 -0
- ugos/exceptions.py +137 -0
- ugos/models/__init__.py +37 -0
- ugos/models/common.py +87 -0
- ugos/models/entities.py +124 -0
- ugos/models/users.py +43 -0
- ugos/py.typed +0 -0
- ugos/resources/__init__.py +55 -0
- ugos/resources/administrators.py +71 -0
- ugos/resources/application.py +107 -0
- ugos/resources/base.py +38 -0
- ugos/resources/certificates.py +62 -0
- ugos/resources/contentrules.py +98 -0
- ugos/resources/contenttypes.py +9 -0
- ugos/resources/fwrules.py +103 -0
- ugos/resources/generic.py +283 -0
- ugos/resources/generic_controllers.py +169 -0
- ugos/resources/groups.py +94 -0
- ugos/resources/icap.py +132 -0
- ugos/resources/idps.py +125 -0
- ugos/resources/interfaces.py +40 -0
- ugos/resources/l7.py +110 -0
- ugos/resources/licensing.py +39 -0
- ugos/resources/mailsecurity.py +101 -0
- ugos/resources/networks.py +82 -0
- ugos/resources/netzones.py +78 -0
- ugos/resources/nlist.py +72 -0
- ugos/resources/overridedomains.py +47 -0
- ugos/resources/overrides.py +109 -0
- ugos/resources/overrides_content.py +254 -0
- ugos/resources/overrides_content_a.py +187 -0
- ugos/resources/overrides_lists.py +294 -0
- ugos/resources/overrides_misc.py +342 -0
- ugos/resources/overrides_network.py +291 -0
- ugos/resources/pcap.py +64 -0
- ugos/resources/registry.py +55 -0
- ugos/resources/settings.py +72 -0
- ugos/resources/sysinfo.py +39 -0
- ugos/resources/twofa.py +62 -0
- ugos/resources/urlcategory.py +69 -0
- ugos/resources/urlfiltering.py +23 -0
- ugos/resources/urllists.py +9 -0
- ugos/resources/users.py +74 -0
- ugos-1.0.0.dist-info/METADATA +139 -0
- ugos-1.0.0.dist-info/RECORD +67 -0
- ugos-1.0.0.dist-info/WHEEL +4 -0
- ugos-1.0.0.dist-info/licenses/LICENSE +16 -0
ugos/client.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""High-level synchronous UGOS NGFW client."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import contextlib
|
|
6
|
+
import threading
|
|
7
|
+
from collections.abc import Mapping
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
import httpx
|
|
12
|
+
|
|
13
|
+
from ._auth import AuthManager
|
|
14
|
+
from ._client_base import CONTROLLER_RE as _CONTROLLER_RE
|
|
15
|
+
from ._client_calls import _CallsMixin
|
|
16
|
+
from ._client_lifecycle import _LifecycleMixin
|
|
17
|
+
from ._client_resources import _ResourcesMixin
|
|
18
|
+
from ._client_transfer import _TransferMixin
|
|
19
|
+
from ._config import DEFAULT_PORT, DEFAULT_TIMEOUT, ClientConfig
|
|
20
|
+
from ._dynamic import ControllerProxy
|
|
21
|
+
from ._transport import HttpTransport
|
|
22
|
+
from .catalog import Catalog, load_catalog
|
|
23
|
+
from .exceptions import ConfigurationError
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class UGOSClient(_LifecycleMixin, _CallsMixin, _TransferMixin, _ResourcesMixin):
|
|
27
|
+
"""Synchronous client for the UGOS NGFW web-console API."""
|
|
28
|
+
|
|
29
|
+
def __init__(
|
|
30
|
+
self,
|
|
31
|
+
base_url: str | None = None,
|
|
32
|
+
*,
|
|
33
|
+
host: str | None = None,
|
|
34
|
+
port: int = DEFAULT_PORT,
|
|
35
|
+
scheme: str = "https",
|
|
36
|
+
username: str | None = None,
|
|
37
|
+
password: str | None = None,
|
|
38
|
+
verify: bool | str | Path = True,
|
|
39
|
+
timeout: float | httpx.Timeout | None = DEFAULT_TIMEOUT,
|
|
40
|
+
headers: Mapping[str, str] | None = None,
|
|
41
|
+
user_agent: str | None = None,
|
|
42
|
+
trust_env: bool = False,
|
|
43
|
+
follow_redirects: bool = False,
|
|
44
|
+
max_retries: int = 2,
|
|
45
|
+
retry_backoff: float = 0.25,
|
|
46
|
+
thread_safe: bool = True,
|
|
47
|
+
max_download_bytes: int | None = 64 * 1024 * 1024,
|
|
48
|
+
max_response_bytes: int | None = 16 * 1024 * 1024,
|
|
49
|
+
allow_insecure_http: bool = False,
|
|
50
|
+
auto_login: bool = True,
|
|
51
|
+
auto_reauth: bool = True,
|
|
52
|
+
logout_on_exit: bool = False,
|
|
53
|
+
catalog_check: bool = True,
|
|
54
|
+
catalog: Catalog | None = None,
|
|
55
|
+
http_client: httpx.Client | None = None,
|
|
56
|
+
) -> None:
|
|
57
|
+
self._config = ClientConfig.build(
|
|
58
|
+
base_url,
|
|
59
|
+
host=host,
|
|
60
|
+
port=port,
|
|
61
|
+
scheme=scheme,
|
|
62
|
+
verify=verify,
|
|
63
|
+
timeout=timeout,
|
|
64
|
+
headers=headers,
|
|
65
|
+
user_agent=user_agent,
|
|
66
|
+
trust_env=trust_env,
|
|
67
|
+
follow_redirects=follow_redirects,
|
|
68
|
+
max_retries=max_retries,
|
|
69
|
+
retry_backoff=retry_backoff,
|
|
70
|
+
thread_safe=thread_safe,
|
|
71
|
+
max_download_bytes=max_download_bytes,
|
|
72
|
+
max_response_bytes=max_response_bytes,
|
|
73
|
+
allow_insecure_http=allow_insecure_http,
|
|
74
|
+
)
|
|
75
|
+
self._transport = HttpTransport(self._config, http_client=http_client)
|
|
76
|
+
self._auth = AuthManager(
|
|
77
|
+
self._transport,
|
|
78
|
+
username=username,
|
|
79
|
+
password=password,
|
|
80
|
+
auto_reauth=auto_reauth,
|
|
81
|
+
)
|
|
82
|
+
self._catalog = catalog or load_catalog()
|
|
83
|
+
self._auto_login = auto_login
|
|
84
|
+
self._logout_on_exit = logout_on_exit
|
|
85
|
+
self._catalog_check = catalog_check
|
|
86
|
+
self._lock = threading.RLock() if thread_safe else contextlib.nullcontext()
|
|
87
|
+
self._resources: dict[str, ControllerProxy] = {}
|
|
88
|
+
|
|
89
|
+
def version(self) -> Any:
|
|
90
|
+
return self.call("utm", "CoreGetVersion")
|
|
91
|
+
|
|
92
|
+
def _prepare(self) -> None:
|
|
93
|
+
if self._auto_login and not self._auth.authenticated:
|
|
94
|
+
self._auth.login()
|
|
95
|
+
|
|
96
|
+
def _refresh_session(self, expected_generation: int) -> None:
|
|
97
|
+
with self._lock:
|
|
98
|
+
if self._auth.generation != expected_generation:
|
|
99
|
+
# Another thread already refreshed the session.
|
|
100
|
+
return
|
|
101
|
+
if self._auth.auto_reauth:
|
|
102
|
+
self._auth.login(force=True)
|
|
103
|
+
else:
|
|
104
|
+
self._auth.invalidate()
|
|
105
|
+
|
|
106
|
+
def _validate(self, controller: str, action: str, *, strict: bool | None = None) -> None:
|
|
107
|
+
if not _CONTROLLER_RE.match(controller):
|
|
108
|
+
raise ConfigurationError(f"invalid controller name: {controller!r}")
|
|
109
|
+
if not _CONTROLLER_RE.match(action):
|
|
110
|
+
raise ConfigurationError(f"invalid action name: {action!r}")
|
|
111
|
+
check = self._catalog_check if strict is None else strict
|
|
112
|
+
if check:
|
|
113
|
+
self._catalog.check(controller, action)
|
ugos/exceptions.py
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"""Public exception hierarchy for :mod:`ugos`."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Mapping
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from ._redaction import redact_mapping, redact_text
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _redact_payload(payload: Any) -> Any:
|
|
12
|
+
if isinstance(payload, Mapping):
|
|
13
|
+
return redact_mapping(payload)
|
|
14
|
+
if isinstance(payload, str):
|
|
15
|
+
return redact_text(payload)
|
|
16
|
+
if isinstance(payload, (list, tuple)):
|
|
17
|
+
return [_redact_payload(item) for item in payload]
|
|
18
|
+
return payload
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class UGOSError(Exception):
|
|
22
|
+
"""Base class for all library errors."""
|
|
23
|
+
|
|
24
|
+
def __init__(
|
|
25
|
+
self,
|
|
26
|
+
message: str,
|
|
27
|
+
*,
|
|
28
|
+
code: int | None = None,
|
|
29
|
+
status_code: int | None = None,
|
|
30
|
+
payload: Any = None,
|
|
31
|
+
controller: str | None = None,
|
|
32
|
+
action: str | None = None,
|
|
33
|
+
) -> None:
|
|
34
|
+
redacted_message = redact_text(message)
|
|
35
|
+
super().__init__(redacted_message)
|
|
36
|
+
self.message = redacted_message
|
|
37
|
+
self.code = code
|
|
38
|
+
self.status_code = status_code
|
|
39
|
+
self.payload = _redact_payload(payload)
|
|
40
|
+
self.controller = controller
|
|
41
|
+
self.action = action
|
|
42
|
+
|
|
43
|
+
def __str__(self) -> str:
|
|
44
|
+
parts = [self.message]
|
|
45
|
+
if self.code is not None:
|
|
46
|
+
parts.append(f"errorCode={self.code}")
|
|
47
|
+
if self.controller and self.action:
|
|
48
|
+
parts.append(f"action={self.controller}/{self.action}")
|
|
49
|
+
return " ".join(parts)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class ConfigurationError(UGOSError):
|
|
53
|
+
"""Invalid client configuration."""
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class CatalogError(UGOSError):
|
|
57
|
+
"""Catalog lookup failed."""
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class UnknownControllerError(CatalogError):
|
|
61
|
+
"""Controller is not present in the API catalog."""
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class UnknownActionError(CatalogError):
|
|
65
|
+
"""Action is not present in the API catalog for the controller."""
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class TransportError(UGOSError):
|
|
69
|
+
"""Network transport failed."""
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class RequestTimeoutError(TransportError):
|
|
73
|
+
"""The request timed out."""
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class ProtocolError(UGOSError):
|
|
77
|
+
"""The appliance returned an unexpected protocol response."""
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class DecodeError(ProtocolError):
|
|
81
|
+
"""The response could not be decoded."""
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class HTTPStatusError(UGOSError):
|
|
85
|
+
"""The server returned an unexpected HTTP status."""
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class ServerError(HTTPStatusError):
|
|
89
|
+
"""The server returned a 5xx response."""
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class APIError(UGOSError):
|
|
93
|
+
"""The API returned ``{"success": false, "errorCode": ...}``."""
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class AuthenticationError(APIError):
|
|
97
|
+
"""Authentication was rejected."""
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
class SessionExpiredError(AuthenticationError):
|
|
101
|
+
"""The cookie session is missing or has expired."""
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class AccessDeniedError(APIError):
|
|
105
|
+
"""The current administrator is not allowed to perform the action."""
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class ValidationError(APIError):
|
|
109
|
+
"""The API rejected one or more arguments."""
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class NotFoundError(APIError):
|
|
113
|
+
"""The requested object does not exist."""
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class DuplicateError(APIError):
|
|
117
|
+
"""The object already exists."""
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class ConflictError(APIError):
|
|
121
|
+
"""The object is still referenced or conflicts with another object."""
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class ReadOnlyListError(APIError):
|
|
125
|
+
"""The requested list is built in and its content is not exposed."""
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class CSRFError(AuthenticationError):
|
|
129
|
+
"""CSRF validation failed."""
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
class DownloadError(ProtocolError):
|
|
133
|
+
"""A file download failed or was incomplete."""
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
class CleanupError(UGOSError):
|
|
137
|
+
"""A cleanup operation failed."""
|
ugos/models/__init__.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Public models."""
|
|
2
|
+
|
|
3
|
+
from .common import DownloadedFile, ListResult, SessionInfo
|
|
4
|
+
from .entities import (
|
|
5
|
+
Administrator,
|
|
6
|
+
Certificate,
|
|
7
|
+
FirewallRule,
|
|
8
|
+
Group,
|
|
9
|
+
Interface,
|
|
10
|
+
LicenseInfo,
|
|
11
|
+
NetworkList,
|
|
12
|
+
PcapFilter,
|
|
13
|
+
PcapRule,
|
|
14
|
+
Tag,
|
|
15
|
+
Zone,
|
|
16
|
+
)
|
|
17
|
+
from .users import User, UserCreate, UserUpdate
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"Administrator",
|
|
21
|
+
"Certificate",
|
|
22
|
+
"DownloadedFile",
|
|
23
|
+
"FirewallRule",
|
|
24
|
+
"Group",
|
|
25
|
+
"Interface",
|
|
26
|
+
"LicenseInfo",
|
|
27
|
+
"ListResult",
|
|
28
|
+
"NetworkList",
|
|
29
|
+
"PcapFilter",
|
|
30
|
+
"PcapRule",
|
|
31
|
+
"SessionInfo",
|
|
32
|
+
"Tag",
|
|
33
|
+
"User",
|
|
34
|
+
"UserCreate",
|
|
35
|
+
"UserUpdate",
|
|
36
|
+
"Zone",
|
|
37
|
+
]
|
ugos/models/common.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Common public models."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import dataclasses
|
|
6
|
+
from collections.abc import Mapping
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any, Generic, TypeVar
|
|
9
|
+
|
|
10
|
+
from ..exceptions import DecodeError
|
|
11
|
+
|
|
12
|
+
T = TypeVar("T")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclasses.dataclass(frozen=True)
|
|
16
|
+
class ListResult(Generic[T]):
|
|
17
|
+
"""A list response envelope.
|
|
18
|
+
|
|
19
|
+
The appliance normally returns ``{"items": [...], "total": N}`` but some
|
|
20
|
+
actions return a bare JSON array. Both forms are normalized here.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
items: list[T]
|
|
24
|
+
total: int | None = None
|
|
25
|
+
success: bool = True
|
|
26
|
+
paged: bool = False
|
|
27
|
+
|
|
28
|
+
@classmethod
|
|
29
|
+
def _from_mapping(cls, data: Mapping[str, Any]) -> ListResult[T]:
|
|
30
|
+
items = data.get("items")
|
|
31
|
+
if not isinstance(items, list):
|
|
32
|
+
raise DecodeError("expected an 'items' list in the response")
|
|
33
|
+
total = data.get("total")
|
|
34
|
+
return cls(
|
|
35
|
+
items=list(items),
|
|
36
|
+
total=total if isinstance(total, int) else None,
|
|
37
|
+
success=bool(data.get("success", True)),
|
|
38
|
+
paged=True,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
@classmethod
|
|
42
|
+
def from_response(cls, data: Any) -> ListResult[T]:
|
|
43
|
+
if isinstance(data, list):
|
|
44
|
+
return cls(items=list(data), total=len(data), success=True, paged=False)
|
|
45
|
+
if isinstance(data, Mapping):
|
|
46
|
+
return cls._from_mapping(data)
|
|
47
|
+
raise DecodeError(f"expected a list response, got {type(data).__name__}")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@dataclasses.dataclass(frozen=True)
|
|
51
|
+
class DownloadedFile:
|
|
52
|
+
"""Result of :meth:`ugos.UGOSClient.download`."""
|
|
53
|
+
|
|
54
|
+
content: bytes | None = dataclasses.field(repr=False)
|
|
55
|
+
filename: str
|
|
56
|
+
content_type: str | None = None
|
|
57
|
+
status_code: int = 200
|
|
58
|
+
headers: Mapping[str, str] = dataclasses.field(default_factory=dict)
|
|
59
|
+
path: Path | None = None
|
|
60
|
+
|
|
61
|
+
@property
|
|
62
|
+
def size(self) -> int:
|
|
63
|
+
if self.content is not None:
|
|
64
|
+
return len(self.content)
|
|
65
|
+
if self.path is not None:
|
|
66
|
+
return self.path.stat().st_size
|
|
67
|
+
return 0
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@dataclasses.dataclass
|
|
71
|
+
class SessionInfo:
|
|
72
|
+
"""State of an authenticated console session."""
|
|
73
|
+
|
|
74
|
+
username: str
|
|
75
|
+
admin_id: int | None = None
|
|
76
|
+
product: str | None = None
|
|
77
|
+
version: str | None = None
|
|
78
|
+
auth_token: bool = False
|
|
79
|
+
fingerprint: str = ""
|
|
80
|
+
raw: dict[str, Any] = dataclasses.field(default_factory=dict, repr=False)
|
|
81
|
+
|
|
82
|
+
def __repr__(self) -> str:
|
|
83
|
+
return (
|
|
84
|
+
f"SessionInfo(username={self.username!r}, admin_id={self.admin_id!r}, "
|
|
85
|
+
f"product={self.product!r}, version={self.version!r}, "
|
|
86
|
+
f"fingerprint={self.fingerprint!r})"
|
|
87
|
+
)
|
ugos/models/entities.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"""TypedDict models for common appliance entities.
|
|
2
|
+
|
|
3
|
+
These models allow unknown fields and mark only the fields that are safe to
|
|
4
|
+
rely on.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import Any, TypedDict
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class _Identified(TypedDict, total=False):
|
|
13
|
+
id: int | str
|
|
14
|
+
guid: str
|
|
15
|
+
name: str
|
|
16
|
+
description: str
|
|
17
|
+
cc: bool
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Administrator(_Identified, total=False):
|
|
21
|
+
login: str
|
|
22
|
+
display_name: str
|
|
23
|
+
enabled: bool
|
|
24
|
+
profile_id: int
|
|
25
|
+
profile_name: str
|
|
26
|
+
user_auth_profile_id: int
|
|
27
|
+
locked: bool
|
|
28
|
+
is_root: bool
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Group(_Identified, total=False):
|
|
32
|
+
group_type: str
|
|
33
|
+
is_transient: bool
|
|
34
|
+
all_users: list[str]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class FirewallRule(_Identified, total=False):
|
|
38
|
+
action: str
|
|
39
|
+
enabled: bool
|
|
40
|
+
position: int
|
|
41
|
+
position_layer: str
|
|
42
|
+
src_zones: list[Any]
|
|
43
|
+
dst_zones: list[Any]
|
|
44
|
+
src_ips: list[Any]
|
|
45
|
+
dst_ips: list[Any]
|
|
46
|
+
services: list[Any]
|
|
47
|
+
users: list[Any]
|
|
48
|
+
time_restrictions: list[Any]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class Zone(_Identified, total=False):
|
|
52
|
+
networks: list[Any]
|
|
53
|
+
services_access: list[Any]
|
|
54
|
+
dos_profiles: list[Any]
|
|
55
|
+
enable_antispoof: bool
|
|
56
|
+
antispoof_invert: bool
|
|
57
|
+
read_only: bool
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class Interface(_Identified, total=False):
|
|
61
|
+
kind: str
|
|
62
|
+
enabled: bool
|
|
63
|
+
node_name: str
|
|
64
|
+
zone_id: Any
|
|
65
|
+
mode: str
|
|
66
|
+
mtu: int
|
|
67
|
+
ipv4: list[Any]
|
|
68
|
+
tags: list[Any]
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class NetworkList(_Identified, total=False):
|
|
72
|
+
type: str
|
|
73
|
+
url: str
|
|
74
|
+
enabled: bool
|
|
75
|
+
editable: bool
|
|
76
|
+
readonly: bool
|
|
77
|
+
threat_level: int
|
|
78
|
+
list_type_update: str
|
|
79
|
+
schedule: str
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class Certificate(_Identified, total=False):
|
|
83
|
+
subject: Any
|
|
84
|
+
issuer: Any
|
|
85
|
+
role: str
|
|
86
|
+
ca: bool
|
|
87
|
+
not_before: str
|
|
88
|
+
not_after: str
|
|
89
|
+
has_private_key: bool
|
|
90
|
+
has_cert: bool
|
|
91
|
+
has_csr: bool
|
|
92
|
+
has_cert_chain: bool
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class Tag(_Identified, total=False):
|
|
96
|
+
html_color: str
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class PcapRule(_Identified, total=False):
|
|
100
|
+
file: str
|
|
101
|
+
byte_count: int
|
|
102
|
+
interfaces: list[str]
|
|
103
|
+
filters: list[int]
|
|
104
|
+
capturing: bool
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class PcapFilter(_Identified, total=False):
|
|
108
|
+
source: str
|
|
109
|
+
source_port: str | int
|
|
110
|
+
destination: str
|
|
111
|
+
destination_port: str | int
|
|
112
|
+
ethernet_protocol: str
|
|
113
|
+
ipv4_protocol: int
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class LicenseInfo(TypedDict, total=False):
|
|
117
|
+
version: str
|
|
118
|
+
product: str
|
|
119
|
+
license_type: str
|
|
120
|
+
user_limit: int
|
|
121
|
+
expiry_date: str
|
|
122
|
+
modules: list[dict[str, Any]]
|
|
123
|
+
product_serial: str
|
|
124
|
+
product_device: str
|
ugos/models/users.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""TypedDict models for users."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TypedDict
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class UserRequired(TypedDict):
|
|
9
|
+
id: str
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class User(UserRequired, total=False):
|
|
13
|
+
name: str
|
|
14
|
+
auth_login: str
|
|
15
|
+
enabled: bool
|
|
16
|
+
is_ldap: bool
|
|
17
|
+
first_name: str
|
|
18
|
+
last_name: str
|
|
19
|
+
emails: list[str]
|
|
20
|
+
phones: list[str]
|
|
21
|
+
groups: list[object]
|
|
22
|
+
all_groups: list[str]
|
|
23
|
+
static_ip_addresses: list[list[str]]
|
|
24
|
+
expiration_date: bool | str
|
|
25
|
+
creation_date: str
|
|
26
|
+
ldap_dn: str
|
|
27
|
+
cc: bool
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class UserCreate(TypedDict, total=False):
|
|
31
|
+
name: str
|
|
32
|
+
auth_login: str
|
|
33
|
+
auth_password: str
|
|
34
|
+
enabled: bool
|
|
35
|
+
expiration_date: bool | str
|
|
36
|
+
all_groups: list[str]
|
|
37
|
+
static_ip_addresses: list[list[str]]
|
|
38
|
+
emails: list[str]
|
|
39
|
+
phones: list[str]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class UserUpdate(UserCreate, total=False):
|
|
43
|
+
id: str
|
ugos/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Typed controller resources."""
|
|
2
|
+
|
|
3
|
+
from .administrators import AdministratorsResource
|
|
4
|
+
from .application import ApplicationResource
|
|
5
|
+
from .base import Resource
|
|
6
|
+
from .certificates import CertificatesResource
|
|
7
|
+
from .contentrules import ContentRulesResource
|
|
8
|
+
from .contenttypes import ContentTypesResource
|
|
9
|
+
from .fwrules import FirewallRulesResource
|
|
10
|
+
from .groups import GroupsResource
|
|
11
|
+
from .icap import IcapResource
|
|
12
|
+
from .idps import IdpsResource
|
|
13
|
+
from .interfaces import InterfacesResource
|
|
14
|
+
from .l7 import L7Resource
|
|
15
|
+
from .licensing import LicensingResource
|
|
16
|
+
from .mailsecurity import MailSecurityResource
|
|
17
|
+
from .networks import NetworksResource
|
|
18
|
+
from .netzones import NetzonesResource
|
|
19
|
+
from .overridedomains import OverrideDomainsResource
|
|
20
|
+
from .pcap import PcapResource
|
|
21
|
+
from .settings import SettingsResource
|
|
22
|
+
from .sysinfo import SysinfoResource
|
|
23
|
+
from .twofa import TwoFactorResource
|
|
24
|
+
from .urlcategory import UrlCategoryResource
|
|
25
|
+
from .urlfiltering import UrlFilteringResource
|
|
26
|
+
from .urllists import UrlListsResource
|
|
27
|
+
from .users import UsersResource
|
|
28
|
+
|
|
29
|
+
__all__ = [
|
|
30
|
+
"AdministratorsResource",
|
|
31
|
+
"ApplicationResource",
|
|
32
|
+
"CertificatesResource",
|
|
33
|
+
"ContentRulesResource",
|
|
34
|
+
"ContentTypesResource",
|
|
35
|
+
"FirewallRulesResource",
|
|
36
|
+
"GroupsResource",
|
|
37
|
+
"IcapResource",
|
|
38
|
+
"IdpsResource",
|
|
39
|
+
"InterfacesResource",
|
|
40
|
+
"L7Resource",
|
|
41
|
+
"LicensingResource",
|
|
42
|
+
"MailSecurityResource",
|
|
43
|
+
"NetworksResource",
|
|
44
|
+
"NetzonesResource",
|
|
45
|
+
"OverrideDomainsResource",
|
|
46
|
+
"PcapResource",
|
|
47
|
+
"Resource",
|
|
48
|
+
"SettingsResource",
|
|
49
|
+
"SysinfoResource",
|
|
50
|
+
"TwoFactorResource",
|
|
51
|
+
"UrlCategoryResource",
|
|
52
|
+
"UrlFilteringResource",
|
|
53
|
+
"UrlListsResource",
|
|
54
|
+
"UsersResource",
|
|
55
|
+
]
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Administrators controller."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Iterator
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from ..models.common import ListResult
|
|
9
|
+
from ..models.entities import Administrator
|
|
10
|
+
from .base import Resource
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AdministratorsResource(Resource):
|
|
14
|
+
controller = "administrators"
|
|
15
|
+
|
|
16
|
+
def list(self, *, start: int = 0, limit: int = 100) -> ListResult[Administrator]:
|
|
17
|
+
return ListResult.from_response(self.call("AdministratorsList", start=start, limit=limit))
|
|
18
|
+
|
|
19
|
+
def iter_all( # type: ignore[override]
|
|
20
|
+
self,
|
|
21
|
+
*,
|
|
22
|
+
page_size: int = 100,
|
|
23
|
+
start: int = 0,
|
|
24
|
+
max_items: int | None = None,
|
|
25
|
+
max_pages: int = 1000,
|
|
26
|
+
) -> Iterator[dict[str, Any]]:
|
|
27
|
+
return self._iter_all(
|
|
28
|
+
"AdministratorsList",
|
|
29
|
+
page_size=page_size,
|
|
30
|
+
start=start,
|
|
31
|
+
max_items=max_items,
|
|
32
|
+
max_pages=max_pages,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
def get(self, admin_id: int, /) -> Administrator:
|
|
36
|
+
return self.call("AdministratorFetch", id=admin_id)
|
|
37
|
+
|
|
38
|
+
def create(self, data: dict[str, Any], /) -> Any:
|
|
39
|
+
return self.call("AdministratorAdd", data=data)
|
|
40
|
+
|
|
41
|
+
def update(self, admin_id: int, data: dict[str, Any], /) -> Any:
|
|
42
|
+
payload = dict(data)
|
|
43
|
+
payload["id"] = admin_id
|
|
44
|
+
return self.call("AdministratorUpdate", data=payload)
|
|
45
|
+
|
|
46
|
+
def delete(self, admin_id: int, /) -> Any:
|
|
47
|
+
return self.call("AdministratorDelete", data={"id": admin_id})
|
|
48
|
+
|
|
49
|
+
def change_password(self, old_password: str, new_password: str, /) -> Any:
|
|
50
|
+
return self.call(
|
|
51
|
+
"ChangePassword",
|
|
52
|
+
data={"old_password": old_password, "new_password": new_password},
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
def unlock(self, admin_id: int, /) -> Any:
|
|
56
|
+
return self.call("AdministratorUnlock", id=admin_id)
|
|
57
|
+
|
|
58
|
+
def roles(self) -> ListResult[dict[str, Any]]:
|
|
59
|
+
return ListResult.from_response(self.call("RolesList"))
|
|
60
|
+
|
|
61
|
+
def sessions(self) -> ListResult[dict[str, Any]]:
|
|
62
|
+
return ListResult.from_response(self.call("SessionsList"))
|
|
63
|
+
|
|
64
|
+
def terminate_session(self, session_id: str, /) -> Any:
|
|
65
|
+
return self.call("SessionTerminate", data={"id": session_id})
|
|
66
|
+
|
|
67
|
+
def profiles(self) -> ListResult[dict[str, Any]]:
|
|
68
|
+
return ListResult.from_response(self.call("ProfilesList"))
|
|
69
|
+
|
|
70
|
+
def config(self) -> dict[str, Any]:
|
|
71
|
+
return self.call("ConfigFetch")
|