hydroserverpy 1.0.0__tar.gz → 1.1.0__tar.gz
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.
Potentially problematic release.
This version of hydroserverpy might be problematic. Click here for more details.
- {hydroserverpy-1.0.0/src/hydroserverpy.egg-info → hydroserverpy-1.1.0}/PKG-INFO +1 -1
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/setup.cfg +1 -1
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/main.py +1 -1
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/models/__init__.py +2 -0
- hydroserverpy-1.1.0/src/hydroserverpy/api/models/iam/apikey.py +77 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/models/iam/workspace.py +75 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/services/iam/workspace.py +111 -2
- hydroserverpy-1.1.0/src/hydroserverpy/etl/extractors/http_extractor.py +99 -0
- hydroserverpy-1.1.0/src/hydroserverpy/etl/extractors/local_file_extractor.py +29 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/etl/loaders/hydroserver_loader.py +39 -16
- hydroserverpy-1.1.0/src/hydroserverpy/etl/transformers/base.py +117 -0
- hydroserverpy-1.1.0/src/hydroserverpy/etl/transformers/csv_transformer.py +77 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/etl/transformers/json_transformer.py +6 -26
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0/src/hydroserverpy.egg-info}/PKG-INFO +1 -1
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy.egg-info/SOURCES.txt +1 -0
- hydroserverpy-1.0.0/src/hydroserverpy/etl/extractors/http_extractor.py +0 -84
- hydroserverpy-1.0.0/src/hydroserverpy/etl/extractors/local_file_extractor.py +0 -25
- hydroserverpy-1.0.0/src/hydroserverpy/etl/transformers/base.py +0 -52
- hydroserverpy-1.0.0/src/hydroserverpy/etl/transformers/csv_transformer.py +0 -88
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/LICENSE +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/README.md +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/pyproject.toml +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/setup.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/__init__.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/__init__.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/http.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/models/base.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/models/etl/__init__.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/models/etl/data_archive.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/models/etl/data_source.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/models/etl/orchestration_configuration.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/models/etl/orchestration_system.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/models/iam/__init__.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/models/iam/account.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/models/iam/collaborator.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/models/iam/role.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/models/sta/__init__.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/models/sta/datastream.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/models/sta/observed_property.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/models/sta/processing_level.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/models/sta/result_qualifier.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/models/sta/sensor.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/models/sta/thing.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/models/sta/unit.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/services/__init__.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/services/base.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/services/etl/__init__.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/services/etl/data_archive.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/services/etl/data_source.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/services/etl/orchestration_system.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/services/iam/__init__.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/services/sta/__init__.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/services/sta/datastream.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/services/sta/observed_property.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/services/sta/processing_level.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/services/sta/result_qualifier.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/services/sta/sensor.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/services/sta/thing.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/api/services/sta/unit.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/etl/__init__.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/etl/extractors/__init__.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/etl/extractors/base.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/etl/extractors/ftp_extractor.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/etl/hydroserver_etl.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/etl/loaders/__init__.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/etl/loaders/base.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/etl/transformers/__init__.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/etl/types.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/etl_csv/__init__.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/etl_csv/exceptions.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/etl_csv/hydroserver_etl_csv.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/quality/__init__.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/quality/service.py +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy.egg-info/dependency_links.txt +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy.egg-info/requires.txt +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy.egg-info/top_level.txt +0 -0
- {hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy.egg-info/zip-safe +0 -0
|
@@ -62,7 +62,7 @@ class HydroServer:
|
|
|
62
62
|
auth = auth or self.auth
|
|
63
63
|
|
|
64
64
|
if auth and auth[0] == "__key__":
|
|
65
|
-
self._session.headers.update({"
|
|
65
|
+
self._session.headers.update({"X-API-Key": auth[1]})
|
|
66
66
|
elif auth:
|
|
67
67
|
self._session.headers.update(
|
|
68
68
|
{"Authorization": f"Bearer {self._authenticate(auth[0], auth[1])}"}
|
|
@@ -2,6 +2,7 @@ from .iam.account import Account
|
|
|
2
2
|
from .iam.workspace import Workspace
|
|
3
3
|
from .iam.role import Role
|
|
4
4
|
from .iam.collaborator import Collaborator
|
|
5
|
+
from .iam.apikey import APIKey
|
|
5
6
|
from .iam.account import Account
|
|
6
7
|
from .sta.datastream import Datastream
|
|
7
8
|
from .sta.observed_property import ObservedProperty
|
|
@@ -17,5 +18,6 @@ from .etl.data_archive import DataArchive
|
|
|
17
18
|
Workspace.model_rebuild()
|
|
18
19
|
Role.model_rebuild()
|
|
19
20
|
Collaborator.model_rebuild()
|
|
21
|
+
APIKey.model_rebuild()
|
|
20
22
|
|
|
21
23
|
Unit.model_rebuild()
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
from typing import Optional, Union, TYPE_CHECKING
|
|
2
|
+
from uuid import UUID
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from pydantic import BaseModel
|
|
5
|
+
from ..base import HydroServerModel
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from hydroserverpy import HydroServer
|
|
9
|
+
from hydroserverpy.api.models import Workspace, Role
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class APIKeyFields(BaseModel):
|
|
13
|
+
name: str
|
|
14
|
+
description: Optional[str] = None
|
|
15
|
+
is_active: bool
|
|
16
|
+
expires_at: Optional[datetime] = None
|
|
17
|
+
role: "Role"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class APIKey(HydroServerModel, APIKeyFields):
|
|
21
|
+
def __init__(self, _connection: "HydroServer", _uid: Union[UUID, str], **data):
|
|
22
|
+
super().__init__(
|
|
23
|
+
_connection=_connection, _model_ref="apikeys", _uid=_uid, **data
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
self._workspace_id = str(data.get("workspace_id") or data["workspaceId"])
|
|
27
|
+
self._workspace = None
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def workspace(self) -> "Workspace":
|
|
31
|
+
"""The workspace this data source belongs to."""
|
|
32
|
+
|
|
33
|
+
if self._workspace is None and self._workspace_id:
|
|
34
|
+
self._workspace = self._connection.workspaces.get(uid=self._workspace_id)
|
|
35
|
+
|
|
36
|
+
return self._workspace
|
|
37
|
+
|
|
38
|
+
def refresh(self):
|
|
39
|
+
"""Refresh this data source from HydroServer."""
|
|
40
|
+
|
|
41
|
+
self._original_data = (
|
|
42
|
+
self._connection.workspaces.get_api_key(
|
|
43
|
+
uid=self._workspace_id, api_key_id=self.uid
|
|
44
|
+
).model_dump(exclude=["uid"])
|
|
45
|
+
)
|
|
46
|
+
self.__dict__.update(self._original_data)
|
|
47
|
+
self._workspace = None
|
|
48
|
+
|
|
49
|
+
def save(self):
|
|
50
|
+
"""Save changes to this data source to HydroServer."""
|
|
51
|
+
|
|
52
|
+
if self._patch_data:
|
|
53
|
+
api_key = self._connection.workspaces.update_api_key(
|
|
54
|
+
uid=self._workspace_id, api_key_id=self.uid, **self._patch_data
|
|
55
|
+
)
|
|
56
|
+
self._original_data = api_key.dict(by_alias=False, exclude=["uid"])
|
|
57
|
+
self.__dict__.update(self._original_data)
|
|
58
|
+
|
|
59
|
+
def delete(self):
|
|
60
|
+
"""Delete this data source from HydroServer."""
|
|
61
|
+
|
|
62
|
+
if not self._uid:
|
|
63
|
+
raise AttributeError("This resource cannot be deleted: UID is not set.")
|
|
64
|
+
|
|
65
|
+
self._connection.workspaces.delete_api_key(
|
|
66
|
+
uid=self._workspace_id, api_key_id=self.uid
|
|
67
|
+
)
|
|
68
|
+
self._uid = None
|
|
69
|
+
|
|
70
|
+
def regenerate(self):
|
|
71
|
+
"""Regenerates this API key. WARNING: Previous key will be invalidated."""
|
|
72
|
+
|
|
73
|
+
_, key = self._connection.workspaces.regenerate_api_key(
|
|
74
|
+
uid=self._workspace_id, api_key_id=self.uid
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
return key
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from typing import List, Union, Optional, TYPE_CHECKING
|
|
2
2
|
from uuid import UUID
|
|
3
|
+
from datetime import datetime
|
|
3
4
|
from pydantic import BaseModel, Field, EmailStr
|
|
4
5
|
from ..base import HydroServerModel
|
|
5
6
|
|
|
@@ -8,6 +9,7 @@ if TYPE_CHECKING:
|
|
|
8
9
|
from hydroserverpy.api.models import (
|
|
9
10
|
Role,
|
|
10
11
|
Collaborator,
|
|
12
|
+
APIKey,
|
|
11
13
|
Account,
|
|
12
14
|
Thing,
|
|
13
15
|
ObservedProperty,
|
|
@@ -189,6 +191,79 @@ class Workspace(HydroServerModel, WorkspaceFields):
|
|
|
189
191
|
|
|
190
192
|
super()._delete()
|
|
191
193
|
|
|
194
|
+
def list_api_keys(self) -> List["APIKey"]:
|
|
195
|
+
"""Get all API keys associated with this workspace."""
|
|
196
|
+
|
|
197
|
+
return self._connection.workspaces.list_api_keys(uid=self.uid)
|
|
198
|
+
|
|
199
|
+
def get_api_key(self, api_key: Union["APIKey", UUID, str]) -> "APIKey":
|
|
200
|
+
"""Get an API key associated with this workspace."""
|
|
201
|
+
|
|
202
|
+
return self._connection.workspaces.get_api_key(
|
|
203
|
+
uid=self.uid,
|
|
204
|
+
api_key_id=str(getattr(api_key, "uid", api_key))
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
def create_api_key(
|
|
208
|
+
self,
|
|
209
|
+
role: Union["Role", UUID, str],
|
|
210
|
+
name: str,
|
|
211
|
+
description: Optional[str] = None,
|
|
212
|
+
is_active: bool = True,
|
|
213
|
+
expires_at: Optional[datetime] = None
|
|
214
|
+
):
|
|
215
|
+
"""Create an API key associated with this workspace."""
|
|
216
|
+
|
|
217
|
+
api_key, key = self._connection.workspaces.create_api_key(
|
|
218
|
+
uid=self.uid,
|
|
219
|
+
role=role,
|
|
220
|
+
name=name,
|
|
221
|
+
description=description,
|
|
222
|
+
is_active=is_active,
|
|
223
|
+
expires_at=expires_at
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
return api_key, key
|
|
227
|
+
|
|
228
|
+
def update_api_key(
|
|
229
|
+
self,
|
|
230
|
+
api_key_id: Union[UUID, str],
|
|
231
|
+
role: Union["Role", UUID, str] = ...,
|
|
232
|
+
name: str = ...,
|
|
233
|
+
description: Optional[str] = ...,
|
|
234
|
+
is_active: bool = ...,
|
|
235
|
+
expires_at: Optional[datetime] = ...
|
|
236
|
+
):
|
|
237
|
+
"""Create an API key associated with this workspace."""
|
|
238
|
+
|
|
239
|
+
return self._connection.workspaces.update_api_key(
|
|
240
|
+
uid=self.uid,
|
|
241
|
+
api_key_id=api_key_id,
|
|
242
|
+
role=role,
|
|
243
|
+
name=name,
|
|
244
|
+
description=description,
|
|
245
|
+
is_active=is_active,
|
|
246
|
+
expires_at=expires_at
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
def delete_api_key(self, api_key_id: Union[UUID, str]):
|
|
250
|
+
"""Delete an API key associated with this workspace."""
|
|
251
|
+
|
|
252
|
+
return self._connection.workspaces.delete_api_key(
|
|
253
|
+
uid=self.uid,
|
|
254
|
+
api_key_id=api_key_id
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
def regenerate_api_key(self, api_key_id: Union[UUID, str]):
|
|
258
|
+
"""Regenerate an API key associated with this workspace."""
|
|
259
|
+
|
|
260
|
+
api_key, key = self._connection.workspaces.regenerate_api_key(
|
|
261
|
+
uid=self.uid,
|
|
262
|
+
api_key_id=api_key_id
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
return api_key, key
|
|
266
|
+
|
|
192
267
|
def add_collaborator(
|
|
193
268
|
self, email: EmailStr, role: Union["Role", UUID, str]
|
|
194
269
|
) -> "Collaborator":
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
from typing import TYPE_CHECKING, Union, List
|
|
1
|
+
from typing import TYPE_CHECKING, Union, List, Tuple, Optional
|
|
2
2
|
from pydantic import EmailStr
|
|
3
3
|
from uuid import UUID
|
|
4
|
-
from
|
|
4
|
+
from datetime import datetime
|
|
5
|
+
from hydroserverpy.api.models import Workspace, Role, Collaborator, APIKey
|
|
5
6
|
from ..base import EndpointService
|
|
6
7
|
|
|
7
8
|
|
|
@@ -107,6 +108,114 @@ class WorkspaceService(EndpointService):
|
|
|
107
108
|
path = f"/{self._api_route}/{self._endpoint_route}/{str(uid)}/collaborators"
|
|
108
109
|
self._connection.request("delete", path, json={"email": email})
|
|
109
110
|
|
|
111
|
+
def list_api_keys(self, uid: Union[UUID, str]) -> List["APIKey"]:
|
|
112
|
+
"""Get all API keys associated with a workspace."""
|
|
113
|
+
|
|
114
|
+
path = f"/{self._api_route}/{self._endpoint_route}/{str(uid)}/api-keys"
|
|
115
|
+
response = self._connection.request("get", path)
|
|
116
|
+
|
|
117
|
+
return [APIKey(_connection=self._connection, _uid=UUID(str(obj.pop("id"))), **obj) for obj in response.json()]
|
|
118
|
+
|
|
119
|
+
def get_api_key(self, uid: Union[UUID, str], api_key_id: Union[UUID, str]) -> "APIKey":
|
|
120
|
+
"""Get an API key associated with a workspace."""
|
|
121
|
+
|
|
122
|
+
path = f"/{self._api_route}/{self._endpoint_route}/{str(uid)}/api-keys/{api_key_id}"
|
|
123
|
+
response = self._connection.request("get", path).json()
|
|
124
|
+
|
|
125
|
+
return APIKey(_connection=self._connection, _uid=UUID(str(response.pop("id"))), **response)
|
|
126
|
+
|
|
127
|
+
def create_api_key(
|
|
128
|
+
self,
|
|
129
|
+
uid: Union[UUID, str],
|
|
130
|
+
role: Union["Role", UUID, str],
|
|
131
|
+
name: str,
|
|
132
|
+
description: Optional[str] = None,
|
|
133
|
+
is_active: bool = True,
|
|
134
|
+
expires_at: Optional[datetime] = None
|
|
135
|
+
) -> Tuple["APIKey", str]:
|
|
136
|
+
"""Create an API key for a workspace."""
|
|
137
|
+
|
|
138
|
+
path = f"/{self._api_route}/{self._endpoint_route}/{str(uid)}/api-keys"
|
|
139
|
+
kwargs = {
|
|
140
|
+
"roleId": str(getattr(role, "uid", role)),
|
|
141
|
+
"name": name,
|
|
142
|
+
"description": description,
|
|
143
|
+
"isActive": is_active,
|
|
144
|
+
"expiresAt": expires_at
|
|
145
|
+
}
|
|
146
|
+
headers = {"Content-type": "application/json"}
|
|
147
|
+
|
|
148
|
+
response = self._connection.request(
|
|
149
|
+
"post", path, headers=headers, json=self._to_iso_time(kwargs)
|
|
150
|
+
).json()
|
|
151
|
+
|
|
152
|
+
return APIKey(
|
|
153
|
+
_connection=self._connection, _uid=UUID(str(response.pop("id"))), **response
|
|
154
|
+
), response["key"]
|
|
155
|
+
|
|
156
|
+
def update_api_key(
|
|
157
|
+
self,
|
|
158
|
+
uid: Union[UUID, str],
|
|
159
|
+
api_key_id: Union[UUID, str],
|
|
160
|
+
role: Union["Role", UUID, str] = ...,
|
|
161
|
+
name: str = ...,
|
|
162
|
+
description: Optional[str] = ...,
|
|
163
|
+
is_active: bool = ...,
|
|
164
|
+
expires_at: Optional[datetime] = ...
|
|
165
|
+
) -> "APIKey":
|
|
166
|
+
"""Update an existing API key."""
|
|
167
|
+
|
|
168
|
+
path = f"/{self._api_route}/{self._endpoint_route}/{str(uid)}/api-keys/{str(api_key_id)}"
|
|
169
|
+
kwargs = {
|
|
170
|
+
"roleId": ... if role is ... else str(getattr(role, "uid", role)),
|
|
171
|
+
"name": name,
|
|
172
|
+
"description": description,
|
|
173
|
+
"isActive": is_active,
|
|
174
|
+
"expiresAt": (
|
|
175
|
+
expires_at.isoformat()
|
|
176
|
+
if expires_at
|
|
177
|
+
not in (
|
|
178
|
+
None,
|
|
179
|
+
...,
|
|
180
|
+
)
|
|
181
|
+
else None
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
headers = {"Content-type": "application/json"}
|
|
185
|
+
|
|
186
|
+
response = self._connection.request(
|
|
187
|
+
"patch", path, headers=headers,
|
|
188
|
+
json={k: v for k, v in kwargs.items() if v is not ...}
|
|
189
|
+
).json()
|
|
190
|
+
|
|
191
|
+
return APIKey(
|
|
192
|
+
_connection=self._connection, _uid=UUID(str(response.pop("id"))), **response
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
def delete_api_key(
|
|
196
|
+
self,
|
|
197
|
+
uid: Union[UUID, str],
|
|
198
|
+
api_key_id: Union[UUID, str]
|
|
199
|
+
):
|
|
200
|
+
"""Delete an existing API key."""
|
|
201
|
+
|
|
202
|
+
path = f"/{self._api_route}/{self._endpoint_route}/{str(uid)}/api-keys/{str(api_key_id)}"
|
|
203
|
+
self._connection.request("delete", path)
|
|
204
|
+
|
|
205
|
+
def regenerate_api_key(
|
|
206
|
+
self,
|
|
207
|
+
uid: Union[UUID, str],
|
|
208
|
+
api_key_id: Union[UUID, str]
|
|
209
|
+
):
|
|
210
|
+
"""Regenerate an existing API key."""
|
|
211
|
+
|
|
212
|
+
path = f"/{self._api_route}/{self._endpoint_route}/{str(uid)}/api-keys/{str(api_key_id)}/regenerate"
|
|
213
|
+
response = self._connection.request("put", path).json()
|
|
214
|
+
|
|
215
|
+
return APIKey(
|
|
216
|
+
_connection=self._connection, _uid=UUID(str(response.pop("id"))), **response
|
|
217
|
+
), response["key"]
|
|
218
|
+
|
|
110
219
|
def transfer_ownership(self, uid: Union[UUID, str], email: str) -> None:
|
|
111
220
|
"""Transfer ownership of a workspace to another HydroServer user."""
|
|
112
221
|
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from hydroserverpy.etl.types import TimeRange
|
|
3
|
+
import requests
|
|
4
|
+
from io import BytesIO
|
|
5
|
+
from typing import Dict
|
|
6
|
+
from .base import Extractor
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class HTTPExtractor(Extractor):
|
|
10
|
+
def __init__(self, settings: object):
|
|
11
|
+
self.url = settings["urlTemplate"]
|
|
12
|
+
# self.url = self.format_url(url, url_variables or {})
|
|
13
|
+
# self.params = settings.get('params', )
|
|
14
|
+
# self.headers = headers
|
|
15
|
+
# self.auth = auth
|
|
16
|
+
|
|
17
|
+
def prepare_params(self, data_requirements: Dict[str, TimeRange]):
|
|
18
|
+
pass
|
|
19
|
+
# TODO: Uncomment this once url templates work on in the Data Management App
|
|
20
|
+
# start_times = [
|
|
21
|
+
# req["start_time"] for req in data_requirements.values() if req["start_time"]
|
|
22
|
+
# ]
|
|
23
|
+
|
|
24
|
+
# if start_times:
|
|
25
|
+
# oldest_start_time = min(start_times)
|
|
26
|
+
# start_time_key = self.params.pop("start_time_key", None)
|
|
27
|
+
# if start_time_key:
|
|
28
|
+
# self.params[start_time_key] = oldest_start_time
|
|
29
|
+
# logging.info(
|
|
30
|
+
# f"Set start_time to {oldest_start_time} and removed 'start_time_key'"
|
|
31
|
+
# )
|
|
32
|
+
# else:
|
|
33
|
+
# logging.warning("'start_time_key' not found in params.")
|
|
34
|
+
|
|
35
|
+
# end_times = [
|
|
36
|
+
# req["end_time"] for req in data_requirements.values() if req["end_time"]
|
|
37
|
+
# ]
|
|
38
|
+
|
|
39
|
+
# if end_times:
|
|
40
|
+
# newest_end_time = max(end_times)
|
|
41
|
+
# end_time_key = self.params.pop("end_time_key", None)
|
|
42
|
+
# if end_time_key:
|
|
43
|
+
# self.params[end_time_key] = newest_end_time
|
|
44
|
+
# logging.info(
|
|
45
|
+
# f"Set end_time to {newest_end_time} and removed 'end_time_key'"
|
|
46
|
+
# )
|
|
47
|
+
# else:
|
|
48
|
+
# logging.warning("'end_time_key' not found in params.")
|
|
49
|
+
|
|
50
|
+
def extract(self):
|
|
51
|
+
"""
|
|
52
|
+
Downloads the file from the HTTP/HTTPS server and returns a file-like object.
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
logging.info(f"Requesting data from → {self.url}")
|
|
56
|
+
|
|
57
|
+
# endpoints = [
|
|
58
|
+
# "https://httpbin.org/get",
|
|
59
|
+
# "https://jsonplaceholder.typicode.com/posts/1",
|
|
60
|
+
# "https://api.github.com",
|
|
61
|
+
# "https://api.ipify.org?format=json",
|
|
62
|
+
# "https://www.python.org/",
|
|
63
|
+
# "https://waterservices.usgs.gov/nwis/iv/?&format=json&sites=01646500¶meterCd=00060",
|
|
64
|
+
# "https://datahub.io/core/country-list/r/data.csv",
|
|
65
|
+
# "https://raw.githubusercontent.com/cs109/2014_data/master/countries.csv",
|
|
66
|
+
# # "https://rain-flow.slco.org/export/file/?delimiter=comma&site_id=68&data_start=2025-04-09&data_end=2025-05-09&device_id=2",
|
|
67
|
+
# # "https://rain-flow.slco.org/export/file/?mime=txt&delimiter=comma&site_id=68&data_start=2025-05-09%2000:00:00&data_end=2025-05-09%2023:59:59&device_id=2"
|
|
68
|
+
# ]
|
|
69
|
+
# for url in endpoints:
|
|
70
|
+
# try:
|
|
71
|
+
# r = requests.get(url, timeout=10)
|
|
72
|
+
# print(f"{url:50} → {r.status_code}")
|
|
73
|
+
# except Exception as e:
|
|
74
|
+
# print(f"{url:50} → ERROR: {e}")
|
|
75
|
+
|
|
76
|
+
try:
|
|
77
|
+
response = requests.get(self.url)
|
|
78
|
+
except Exception as e:
|
|
79
|
+
logging.error(f"Failed to fetch {repr(self.url)}: {e}")
|
|
80
|
+
raise
|
|
81
|
+
|
|
82
|
+
logging.info(f"Received response")
|
|
83
|
+
|
|
84
|
+
data = BytesIO()
|
|
85
|
+
for chunk in response.iter_content(chunk_size=8192):
|
|
86
|
+
if chunk:
|
|
87
|
+
data.write(chunk)
|
|
88
|
+
data.seek(0)
|
|
89
|
+
return data
|
|
90
|
+
|
|
91
|
+
@staticmethod
|
|
92
|
+
def format_url(url_template, url_variables):
|
|
93
|
+
try:
|
|
94
|
+
url = url_template.format(**url_variables)
|
|
95
|
+
except KeyError as e:
|
|
96
|
+
missing_key = e.args[0]
|
|
97
|
+
raise KeyError(f"Missing configuration url_variable: {missing_key}")
|
|
98
|
+
|
|
99
|
+
return url
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from typing import Dict
|
|
3
|
+
|
|
4
|
+
from .base import Extractor
|
|
5
|
+
from ..types import TimeRange
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class LocalFileExtractor(Extractor):
|
|
9
|
+
def __init__(self, settings: object):
|
|
10
|
+
if "path" not in settings:
|
|
11
|
+
message = "Missing required setting 'path' in LocalFileExtractor settings."
|
|
12
|
+
logging.error(message)
|
|
13
|
+
raise ValueError(message)
|
|
14
|
+
self.path = settings["path"]
|
|
15
|
+
|
|
16
|
+
def prepare_params(self, data_requirements: Dict[str, TimeRange]):
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
def extract(self):
|
|
20
|
+
"""
|
|
21
|
+
Opens the file and returns a file-like object.
|
|
22
|
+
"""
|
|
23
|
+
try:
|
|
24
|
+
file_handle = open(self.path, "r")
|
|
25
|
+
logging.info(f"Successfully opened file '{self.path}'.")
|
|
26
|
+
return file_handle
|
|
27
|
+
except Exception as e:
|
|
28
|
+
logging.error(f"Error opening file '{self.path}': {e}")
|
|
29
|
+
return None
|
{hydroserverpy-1.0.0 → hydroserverpy-1.1.0}/src/hydroserverpy/etl/loaders/hydroserver_loader.py
RENAMED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import datetime
|
|
1
2
|
from hydroserverpy import HydroServer
|
|
2
3
|
from typing import Dict, Optional
|
|
4
|
+
|
|
5
|
+
from src.hydroserverpy.etl.types import TimeRange
|
|
3
6
|
from .base import Loader
|
|
4
7
|
import logging
|
|
5
8
|
import pandas as pd
|
|
@@ -13,20 +16,25 @@ class HydroServerLoader(HydroServer, Loader):
|
|
|
13
16
|
def __init__(
|
|
14
17
|
self,
|
|
15
18
|
host: str,
|
|
16
|
-
|
|
19
|
+
email: Optional[str] = None,
|
|
17
20
|
password: Optional[str] = None,
|
|
18
21
|
apikey: Optional[str] = None,
|
|
19
|
-
api_route: str = "api",
|
|
20
22
|
):
|
|
21
|
-
super().__init__(
|
|
23
|
+
super().__init__(
|
|
24
|
+
host=host,
|
|
25
|
+
email=email,
|
|
26
|
+
password=password,
|
|
27
|
+
apikey=apikey,
|
|
28
|
+
)
|
|
22
29
|
|
|
23
|
-
def load(self, data: pd.DataFrame,
|
|
30
|
+
def load(self, data: pd.DataFrame, payload_settings) -> None:
|
|
24
31
|
"""
|
|
25
32
|
Load observations from a DataFrame to the HydroServer.
|
|
26
33
|
|
|
27
34
|
:param data: A Pandas DataFrame where each column corresponds to a datastream.
|
|
28
35
|
"""
|
|
29
|
-
|
|
36
|
+
mappings = payload_settings["mappings"]
|
|
37
|
+
time_ranges = self.get_data_requirements(mappings)
|
|
30
38
|
for ds_id in data.columns:
|
|
31
39
|
if ds_id == "timestamp":
|
|
32
40
|
continue
|
|
@@ -35,9 +43,17 @@ class HydroServerLoader(HydroServer, Loader):
|
|
|
35
43
|
df.rename(columns={ds_id: "value"}, inplace=True)
|
|
36
44
|
df.dropna(subset=["value"], inplace=True)
|
|
37
45
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
# ensure the timestamp column is UTC‑aware
|
|
47
|
+
timestamp_column = df["timestamp"]
|
|
48
|
+
if timestamp_column.dt.tz is None:
|
|
49
|
+
df["timestamp"] = timestamp_column.dt.tz_localize("UTC")
|
|
50
|
+
|
|
51
|
+
time_range = time_ranges[ds_id]
|
|
52
|
+
start_ts = pd.to_datetime(time_range["start_time"], utc=True)
|
|
53
|
+
|
|
54
|
+
if start_ts:
|
|
55
|
+
df = df[df["timestamp"] > start_ts]
|
|
56
|
+
logging.info(f"start cutoff for data loading {start_ts}")
|
|
41
57
|
if df.empty:
|
|
42
58
|
logging.warning(
|
|
43
59
|
f"No new data to upload for datastream {ds_id}. Skipping."
|
|
@@ -45,24 +61,31 @@ class HydroServerLoader(HydroServer, Loader):
|
|
|
45
61
|
continue
|
|
46
62
|
self.datastreams.load_observations(uid=ds_id, observations=df)
|
|
47
63
|
|
|
48
|
-
def get_data_requirements(
|
|
49
|
-
self, source_target_map
|
|
50
|
-
) -> Dict[str, Dict[str, pd.Timestamp]]:
|
|
64
|
+
def get_data_requirements(self, source_target_map) -> Dict[str, TimeRange]:
|
|
51
65
|
"""
|
|
52
66
|
Each target system needs to be able to answer the question: 'What data do you need?'
|
|
53
67
|
and return a time range for each target time series. Usually the answer will be
|
|
54
68
|
'anything newer than my most recent observation'.
|
|
55
69
|
"""
|
|
56
70
|
data_requirements = {}
|
|
57
|
-
for
|
|
58
|
-
|
|
71
|
+
target_ids = [mapping["targetIdentifier"] for mapping in source_target_map]
|
|
72
|
+
for id in target_ids:
|
|
73
|
+
datastream = self.datastreams.get(uid=id)
|
|
59
74
|
if not datastream:
|
|
60
75
|
message = "Couldn't fetch target datastream. ETL process aborted."
|
|
61
76
|
logging.error(message)
|
|
62
77
|
raise message
|
|
63
|
-
|
|
78
|
+
|
|
79
|
+
start_ts = pd.Timestamp(
|
|
64
80
|
datastream.phenomenon_end_time or "1970-01-01T00:00:00Z"
|
|
65
81
|
)
|
|
66
|
-
|
|
67
|
-
|
|
82
|
+
if start_ts.tzinfo is None:
|
|
83
|
+
start_ts = start_ts.tz_localize("UTC")
|
|
84
|
+
|
|
85
|
+
end_ts = pd.Timestamp.now(tz="UTC")
|
|
86
|
+
|
|
87
|
+
data_requirements[id] = {
|
|
88
|
+
"start_time": start_ts.isoformat(),
|
|
89
|
+
"end_time": end_ts.isoformat(),
|
|
90
|
+
}
|
|
68
91
|
return data_requirements
|