geobox 1.4.2__py3-none-any.whl → 2.0.1__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.
- geobox/__init__.py +2 -2
- geobox/aio/__init__.py +63 -0
- geobox/aio/api.py +2640 -0
- geobox/aio/apikey.py +263 -0
- geobox/aio/attachment.py +339 -0
- geobox/aio/base.py +262 -0
- geobox/aio/basemap.py +196 -0
- geobox/aio/dashboard.py +342 -0
- geobox/aio/feature.py +527 -0
- geobox/aio/field.py +321 -0
- geobox/aio/file.py +522 -0
- geobox/aio/layout.py +341 -0
- geobox/aio/log.py +145 -0
- geobox/aio/map.py +1034 -0
- geobox/aio/model3d.py +415 -0
- geobox/aio/mosaic.py +696 -0
- geobox/aio/plan.py +315 -0
- geobox/aio/query.py +693 -0
- geobox/aio/raster.py +869 -0
- geobox/aio/route.py +63 -0
- geobox/aio/scene.py +342 -0
- geobox/aio/settings.py +194 -0
- geobox/aio/task.py +402 -0
- geobox/aio/tile3d.py +339 -0
- geobox/aio/tileset.py +672 -0
- geobox/aio/usage.py +243 -0
- geobox/aio/user.py +507 -0
- geobox/aio/vectorlayer.py +1363 -0
- geobox/aio/version.py +273 -0
- geobox/aio/view.py +983 -0
- geobox/aio/workflow.py +341 -0
- geobox/api.py +14 -15
- geobox/apikey.py +28 -1
- geobox/attachment.py +27 -1
- geobox/base.py +4 -4
- geobox/basemap.py +30 -1
- geobox/dashboard.py +27 -0
- geobox/feature.py +33 -13
- geobox/field.py +33 -21
- geobox/file.py +40 -46
- geobox/layout.py +28 -1
- geobox/log.py +31 -7
- geobox/map.py +34 -2
- geobox/model3d.py +31 -37
- geobox/mosaic.py +28 -7
- geobox/plan.py +29 -3
- geobox/query.py +39 -14
- geobox/raster.py +26 -13
- geobox/scene.py +26 -0
- geobox/settings.py +30 -1
- geobox/task.py +28 -6
- geobox/tile3d.py +27 -1
- geobox/tileset.py +26 -5
- geobox/usage.py +32 -1
- geobox/user.py +62 -6
- geobox/utils.py +34 -0
- geobox/vectorlayer.py +40 -4
- geobox/version.py +25 -1
- geobox/view.py +37 -17
- geobox/workflow.py +27 -1
- {geobox-1.4.2.dist-info → geobox-2.0.1.dist-info}/METADATA +4 -1
- geobox-2.0.1.dist-info/RECORD +68 -0
- geobox-1.4.2.dist-info/RECORD +0 -38
- {geobox-1.4.2.dist-info → geobox-2.0.1.dist-info}/WHEEL +0 -0
- {geobox-1.4.2.dist-info → geobox-2.0.1.dist-info}/licenses/LICENSE +0 -0
- {geobox-1.4.2.dist-info → geobox-2.0.1.dist-info}/top_level.txt +0 -0
geobox/aio/route.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from typing import Dict, TYPE_CHECKING
|
|
2
|
+
from urllib.parse import urljoin, urlencode
|
|
3
|
+
|
|
4
|
+
from ..enums import RoutingGeometryType, RoutingOverviewLevel
|
|
5
|
+
from ..utils import clean_data
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from . import AsyncGeoboxClient
|
|
9
|
+
|
|
10
|
+
class Routing:
|
|
11
|
+
|
|
12
|
+
BASE_ENDPOINT = 'routing/'
|
|
13
|
+
|
|
14
|
+
@classmethod
|
|
15
|
+
async def route(cls, api: 'AsyncGeoboxClient', stops: str, **kwargs) -> Dict:
|
|
16
|
+
"""
|
|
17
|
+
Find best driving routes between coordinates and return results.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
|
|
21
|
+
stops (str): Comma-separated list of stop coordinates in the format lon,lat;lon,lat.
|
|
22
|
+
|
|
23
|
+
Keyword Args:
|
|
24
|
+
alternatives (bool): Whether to return alternative routes. Default value : False.
|
|
25
|
+
steps (bool): Whether to include step-by-step navigation instructions. Default value : False.
|
|
26
|
+
geometries (RoutingGeometryType): Format of the returned geometry.
|
|
27
|
+
overview (RoutingOverviewLevel): Level of detail in the returned geometry.
|
|
28
|
+
annotations (bool): Whether to include additional metadata like speed, weight, etc.
|
|
29
|
+
|
|
30
|
+
Returns:
|
|
31
|
+
Dict: the routing output
|
|
32
|
+
|
|
33
|
+
Example:
|
|
34
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
35
|
+
>>> from geobox.aio.route import Routing
|
|
36
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
37
|
+
>>> route = await routing.route(client,
|
|
38
|
+
... stops="53,33;56,36",
|
|
39
|
+
... alternatives=True,
|
|
40
|
+
... steps=True,
|
|
41
|
+
... geometries=RoutingGeometryType.geojson,
|
|
42
|
+
... overview=RoutingOverviewLevel.full,
|
|
43
|
+
... annotations=True)
|
|
44
|
+
or
|
|
45
|
+
>>> route = await client.route(stops="53,33;56,36",
|
|
46
|
+
... alternatives=True,
|
|
47
|
+
... steps=True,
|
|
48
|
+
... geometries=RoutingGeometryType.geojson,
|
|
49
|
+
... overview=RoutingOverviewLevel.full,
|
|
50
|
+
... annotations=True)
|
|
51
|
+
"""
|
|
52
|
+
params = clean_data({
|
|
53
|
+
'stops': stops,
|
|
54
|
+
'alternatives': kwargs.get('alternatives'),
|
|
55
|
+
'steps': kwargs.get('steps'),
|
|
56
|
+
'geometries': kwargs.get('geometries').value if kwargs.get('geometries') else None,
|
|
57
|
+
'overview': kwargs.get('overview').value if kwargs.get('geometries') else None,
|
|
58
|
+
'annotaions': kwargs.get('annotations')
|
|
59
|
+
})
|
|
60
|
+
query_string = urlencode(params)
|
|
61
|
+
endpoint = f"{cls.BASE_ENDPOINT}route?{query_string}"
|
|
62
|
+
return await api.get(endpoint)
|
|
63
|
+
|
geobox/aio/scene.py
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
from typing import List, Dict, Optional, TYPE_CHECKING, Union
|
|
2
|
+
from urllib.parse import urljoin
|
|
3
|
+
|
|
4
|
+
from .base import AsyncBase
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from . import AsyncGeoboxClient
|
|
8
|
+
from .user import User
|
|
9
|
+
from ..api import GeoboxClient as SyncGeoboxClient
|
|
10
|
+
from ..scene import Scene as SyncScene
|
|
11
|
+
|
|
12
|
+
class Scene(AsyncBase):
|
|
13
|
+
|
|
14
|
+
BASE_ENDPOINT = 'scenes/'
|
|
15
|
+
|
|
16
|
+
def __init__(self,
|
|
17
|
+
api: 'AsyncGeoboxClient',
|
|
18
|
+
uuid: str,
|
|
19
|
+
data: Optional[Dict] = {}):
|
|
20
|
+
"""
|
|
21
|
+
Initialize a Scene instance.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
|
|
25
|
+
uuid (str): The unique identifier for the Scene.
|
|
26
|
+
data (Dict): The data of the Scene.
|
|
27
|
+
"""
|
|
28
|
+
super().__init__(api, uuid=uuid, data=data)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@classmethod
|
|
32
|
+
async def get_scenes(cls, api: 'AsyncGeoboxClient', **kwargs) -> Union[List['Scene'], int]:
|
|
33
|
+
"""
|
|
34
|
+
[async] Get list of scenes with optional filtering and pagination.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
|
|
38
|
+
|
|
39
|
+
Keyword Args:
|
|
40
|
+
q (str): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'"
|
|
41
|
+
search (str): search term for keyword-based searching among search_fields or all textual fields if search_fields does not have value. NOTE: if q param is defined this param will be ignored.
|
|
42
|
+
search_fields (str): comma separated list of fields for searching.
|
|
43
|
+
order_by (str): comma separated list of fields for sorting results [field1 A|D, field2 A|D, …]. e.g. name A, type D. NOTE: "A" denotes ascending order and "D" denotes descending order.
|
|
44
|
+
return_count (bool): Whether to return total count. default is False.
|
|
45
|
+
skip (int): Number of items to skip. default is 0.
|
|
46
|
+
limit (int): Number of items to return. default is 10.
|
|
47
|
+
user_id (int): Specific user. privileges required.
|
|
48
|
+
shared (bool): Whether to return shared scenes. default is False.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
List[Scene] | int: A list of scene instances or the total number of scenes.
|
|
52
|
+
|
|
53
|
+
Example:
|
|
54
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
55
|
+
>>> from geobox.aio.scene import Scene
|
|
56
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
57
|
+
>>> scenes = await Scene.get_scenes(client, q="name LIKE '%My scene%'")
|
|
58
|
+
or
|
|
59
|
+
>>> scenes = await client.get_scenes(q="name LIKE '%My scene%'")
|
|
60
|
+
"""
|
|
61
|
+
params = {
|
|
62
|
+
'f': 'json',
|
|
63
|
+
'q': kwargs.get('q'),
|
|
64
|
+
'search': kwargs.get('search'),
|
|
65
|
+
'search_fields': kwargs.get('search_fields'),
|
|
66
|
+
'order_by': kwargs.get('order_by'),
|
|
67
|
+
'return_count': kwargs.get('return_count', False),
|
|
68
|
+
'skip': kwargs.get('skip', 0),
|
|
69
|
+
'limit': kwargs.get('limit', 10),
|
|
70
|
+
'user_id': kwargs.get('user_id'),
|
|
71
|
+
'shared': kwargs.get('shared', False)
|
|
72
|
+
}
|
|
73
|
+
return await super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: Scene(api, item['uuid'], item))
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@classmethod
|
|
77
|
+
async def create_scene(cls,
|
|
78
|
+
api: 'AsyncGeoboxClient',
|
|
79
|
+
name: str,
|
|
80
|
+
display_name: str = None,
|
|
81
|
+
description: str = None,
|
|
82
|
+
settings: Dict = {},
|
|
83
|
+
thumbnail: str = None,
|
|
84
|
+
user_id: int = None) -> 'Scene':
|
|
85
|
+
"""
|
|
86
|
+
[async] Create a new scene.
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
|
|
90
|
+
name (str): The name of the scene.
|
|
91
|
+
display_name (str, optional): The display name of the scene.
|
|
92
|
+
description (str, optional): The description of the scene.
|
|
93
|
+
settings (Dict,optional): The settings of the scene.
|
|
94
|
+
thumbnail (str, optional): The thumbnail of the scene.
|
|
95
|
+
user_id (int, optional): Specific user. privileges required.
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
Scene: The newly created scene instance.
|
|
99
|
+
|
|
100
|
+
Raises:
|
|
101
|
+
ValidationError: If the scene data is invalid.
|
|
102
|
+
|
|
103
|
+
Example:
|
|
104
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
105
|
+
>>> from geobox.aio.scene import Scene
|
|
106
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
107
|
+
>>> scene = await Scene.create_scene(client, name="my_scene")
|
|
108
|
+
or
|
|
109
|
+
>>> scene = await client.create_scene(name="my_scene")
|
|
110
|
+
"""
|
|
111
|
+
data = {
|
|
112
|
+
"name": name,
|
|
113
|
+
"display_name": display_name,
|
|
114
|
+
"description": description,
|
|
115
|
+
"settings": settings,
|
|
116
|
+
"thumbnail": thumbnail,
|
|
117
|
+
"user_id": user_id,
|
|
118
|
+
}
|
|
119
|
+
return await super()._create(api, cls.BASE_ENDPOINT, data, factory_func=lambda api, item: Scene(api, item['uuid'], item))
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
@classmethod
|
|
123
|
+
async def get_scene(cls, api: 'AsyncGeoboxClient', uuid: str, user_id: int = None) -> 'Scene':
|
|
124
|
+
"""
|
|
125
|
+
[async] Get a scene by its UUID.
|
|
126
|
+
|
|
127
|
+
Args:
|
|
128
|
+
api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
|
|
129
|
+
uuid (str): The UUID of the scene to get.
|
|
130
|
+
user_id (int, optional): Specific user. privileges required.
|
|
131
|
+
|
|
132
|
+
Returns:
|
|
133
|
+
Scene: The scene object.
|
|
134
|
+
|
|
135
|
+
Raises:
|
|
136
|
+
NotFoundError: If the scene with the specified UUID is not found.
|
|
137
|
+
|
|
138
|
+
Example:
|
|
139
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
140
|
+
>>> from geobox.aio.scene import Scene
|
|
141
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
142
|
+
>>> scene = await Scene.get_scene(client, uuid="12345678-1234-5678-1234-567812345678")
|
|
143
|
+
or
|
|
144
|
+
>>> scene = await client.get_scene(uuid="12345678-1234-5678-1234-567812345678")
|
|
145
|
+
"""
|
|
146
|
+
params = {
|
|
147
|
+
'f': 'json',
|
|
148
|
+
'user_id': user_id,
|
|
149
|
+
}
|
|
150
|
+
return await super()._get_detail(api, cls.BASE_ENDPOINT, uuid, params, factory_func=lambda api, item: Scene(api, item['uuid'], item))
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
@classmethod
|
|
154
|
+
async def get_scene_by_name(cls, api: 'AsyncGeoboxClient', name: str, user_id: int = None) -> Union['Scene', None]:
|
|
155
|
+
"""
|
|
156
|
+
[async] Get a scene by name
|
|
157
|
+
|
|
158
|
+
Args:
|
|
159
|
+
api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
|
|
160
|
+
name (str): the name of the scene to get
|
|
161
|
+
user_id (int, optional): specific user. privileges required.
|
|
162
|
+
|
|
163
|
+
Returns:
|
|
164
|
+
Scene | None: returns the scene if a scene matches the given name, else None
|
|
165
|
+
|
|
166
|
+
Example:
|
|
167
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
168
|
+
>>> from geobox.aio.scene import Scene
|
|
169
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
170
|
+
>>> scene = await Scene.get_scene_by_name(client, name='test')
|
|
171
|
+
or
|
|
172
|
+
>>> scene = await client.get_scene_by_name(name='test')
|
|
173
|
+
"""
|
|
174
|
+
scenes = await cls.get_scenes(api, q=f"name = '{name}'", user_id=user_id)
|
|
175
|
+
if scenes and scenes[0].name == name:
|
|
176
|
+
return scenes[0]
|
|
177
|
+
else:
|
|
178
|
+
return None
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
async def update(self, **kwargs) -> Dict:
|
|
182
|
+
"""
|
|
183
|
+
[async] Update the scene.
|
|
184
|
+
|
|
185
|
+
Keyword Args:
|
|
186
|
+
name (str): The name of the scene.
|
|
187
|
+
display_name (str): The display name of the scene.
|
|
188
|
+
description (str): The description of the scene.
|
|
189
|
+
settings (Dict): The settings of the scene.
|
|
190
|
+
thumbnail (str): The thumbnail of the scene.
|
|
191
|
+
|
|
192
|
+
Returns:
|
|
193
|
+
Dict: The updated scene data.
|
|
194
|
+
|
|
195
|
+
Raises:
|
|
196
|
+
ApiRequestError: If the API request fails.
|
|
197
|
+
ValidationError: If the scene data is invalid.
|
|
198
|
+
|
|
199
|
+
Example:
|
|
200
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
201
|
+
>>> from geobox.aio.scene import Scene
|
|
202
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
203
|
+
>>> scene = await Scene.get_scene(client, uuid="12345678-1234-5678-1234-567812345678")
|
|
204
|
+
>>> await scene.update(display_name="New Display Name")
|
|
205
|
+
"""
|
|
206
|
+
data = {
|
|
207
|
+
"name": kwargs.get('name'),
|
|
208
|
+
"display_name": kwargs.get('display_name'),
|
|
209
|
+
"description": kwargs.get('description'),
|
|
210
|
+
"settings": kwargs.get('settings'),
|
|
211
|
+
"thumbnail": kwargs.get('thumbnail')
|
|
212
|
+
}
|
|
213
|
+
return await super()._update(self.endpoint, data)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
async def delete(self) -> None:
|
|
217
|
+
"""
|
|
218
|
+
[async] Delete the scene.
|
|
219
|
+
|
|
220
|
+
Returns:
|
|
221
|
+
None
|
|
222
|
+
|
|
223
|
+
Example:
|
|
224
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
225
|
+
>>> from geobox.aio.scene import Scene
|
|
226
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
227
|
+
>>> scene = await Scene.get_scene(client, uuid="12345678-1234-5678-1234-567812345678")
|
|
228
|
+
>>> await scene.delete()
|
|
229
|
+
"""
|
|
230
|
+
await super().delete(self.endpoint)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
@property
|
|
234
|
+
def thumbnail(self) -> str:
|
|
235
|
+
"""
|
|
236
|
+
Get the thumbnail URL of the scene.
|
|
237
|
+
|
|
238
|
+
Returns:
|
|
239
|
+
str: The thumbnail of the scene.
|
|
240
|
+
|
|
241
|
+
Example:
|
|
242
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
243
|
+
>>> from geobox.aio.scene import Scene
|
|
244
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
245
|
+
>>> scene = await Scene.get_scene(client, uuid="12345678-1234-5678-1234-567812345678")
|
|
246
|
+
>>> scene.thumbnail
|
|
247
|
+
'https://example.com/thumbnail.png'
|
|
248
|
+
"""
|
|
249
|
+
return super().thumbnail()
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
async def share(self, users: List['User']) -> None:
|
|
253
|
+
"""
|
|
254
|
+
[async] Shares the scene with specified users.
|
|
255
|
+
|
|
256
|
+
Args:
|
|
257
|
+
users (List[User]): The list of user objects to share the scene with.
|
|
258
|
+
|
|
259
|
+
Returns:
|
|
260
|
+
None
|
|
261
|
+
|
|
262
|
+
Example:
|
|
263
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
264
|
+
>>> from geobox.aio.scene import Scene
|
|
265
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
266
|
+
>>> scene = await Scene.get_scene(client, uuid="12345678-1234-5678-1234-567812345678")
|
|
267
|
+
>>> users = await client.search_users(search='John')
|
|
268
|
+
>>> await scene.share(users=users)
|
|
269
|
+
"""
|
|
270
|
+
await super()._share(self.endpoint, users)
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
async def unshare(self, users: List['User']) -> None:
|
|
274
|
+
"""
|
|
275
|
+
[async] Unshares the scene with specified users.
|
|
276
|
+
|
|
277
|
+
Args:
|
|
278
|
+
users (List[User]): The list of user objects to unshare the scene with.
|
|
279
|
+
|
|
280
|
+
Returns:
|
|
281
|
+
None
|
|
282
|
+
|
|
283
|
+
Example:
|
|
284
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
285
|
+
>>> from geobox.aio.scene import Scene
|
|
286
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
287
|
+
>>> scene = await Scene.get_scene(client, uuid="12345678-1234-5678-1234-567812345678")
|
|
288
|
+
>>> users = await client.search_users(search='John')
|
|
289
|
+
>>> await scene.unshare(users=users)
|
|
290
|
+
"""
|
|
291
|
+
await super()._unshare(self.endpoint, users)
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
async def get_shared_users(self, search: str = None, skip: int = 0, limit: int = 10) -> List['User']:
|
|
295
|
+
"""
|
|
296
|
+
[async] Retrieves the list of users the scene is shared with.
|
|
297
|
+
|
|
298
|
+
Args:
|
|
299
|
+
search (str, optional): The search query.
|
|
300
|
+
skip (int, optional): The number of users to skip.
|
|
301
|
+
limit (int, optional): The maximum number of users to retrieve.
|
|
302
|
+
|
|
303
|
+
Returns:
|
|
304
|
+
List[User]: The list of shared users.
|
|
305
|
+
|
|
306
|
+
Example:
|
|
307
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
308
|
+
>>> from geobox.aio.scene import Scene
|
|
309
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
310
|
+
>>> scene = await Scene.get_scene(client, uuid="12345678-1234-5678-1234-567812345678")
|
|
311
|
+
>>> await scene.get_shared_users(search='John', skip=0, limit=10)
|
|
312
|
+
"""
|
|
313
|
+
params = {
|
|
314
|
+
'search': search,
|
|
315
|
+
'skip': skip,
|
|
316
|
+
'limit': limit
|
|
317
|
+
}
|
|
318
|
+
return await super()._get_shared_users(self.endpoint, params)
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def to_sync(self, sync_client: 'SyncGeoboxClient') -> 'SyncScene':
|
|
322
|
+
"""
|
|
323
|
+
Switch to sync version of the scene instance to have access to the sync methods
|
|
324
|
+
|
|
325
|
+
Args:
|
|
326
|
+
sync_client (SyncGeoboxClient): The sync version of the GeoboxClient instance for making requests.
|
|
327
|
+
|
|
328
|
+
Returns:
|
|
329
|
+
geobox.scene.Scene: the sync instance of the scene.
|
|
330
|
+
|
|
331
|
+
Example:
|
|
332
|
+
>>> from geobox import Geoboxclient
|
|
333
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
334
|
+
>>> from geobox.aio.scene import Scene
|
|
335
|
+
>>> client = GeoboxClient()
|
|
336
|
+
>>> async with AsyncGeoboxClient() as async_client:
|
|
337
|
+
>>> scene = await Scene.get_scene(async_client, uuid="12345678-1234-5678-1234-567812345678")
|
|
338
|
+
>>> sync_scene = scene.to_sync(client)
|
|
339
|
+
"""
|
|
340
|
+
from ..scene import Scene as SyncScene
|
|
341
|
+
|
|
342
|
+
return SyncScene(api=sync_client, uuid=self.uuid, data=self.data)
|
geobox/aio/settings.py
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
from typing import List, Dict, Optional, TYPE_CHECKING
|
|
2
|
+
from urllib.parse import urljoin, urlencode
|
|
3
|
+
|
|
4
|
+
from .base import AsyncBase
|
|
5
|
+
from ..utils import clean_data
|
|
6
|
+
from ..enums import MaxLogPolicy, InvalidDataPolicy, LoginFailurePolicy, MaxConcurrentSessionPolicy
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from . import AsyncGeoboxClient
|
|
10
|
+
from ..api import GeoboxClient as SyncGeoboxClient
|
|
11
|
+
from ..settings import SystemSettings as SyncSystemSettings
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class SystemSettings(AsyncBase):
|
|
15
|
+
|
|
16
|
+
BASE_ENDPOINT = 'settings/'
|
|
17
|
+
|
|
18
|
+
def __init__(self,
|
|
19
|
+
api: 'AsyncGeoboxClient',
|
|
20
|
+
data: Optional[Dict] = {}):
|
|
21
|
+
"""
|
|
22
|
+
Initialize a System Settings instance.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
|
|
26
|
+
data (Dict, optional): The data of the Setting.
|
|
27
|
+
"""
|
|
28
|
+
super().__init__(api, data=data)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def max_log_policy(self) -> 'MaxLogPolicy':
|
|
33
|
+
"""
|
|
34
|
+
Get max log policy
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
MaxLogPolicy: max log policy
|
|
38
|
+
"""
|
|
39
|
+
return MaxLogPolicy(self.data.get('max_log_policy'))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def invalid_data_policy(self) -> 'InvalidDataPolicy':
|
|
44
|
+
"""
|
|
45
|
+
Get invalid data policy
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
InvalidDataPolicy: invalid data policy
|
|
49
|
+
"""
|
|
50
|
+
return InvalidDataPolicy(self.data.get('invalid_data_policy'))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def login_failure_policy(self) -> 'LoginFailurePolicy':
|
|
55
|
+
"""
|
|
56
|
+
Get login failure policy
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
LoginFailurePolicy: login failure policy
|
|
60
|
+
"""
|
|
61
|
+
return LoginFailurePolicy(self.data.get('login_failure_policy'))
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def max_concurrent_session_policy(self) -> 'MaxConcurrentSessionPolicy':
|
|
66
|
+
"""
|
|
67
|
+
Get max concurrent sessions
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
MaxConcurrentSessionPolicy: max concurrent sessions
|
|
71
|
+
"""
|
|
72
|
+
return MaxConcurrentSessionPolicy(self.data.get('max_concurrent_session_policy'))
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def __repr__(self) -> str:
|
|
76
|
+
"""
|
|
77
|
+
Return a string representation of the system setting instance.
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
str: A string representation of the system setting instance.
|
|
81
|
+
"""
|
|
82
|
+
return "SystemSettings()"
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@classmethod
|
|
86
|
+
async def get_system_settings(cls, api: 'AsyncGeoboxClient') -> 'SystemSettings':
|
|
87
|
+
"""
|
|
88
|
+
[async] Get System Settings object (Permission Required).
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
|
|
92
|
+
|
|
93
|
+
Returns:
|
|
94
|
+
SystemSetting: the system settings object.
|
|
95
|
+
|
|
96
|
+
Example:
|
|
97
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
98
|
+
>>> from geobox.aio.setting import SystemSettings
|
|
99
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
100
|
+
>>> setting = await SystemSettings.get_system_settings(client)
|
|
101
|
+
or
|
|
102
|
+
>>> setting = await client.get_system_settings()
|
|
103
|
+
"""
|
|
104
|
+
params = clean_data({
|
|
105
|
+
'f': 'json'
|
|
106
|
+
})
|
|
107
|
+
query_string = urlencode(params)
|
|
108
|
+
endpoint = urljoin(cls.BASE_ENDPOINT, f"?{query_string}")
|
|
109
|
+
response = await api.get(endpoint)
|
|
110
|
+
return SystemSettings(api, response)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
async def update(self, **kwargs) -> Dict:
|
|
114
|
+
"""
|
|
115
|
+
[async] Update the system settings.
|
|
116
|
+
|
|
117
|
+
Keyword Args:
|
|
118
|
+
brand_name (str)
|
|
119
|
+
brand_website (str)
|
|
120
|
+
max_log (int)
|
|
121
|
+
max_log_policy (MaxLogPolicy)
|
|
122
|
+
users_can_view_their_own_logs (bool)
|
|
123
|
+
max_upload_file_size (int)
|
|
124
|
+
invalid_data_policy (InvalidDataPolicy)
|
|
125
|
+
max_login_attempts (int)
|
|
126
|
+
login_failure_policy (LoginFailurePolicy)
|
|
127
|
+
login_attempts_duration (int)
|
|
128
|
+
min_password_length (int)
|
|
129
|
+
max_concurrent_session (int)
|
|
130
|
+
max_concurrent_session_policy (MaxConcurrentSessionPolicy)
|
|
131
|
+
session_timeout (int)
|
|
132
|
+
allowed_ip_addresses (Dict)
|
|
133
|
+
blocked_ip_addresses (Dict)
|
|
134
|
+
|
|
135
|
+
Returns:
|
|
136
|
+
Dict: The updated system settings data.
|
|
137
|
+
|
|
138
|
+
Raises:
|
|
139
|
+
ValidationError: If the system settings data is invalid.
|
|
140
|
+
|
|
141
|
+
Example:
|
|
142
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
143
|
+
>>> from geobox.aio.setting import SystemSettings
|
|
144
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
145
|
+
>>> settings = await SystemSetting.get_system_settings(client)
|
|
146
|
+
or
|
|
147
|
+
>>> settings = await client.get_system_settings()
|
|
148
|
+
>>> await settings.update(max_log=100000)
|
|
149
|
+
"""
|
|
150
|
+
data = {
|
|
151
|
+
"brand_name": kwargs.get('brand_name'),
|
|
152
|
+
"brand_website": kwargs.get('brand_website'),
|
|
153
|
+
"max_log": kwargs.get('max_log'),
|
|
154
|
+
"max_log_policy": kwargs.get('max_log_policy').value if kwargs.get('max_log_policy') else None,
|
|
155
|
+
"max_upload_file_size": kwargs.get('max_upload_file_size'),
|
|
156
|
+
"invalid_data_policy": kwargs.get('invalid_data_policy').value if kwargs.get('invalid_data_policy') else None,
|
|
157
|
+
"max_login_attempts": kwargs.get('max_login_attempts'),
|
|
158
|
+
"login_failure_policy": kwargs.get('login_failure_policy').value if kwargs.get('login_failure_policy') else None,
|
|
159
|
+
"login_attempts_duration": kwargs.get('login_attempts_duration'),
|
|
160
|
+
"min_password_length": kwargs.get('min_password_length'),
|
|
161
|
+
"max_concurrent_session": kwargs.get('max_concurrent_session'),
|
|
162
|
+
"max_concurrent_session_policy": kwargs.get('max_concurrent_session_policy').value if kwargs.get('max_concurrent_session_policy') else None,
|
|
163
|
+
"session_timeout": kwargs.get('session_timeout'),
|
|
164
|
+
"allowed_ip_addresses": kwargs.get('allowed_ip_addresses'),
|
|
165
|
+
"blocked_ip_addresses": kwargs.get('blocked_ip_addresses'),
|
|
166
|
+
|
|
167
|
+
}
|
|
168
|
+
return await super()._update(self.BASE_ENDPOINT, data)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def to_sync(self, sync_client: 'SyncGeoboxClient') -> 'SyncSystemSettings':
|
|
172
|
+
"""
|
|
173
|
+
Switch to sync version of the system settings instance to have access to the sync methods
|
|
174
|
+
|
|
175
|
+
Args:
|
|
176
|
+
sync_client (SyncGeoboxClient): The sync version of the GeoboxClient instance for making requests.
|
|
177
|
+
|
|
178
|
+
Returns:
|
|
179
|
+
geobox.settings.SystemSettings: the sync instance of the system settings.
|
|
180
|
+
|
|
181
|
+
Example:
|
|
182
|
+
>>> from geobox import Geoboxclient
|
|
183
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
184
|
+
>>> from geobox.aio.setting import SystemSettings
|
|
185
|
+
>>> client = GeoboxClient()
|
|
186
|
+
>>> async with AsyncGeoboxClient() as async_client:
|
|
187
|
+
>>> settings = await SystemSetting.get_system_settings(async_client)
|
|
188
|
+
or
|
|
189
|
+
>>> settings = await async_client.get_system_settings()
|
|
190
|
+
>>> sync_settings = settings.to_sync(client)
|
|
191
|
+
"""
|
|
192
|
+
from ..task import Task as SyncTask
|
|
193
|
+
|
|
194
|
+
return SyncTask(api=sync_client, uuid=self.uuid, data=self.data)
|