geobox 2.1.0__py3-none-any.whl → 2.2.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 +61 -63
- geobox/aio/__init__.py +61 -63
- geobox/aio/api.py +491 -574
- geobox/aio/apikey.py +263 -263
- geobox/aio/attachment.py +341 -339
- geobox/aio/base.py +261 -262
- geobox/aio/basemap.py +196 -196
- geobox/aio/dashboard.py +340 -342
- geobox/aio/feature.py +35 -35
- geobox/aio/field.py +315 -321
- geobox/aio/file.py +72 -72
- geobox/aio/layout.py +340 -341
- geobox/aio/log.py +23 -23
- geobox/aio/map.py +1033 -1034
- geobox/aio/model3d.py +415 -415
- geobox/aio/mosaic.py +696 -696
- geobox/aio/plan.py +314 -314
- geobox/aio/query.py +693 -693
- geobox/aio/raster.py +88 -454
- geobox/aio/{analysis.py → raster_analysis.py} +153 -170
- geobox/aio/route.py +4 -4
- geobox/aio/scene.py +340 -342
- geobox/aio/settings.py +18 -18
- geobox/aio/task.py +404 -402
- geobox/aio/tile3d.py +337 -339
- geobox/aio/tileset.py +102 -103
- geobox/aio/usage.py +52 -51
- geobox/aio/user.py +506 -507
- geobox/aio/vector_tool.py +1968 -0
- geobox/aio/vectorlayer.py +316 -414
- geobox/aio/version.py +272 -273
- geobox/aio/view.py +1019 -983
- geobox/aio/workflow.py +340 -341
- geobox/api.py +14 -98
- geobox/apikey.py +262 -262
- geobox/attachment.py +336 -337
- geobox/base.py +384 -384
- geobox/basemap.py +194 -194
- geobox/dashboard.py +339 -341
- geobox/enums.py +31 -1
- geobox/feature.py +31 -10
- geobox/field.py +320 -320
- geobox/file.py +4 -4
- geobox/layout.py +339 -340
- geobox/log.py +4 -4
- geobox/map.py +1031 -1032
- geobox/model3d.py +410 -410
- geobox/mosaic.py +696 -696
- geobox/plan.py +313 -313
- geobox/query.py +691 -691
- geobox/raster.py +5 -368
- geobox/{analysis.py → raster_analysis.py} +108 -128
- geobox/scene.py +341 -342
- geobox/settings.py +194 -194
- geobox/task.py +399 -400
- geobox/tile3d.py +337 -338
- geobox/tileset.py +4 -4
- geobox/usage.py +3 -3
- geobox/user.py +503 -503
- geobox/vector_tool.py +1968 -0
- geobox/vectorlayer.py +5 -110
- geobox/version.py +272 -272
- geobox/view.py +981 -981
- geobox/workflow.py +338 -339
- {geobox-2.1.0.dist-info → geobox-2.2.1.dist-info}/METADATA +15 -1
- geobox-2.2.1.dist-info/RECORD +72 -0
- geobox-2.1.0.dist-info/RECORD +0 -70
- {geobox-2.1.0.dist-info → geobox-2.2.1.dist-info}/WHEEL +0 -0
- {geobox-2.1.0.dist-info → geobox-2.2.1.dist-info}/licenses/LICENSE +0 -0
- {geobox-2.1.0.dist-info → geobox-2.2.1.dist-info}/top_level.txt +0 -0
geobox/aio/apikey.py
CHANGED
|
@@ -1,263 +1,263 @@
|
|
|
1
|
-
from typing import List, Dict, Optional, TYPE_CHECKING
|
|
2
|
-
from urllib.parse import urljoin
|
|
3
|
-
|
|
4
|
-
from .base import AsyncBase
|
|
5
|
-
from ..utils import clean_data
|
|
6
|
-
|
|
7
|
-
if TYPE_CHECKING:
|
|
8
|
-
from . import AsyncGeoboxClient
|
|
9
|
-
from ..api import GeoboxClient
|
|
10
|
-
from ..apikey import ApiKey
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class
|
|
14
|
-
|
|
15
|
-
BASE_ENDPOINT = 'apikeys/'
|
|
16
|
-
|
|
17
|
-
def __init__(self,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"""
|
|
22
|
-
Initialize an apikey instance.
|
|
23
|
-
|
|
24
|
-
Args:
|
|
25
|
-
api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
|
|
26
|
-
key_id (int): The unique identifier for the apikey.
|
|
27
|
-
data (Dict, optional): The data of the apikey.
|
|
28
|
-
"""
|
|
29
|
-
super().__init__(api, data=data)
|
|
30
|
-
self.key_id = key_id
|
|
31
|
-
self.endpoint = urljoin(self.BASE_ENDPOINT, str(self.id))
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def __repr__(self) -> str:
|
|
35
|
-
"""
|
|
36
|
-
Return a string representation of the attachment.
|
|
37
|
-
|
|
38
|
-
Returns:
|
|
39
|
-
str: The string representation of the attachment.
|
|
40
|
-
"""
|
|
41
|
-
return f'
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
@classmethod
|
|
45
|
-
async def get_apikeys(cls, api: 'AsyncGeoboxClient', **kwargs) -> List['
|
|
46
|
-
"""
|
|
47
|
-
[async] Get a list of apikeys
|
|
48
|
-
|
|
49
|
-
Args:
|
|
50
|
-
api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
|
|
51
|
-
|
|
52
|
-
Keyword Args:
|
|
53
|
-
search (str): search term for keyword-based searching among all textual fields.
|
|
54
|
-
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.
|
|
55
|
-
skip (int): Number of layers to skip. default is 0.
|
|
56
|
-
limit (int): Maximum number of layers to return. default is 10.
|
|
57
|
-
user_id (int): Specific user. privileges required.
|
|
58
|
-
|
|
59
|
-
Example:
|
|
60
|
-
>>> from geobox.aio import AsyncGeoboxClient
|
|
61
|
-
>>> from geobox.aio.apikey import
|
|
62
|
-
>>> async with AsyncGeoboxClient() as client:
|
|
63
|
-
>>> apikeys = await
|
|
64
|
-
or
|
|
65
|
-
>>> apikeys = await client.get_apikeys()
|
|
66
|
-
"""
|
|
67
|
-
params = {
|
|
68
|
-
'search': kwargs.get('search'),
|
|
69
|
-
'order_by': kwargs.get('order_by'),
|
|
70
|
-
'skip': kwargs.get('skip'),
|
|
71
|
-
'limit': kwargs.get('limit'),
|
|
72
|
-
'user_id': kwargs.get('user_id')
|
|
73
|
-
}
|
|
74
|
-
return await super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
@classmethod
|
|
78
|
-
async def create_apikey(cls, api: 'AsyncGeoboxClient', name: str, user_id: int = None) -> '
|
|
79
|
-
"""
|
|
80
|
-
[async] Create an ApiKey
|
|
81
|
-
|
|
82
|
-
Args:
|
|
83
|
-
api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
|
|
84
|
-
name (str): name of the key.
|
|
85
|
-
user_id (int, optional): Specific user. privileges required.
|
|
86
|
-
|
|
87
|
-
Returns:
|
|
88
|
-
ApiKey: the apikey object
|
|
89
|
-
|
|
90
|
-
Example:
|
|
91
|
-
>>> from geobox.aio import AsyncGeoboxClient
|
|
92
|
-
>>> from geobox.aio.apikey import
|
|
93
|
-
>>> async with AsyncGeoboxClient() as client:
|
|
94
|
-
>>> apikey = await
|
|
95
|
-
or
|
|
96
|
-
>>> apikey = await client.create_apikey(name='test')
|
|
97
|
-
"""
|
|
98
|
-
data = clean_data({
|
|
99
|
-
'name': name,
|
|
100
|
-
'user_id': user_id
|
|
101
|
-
})
|
|
102
|
-
response = await api.post(cls.BASE_ENDPOINT, payload=data, is_json=False)
|
|
103
|
-
return
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
@classmethod
|
|
107
|
-
async def get_apikey(cls, api: 'AsyncGeoboxClient', key_id: int) -> '
|
|
108
|
-
"""
|
|
109
|
-
[async] Get an ApiKey
|
|
110
|
-
|
|
111
|
-
Args:
|
|
112
|
-
api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
|
|
113
|
-
key_id (str): the id of the apikey.
|
|
114
|
-
|
|
115
|
-
Returns:
|
|
116
|
-
ApiKey: the ApiKey object
|
|
117
|
-
|
|
118
|
-
Example:
|
|
119
|
-
>>> from geobox.aio import AsyncGeoboxClient
|
|
120
|
-
>>> from geobox.aio.apikey import
|
|
121
|
-
>>> async with AsyncGeoboxClient() as client:
|
|
122
|
-
>>> apikey = await
|
|
123
|
-
or
|
|
124
|
-
>>> apikey = await client.get_apikey(key_id=1)
|
|
125
|
-
"""
|
|
126
|
-
params = {
|
|
127
|
-
'f': 'json'
|
|
128
|
-
}
|
|
129
|
-
return await super()._get_detail(api=api,
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
@classmethod
|
|
137
|
-
async def get_apikey_by_name(cls, api: 'AsyncGeoboxClient', name: str, user_id: int = None) -> '
|
|
138
|
-
"""
|
|
139
|
-
[async] Get an ApiKey by name
|
|
140
|
-
|
|
141
|
-
Args:
|
|
142
|
-
api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
|
|
143
|
-
name (str): the name of the key to get
|
|
144
|
-
user_id (int, optional): specific user. privileges required.
|
|
145
|
-
|
|
146
|
-
Returns:
|
|
147
|
-
ApiKey | None: returns the key if a key matches the given name, else None
|
|
148
|
-
|
|
149
|
-
Example:
|
|
150
|
-
>>> from geobox.aio import AsyncGeoboxClient
|
|
151
|
-
>>> from geobox.aio.apikey import
|
|
152
|
-
>>> async with AsyncGeoboxClient() as client:
|
|
153
|
-
>>> apikey = await
|
|
154
|
-
or
|
|
155
|
-
>>> apikey = await client.get_apikey_by_name(name='test')
|
|
156
|
-
"""
|
|
157
|
-
apikeys = await cls.get_apikeys(api, search=name, user_id=user_id)
|
|
158
|
-
if apikeys and apikeys[0].name == name:
|
|
159
|
-
return apikeys[0]
|
|
160
|
-
else:
|
|
161
|
-
return None
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
async def update(self, name: str, user_id: int = None) -> Dict:
|
|
165
|
-
"""
|
|
166
|
-
[async] Update an ApiKey
|
|
167
|
-
|
|
168
|
-
Args:
|
|
169
|
-
name (str): the name of the key
|
|
170
|
-
user_id (int, optional): Specific user. privileges required.
|
|
171
|
-
|
|
172
|
-
Returns:
|
|
173
|
-
Dict: Updated ApiKey data
|
|
174
|
-
|
|
175
|
-
Example:
|
|
176
|
-
>>> from geobox.aio import AsyncGeoboxClient
|
|
177
|
-
>>> from geobox.aio.apikey import
|
|
178
|
-
>>> async with AsyncGeoboxClient() as client:
|
|
179
|
-
>>> apikey = await
|
|
180
|
-
>>> await apikey.update(name="updated_name")
|
|
181
|
-
"""
|
|
182
|
-
data = clean_data({
|
|
183
|
-
"name": name,
|
|
184
|
-
"user_id": user_id
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
response = await self.api.put(self.endpoint, data, is_json=False)
|
|
188
|
-
self._update_properties(response)
|
|
189
|
-
return response
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
async def delete(self) -> None:
|
|
193
|
-
"""
|
|
194
|
-
[async] Delete the ApiKey.
|
|
195
|
-
|
|
196
|
-
Returns:
|
|
197
|
-
None
|
|
198
|
-
|
|
199
|
-
Example:
|
|
200
|
-
>>> from geobox.aio import AsyncGeoboxClient
|
|
201
|
-
>>> from geobox.aio.apikey import
|
|
202
|
-
>>> async with AsyncGeoboxClient() as client:
|
|
203
|
-
>>> apikey = await
|
|
204
|
-
>>> await apikey.delete()
|
|
205
|
-
"""
|
|
206
|
-
await super().
|
|
207
|
-
self.key_id = None
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
async def revoke(self) -> None:
|
|
211
|
-
"""
|
|
212
|
-
[async] Revoke an ApiKey
|
|
213
|
-
|
|
214
|
-
Example:
|
|
215
|
-
>>> from geobox.aio import AsyncGeoboxClient
|
|
216
|
-
>>> from geobox.aio.apikey import
|
|
217
|
-
>>> async with AsyncGeoboxClient() as client:
|
|
218
|
-
>>> apikey = await
|
|
219
|
-
>>> await apikey.revoke()
|
|
220
|
-
"""
|
|
221
|
-
endpoint = f"{self.endpoint}/revoke"
|
|
222
|
-
await self.api.post(endpoint)
|
|
223
|
-
self.data['revoked'] = True
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
async def grant(self) -> None:
|
|
227
|
-
"""
|
|
228
|
-
[async] Grant an ApiKey
|
|
229
|
-
|
|
230
|
-
Example:
|
|
231
|
-
>>> from geobox.aio import AsyncGeoboxClient
|
|
232
|
-
>>> from geobox.aio.apikey import
|
|
233
|
-
>>> async with AsyncGeoboxClient() as client:
|
|
234
|
-
>>> apikey = await
|
|
235
|
-
>>> await apikey.grant()
|
|
236
|
-
"""
|
|
237
|
-
endpoint = f"{self.endpoint}/grant"
|
|
238
|
-
await self.api.post(endpoint)
|
|
239
|
-
self.data['revoked'] = False
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
def to_sync(self, sync_client: '
|
|
243
|
-
"""
|
|
244
|
-
Switch to sync version of the apikey instance to have access to the sync methods
|
|
245
|
-
|
|
246
|
-
Args:
|
|
247
|
-
sync_client (
|
|
248
|
-
|
|
249
|
-
Returns:
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
Example:
|
|
253
|
-
>>> from geobox import Geoboxclient
|
|
254
|
-
>>> from geobox.aio import AsyncGeoboxClient
|
|
255
|
-
>>> from geobox.aio.apikey import
|
|
256
|
-
>>> client = GeoboxClient()
|
|
257
|
-
>>> async with AsyncGeoboxClient() as async_client:
|
|
258
|
-
>>> apikey = await
|
|
259
|
-
>>> sync_apikey = apikey.to_sync(client)
|
|
260
|
-
"""
|
|
261
|
-
from ..apikey import ApiKey
|
|
262
|
-
|
|
263
|
-
return
|
|
1
|
+
from typing import List, Dict, Optional, TYPE_CHECKING
|
|
2
|
+
from urllib.parse import urljoin
|
|
3
|
+
|
|
4
|
+
from .base import AsyncBase
|
|
5
|
+
from ..utils import clean_data
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from . import AsyncGeoboxClient
|
|
9
|
+
from ..api import GeoboxClient
|
|
10
|
+
from ..apikey import ApiKey
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AsyncApiKey(AsyncBase):
|
|
14
|
+
|
|
15
|
+
BASE_ENDPOINT = 'apikeys/'
|
|
16
|
+
|
|
17
|
+
def __init__(self,
|
|
18
|
+
api: 'AsyncGeoboxClient',
|
|
19
|
+
key_id: int,
|
|
20
|
+
data: Optional[Dict] = {}):
|
|
21
|
+
"""
|
|
22
|
+
Initialize an apikey instance.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
|
|
26
|
+
key_id (int): The unique identifier for the apikey.
|
|
27
|
+
data (Dict, optional): The data of the apikey.
|
|
28
|
+
"""
|
|
29
|
+
super().__init__(api, data=data)
|
|
30
|
+
self.key_id = key_id
|
|
31
|
+
self.endpoint = urljoin(self.BASE_ENDPOINT, str(self.id))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def __repr__(self) -> str:
|
|
35
|
+
"""
|
|
36
|
+
Return a string representation of the attachment.
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
str: The string representation of the attachment.
|
|
40
|
+
"""
|
|
41
|
+
return f'AsyncApiKey(id={self.key_id}, name={self.name}, revoked={self.revoked})'
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@classmethod
|
|
45
|
+
async def get_apikeys(cls, api: 'AsyncGeoboxClient', **kwargs) -> List['AsyncApiKey']:
|
|
46
|
+
"""
|
|
47
|
+
[async] Get a list of apikeys
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
|
|
51
|
+
|
|
52
|
+
Keyword Args:
|
|
53
|
+
search (str): search term for keyword-based searching among all textual fields.
|
|
54
|
+
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.
|
|
55
|
+
skip (int): Number of layers to skip. default is 0.
|
|
56
|
+
limit (int): Maximum number of layers to return. default is 10.
|
|
57
|
+
user_id (int): Specific user. privileges required.
|
|
58
|
+
|
|
59
|
+
Example:
|
|
60
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
61
|
+
>>> from geobox.aio.apikey import AsyncApiKey
|
|
62
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
63
|
+
>>> apikeys = await AsyncApiKey.get_apikeys(client)
|
|
64
|
+
or
|
|
65
|
+
>>> apikeys = await client.get_apikeys()
|
|
66
|
+
"""
|
|
67
|
+
params = {
|
|
68
|
+
'search': kwargs.get('search'),
|
|
69
|
+
'order_by': kwargs.get('order_by'),
|
|
70
|
+
'skip': kwargs.get('skip'),
|
|
71
|
+
'limit': kwargs.get('limit'),
|
|
72
|
+
'user_id': kwargs.get('user_id')
|
|
73
|
+
}
|
|
74
|
+
return await super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: AsyncApiKey(api, item['id'], item))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@classmethod
|
|
78
|
+
async def create_apikey(cls, api: 'AsyncGeoboxClient', name: str, user_id: int = None) -> 'AsyncApiKey':
|
|
79
|
+
"""
|
|
80
|
+
[async] Create an ApiKey
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
|
|
84
|
+
name (str): name of the key.
|
|
85
|
+
user_id (int, optional): Specific user. privileges required.
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
ApiKey: the apikey object
|
|
89
|
+
|
|
90
|
+
Example:
|
|
91
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
92
|
+
>>> from geobox.aio.apikey import AsyncApiKey
|
|
93
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
94
|
+
>>> apikey = await AsyncApiKey.create_apikey(client, name='test')
|
|
95
|
+
or
|
|
96
|
+
>>> apikey = await client.create_apikey(name='test')
|
|
97
|
+
"""
|
|
98
|
+
data = clean_data({
|
|
99
|
+
'name': name,
|
|
100
|
+
'user_id': user_id
|
|
101
|
+
})
|
|
102
|
+
response = await api.post(cls.BASE_ENDPOINT, payload=data, is_json=False)
|
|
103
|
+
return AsyncApiKey(api, response['id'], response)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
@classmethod
|
|
107
|
+
async def get_apikey(cls, api: 'AsyncGeoboxClient', key_id: int) -> 'AsyncApiKey':
|
|
108
|
+
"""
|
|
109
|
+
[async] Get an ApiKey
|
|
110
|
+
|
|
111
|
+
Args:
|
|
112
|
+
api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
|
|
113
|
+
key_id (str): the id of the apikey.
|
|
114
|
+
|
|
115
|
+
Returns:
|
|
116
|
+
ApiKey: the ApiKey object
|
|
117
|
+
|
|
118
|
+
Example:
|
|
119
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
120
|
+
>>> from geobox.aio.apikey import AsyncApiKey
|
|
121
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
122
|
+
>>> apikey = await AsyncApiKey.get_apikey(client, key_id=1)
|
|
123
|
+
or
|
|
124
|
+
>>> apikey = await client.get_apikey(key_id=1)
|
|
125
|
+
"""
|
|
126
|
+
params = {
|
|
127
|
+
'f': 'json'
|
|
128
|
+
}
|
|
129
|
+
return await super()._get_detail(api=api,
|
|
130
|
+
endpoint=cls.BASE_ENDPOINT,
|
|
131
|
+
uuid=key_id,
|
|
132
|
+
params=params,
|
|
133
|
+
factory_func=lambda api, item: AsyncApiKey(api, item['id'], item))
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
@classmethod
|
|
137
|
+
async def get_apikey_by_name(cls, api: 'AsyncGeoboxClient', name: str, user_id: int = None) -> 'AsyncApiKey':
|
|
138
|
+
"""
|
|
139
|
+
[async] Get an ApiKey by name
|
|
140
|
+
|
|
141
|
+
Args:
|
|
142
|
+
api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
|
|
143
|
+
name (str): the name of the key to get
|
|
144
|
+
user_id (int, optional): specific user. privileges required.
|
|
145
|
+
|
|
146
|
+
Returns:
|
|
147
|
+
ApiKey | None: returns the key if a key matches the given name, else None
|
|
148
|
+
|
|
149
|
+
Example:
|
|
150
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
151
|
+
>>> from geobox.aio.apikey import AsyncApiKey
|
|
152
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
153
|
+
>>> apikey = await AsyncApiKey.get_apikey_by_name(client, name='test')
|
|
154
|
+
or
|
|
155
|
+
>>> apikey = await client.get_apikey_by_name(name='test')
|
|
156
|
+
"""
|
|
157
|
+
apikeys = await cls.get_apikeys(api, search=name, user_id=user_id)
|
|
158
|
+
if apikeys and apikeys[0].name == name:
|
|
159
|
+
return apikeys[0]
|
|
160
|
+
else:
|
|
161
|
+
return None
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
async def update(self, name: str, user_id: int = None) -> Dict:
|
|
165
|
+
"""
|
|
166
|
+
[async] Update an ApiKey
|
|
167
|
+
|
|
168
|
+
Args:
|
|
169
|
+
name (str): the name of the key
|
|
170
|
+
user_id (int, optional): Specific user. privileges required.
|
|
171
|
+
|
|
172
|
+
Returns:
|
|
173
|
+
Dict: Updated ApiKey data
|
|
174
|
+
|
|
175
|
+
Example:
|
|
176
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
177
|
+
>>> from geobox.aio.apikey import AsyncApiKey
|
|
178
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
179
|
+
>>> apikey = await AsyncApiKey.get_apikey(client, key_id=1)
|
|
180
|
+
>>> await apikey.update(name="updated_name")
|
|
181
|
+
"""
|
|
182
|
+
data = clean_data({
|
|
183
|
+
"name": name,
|
|
184
|
+
"user_id": user_id
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
response = await self.api.put(self.endpoint, data, is_json=False)
|
|
188
|
+
self._update_properties(response)
|
|
189
|
+
return response
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
async def delete(self) -> None:
|
|
193
|
+
"""
|
|
194
|
+
[async] Delete the ApiKey.
|
|
195
|
+
|
|
196
|
+
Returns:
|
|
197
|
+
None
|
|
198
|
+
|
|
199
|
+
Example:
|
|
200
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
201
|
+
>>> from geobox.aio.apikey import AsyncApiKey
|
|
202
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
203
|
+
>>> apikey = await AsyncApiKey.get_apikey(client, key_id=1)
|
|
204
|
+
>>> await apikey.delete()
|
|
205
|
+
"""
|
|
206
|
+
await super()._delete(self.endpoint)
|
|
207
|
+
self.key_id = None
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
async def revoke(self) -> None:
|
|
211
|
+
"""
|
|
212
|
+
[async] Revoke an ApiKey
|
|
213
|
+
|
|
214
|
+
Example:
|
|
215
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
216
|
+
>>> from geobox.aio.apikey import AsyncApiKey
|
|
217
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
218
|
+
>>> apikey = await AsyncApiKey.get_apikey(client, key_id=1)
|
|
219
|
+
>>> await apikey.revoke()
|
|
220
|
+
"""
|
|
221
|
+
endpoint = f"{self.endpoint}/revoke"
|
|
222
|
+
await self.api.post(endpoint)
|
|
223
|
+
self.data['revoked'] = True
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
async def grant(self) -> None:
|
|
227
|
+
"""
|
|
228
|
+
[async] Grant an ApiKey
|
|
229
|
+
|
|
230
|
+
Example:
|
|
231
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
232
|
+
>>> from geobox.aio.apikey import AsyncApiKey
|
|
233
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
234
|
+
>>> apikey = await AsyncApiKey.get_apikey(client, key_id=1)
|
|
235
|
+
>>> await apikey.grant()
|
|
236
|
+
"""
|
|
237
|
+
endpoint = f"{self.endpoint}/grant"
|
|
238
|
+
await self.api.post(endpoint)
|
|
239
|
+
self.data['revoked'] = False
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def to_sync(self, sync_client: 'GeoboxClient') -> 'ApiKey':
|
|
243
|
+
"""
|
|
244
|
+
Switch to sync version of the apikey instance to have access to the sync methods
|
|
245
|
+
|
|
246
|
+
Args:
|
|
247
|
+
sync_client (GeoboxClient): The sync version of the GeoboxClient instance for making requests.
|
|
248
|
+
|
|
249
|
+
Returns:
|
|
250
|
+
ApiKey: the sync instance of the apikey.
|
|
251
|
+
|
|
252
|
+
Example:
|
|
253
|
+
>>> from geobox import Geoboxclient
|
|
254
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
255
|
+
>>> from geobox.aio.apikey import AsyncApiKey
|
|
256
|
+
>>> client = GeoboxClient()
|
|
257
|
+
>>> async with AsyncGeoboxClient() as async_client:
|
|
258
|
+
>>> apikey = await AsyncApiKey.get_apikey(async_client, key_id=1)
|
|
259
|
+
>>> sync_apikey = apikey.to_sync(client)
|
|
260
|
+
"""
|
|
261
|
+
from ..apikey import ApiKey
|
|
262
|
+
|
|
263
|
+
return ApiKey(api=sync_client, key_id=self.key_id, data=self.data)
|