hydroserverpy 0.4.0__py3-none-any.whl → 0.5.0b2__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.
Potentially problematic release.
This version of hydroserverpy might be problematic. Click here for more details.
- hydroserverpy/__init__.py +2 -3
- hydroserverpy/api/http.py +22 -0
- hydroserverpy/api/main.py +173 -0
- hydroserverpy/api/models/__init__.py +21 -0
- hydroserverpy/api/models/base.py +74 -0
- hydroserverpy/api/models/etl/__init__.py +0 -0
- hydroserverpy/api/models/etl/data_archive.py +105 -0
- hydroserverpy/api/models/etl/data_source.py +150 -0
- hydroserverpy/api/models/etl/orchestration_configuration.py +35 -0
- hydroserverpy/api/models/etl/orchestration_system.py +78 -0
- hydroserverpy/api/models/iam/__init__.py +0 -0
- hydroserverpy/api/models/iam/account.py +12 -0
- hydroserverpy/api/models/iam/collaborator.py +34 -0
- hydroserverpy/api/models/iam/role.py +10 -0
- hydroserverpy/api/models/iam/workspace.py +238 -0
- hydroserverpy/api/models/sta/__init__.py +0 -0
- hydroserverpy/api/models/sta/datastream.py +338 -0
- hydroserverpy/api/models/sta/observed_property.py +72 -0
- hydroserverpy/api/models/sta/processing_level.py +50 -0
- hydroserverpy/api/models/sta/result_qualifier.py +49 -0
- hydroserverpy/api/models/sta/sensor.py +105 -0
- hydroserverpy/api/models/sta/thing.py +217 -0
- hydroserverpy/api/models/sta/unit.py +49 -0
- hydroserverpy/api/services/__init__.py +11 -0
- hydroserverpy/api/services/base.py +102 -0
- hydroserverpy/api/services/etl/__init__.py +0 -0
- hydroserverpy/api/services/etl/data_archive.py +196 -0
- hydroserverpy/api/services/etl/data_source.py +196 -0
- hydroserverpy/api/services/etl/orchestration_system.py +74 -0
- hydroserverpy/api/services/iam/__init__.py +0 -0
- hydroserverpy/api/services/iam/workspace.py +126 -0
- hydroserverpy/api/services/sta/__init__.py +0 -0
- hydroserverpy/api/services/sta/datastream.py +354 -0
- hydroserverpy/api/services/sta/observed_property.py +100 -0
- hydroserverpy/api/services/sta/processing_level.py +78 -0
- hydroserverpy/api/services/sta/result_qualifier.py +74 -0
- hydroserverpy/api/services/sta/sensor.py +116 -0
- hydroserverpy/api/services/sta/thing.py +188 -0
- hydroserverpy/api/services/sta/unit.py +82 -0
- hydroserverpy/etl/loaders/hydroserver_loader.py +1 -1
- hydroserverpy/etl_csv/hydroserver_etl_csv.py +49 -34
- {hydroserverpy-0.4.0.dist-info → hydroserverpy-0.5.0b2.dist-info}/METADATA +4 -3
- hydroserverpy-0.5.0b2.dist-info/RECORD +66 -0
- {hydroserverpy-0.4.0.dist-info → hydroserverpy-0.5.0b2.dist-info}/WHEEL +1 -1
- hydroserverpy/core/endpoints/__init__.py +0 -9
- hydroserverpy/core/endpoints/base.py +0 -146
- hydroserverpy/core/endpoints/data_loaders.py +0 -93
- hydroserverpy/core/endpoints/data_sources.py +0 -93
- hydroserverpy/core/endpoints/datastreams.py +0 -225
- hydroserverpy/core/endpoints/observed_properties.py +0 -111
- hydroserverpy/core/endpoints/processing_levels.py +0 -111
- hydroserverpy/core/endpoints/result_qualifiers.py +0 -111
- hydroserverpy/core/endpoints/sensors.py +0 -111
- hydroserverpy/core/endpoints/things.py +0 -261
- hydroserverpy/core/endpoints/units.py +0 -111
- hydroserverpy/core/schemas/__init__.py +0 -9
- hydroserverpy/core/schemas/base.py +0 -124
- hydroserverpy/core/schemas/data_loaders.py +0 -73
- hydroserverpy/core/schemas/data_sources.py +0 -223
- hydroserverpy/core/schemas/datastreams.py +0 -330
- hydroserverpy/core/schemas/observed_properties.py +0 -43
- hydroserverpy/core/schemas/processing_levels.py +0 -31
- hydroserverpy/core/schemas/result_qualifiers.py +0 -26
- hydroserverpy/core/schemas/sensors.py +0 -68
- hydroserverpy/core/schemas/things.py +0 -346
- hydroserverpy/core/schemas/units.py +0 -29
- hydroserverpy/core/service.py +0 -200
- hydroserverpy-0.4.0.dist-info/RECORD +0 -51
- /hydroserverpy/{core → api}/__init__.py +0 -0
- {hydroserverpy-0.4.0.dist-info → hydroserverpy-0.5.0b2.dist-info/licenses}/LICENSE +0 -0
- {hydroserverpy-0.4.0.dist-info → hydroserverpy-0.5.0b2.dist-info}/top_level.txt +0 -0
- {hydroserverpy-0.4.0.dist-info → hydroserverpy-0.5.0b2.dist-info}/zip-safe +0 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from typing import Optional, Literal, Union, List, TYPE_CHECKING
|
|
3
|
+
from uuid import UUID
|
|
4
|
+
from ..base import EndpointService
|
|
5
|
+
from hydroserverpy.api.models import DataArchive, Datastream
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from hydroserverpy import HydroServer
|
|
10
|
+
from hydroserverpy.api.models import Workspace, OrchestrationSystem
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class DataArchiveService(EndpointService):
|
|
14
|
+
def __init__(self, connection: "HydroServer"):
|
|
15
|
+
self._model = DataArchive
|
|
16
|
+
self._api_route = "api/data"
|
|
17
|
+
self._endpoint_route = "data-archives"
|
|
18
|
+
|
|
19
|
+
super().__init__(connection)
|
|
20
|
+
|
|
21
|
+
def list(
|
|
22
|
+
self,
|
|
23
|
+
workspace: Optional[Union["Workspace", UUID, str]] = None,
|
|
24
|
+
orchestration_system: Optional[Union["OrchestrationSystem", UUID, str]] = None,
|
|
25
|
+
) -> List["DataArchive"]:
|
|
26
|
+
"""Fetch a collection of data archives."""
|
|
27
|
+
|
|
28
|
+
params = {}
|
|
29
|
+
|
|
30
|
+
workspace_id = getattr(workspace, "uid", workspace)
|
|
31
|
+
workspace_id = str(workspace_id) if workspace_id else None
|
|
32
|
+
|
|
33
|
+
orchestration_system_id = getattr(
|
|
34
|
+
orchestration_system, "uid", orchestration_system
|
|
35
|
+
)
|
|
36
|
+
orchestration_system_id = (
|
|
37
|
+
str(orchestration_system_id) if orchestration_system_id else None
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
if workspace_id:
|
|
41
|
+
params["workspace_id"] = workspace_id
|
|
42
|
+
|
|
43
|
+
if orchestration_system_id:
|
|
44
|
+
params["orchestration_system_id"] = orchestration_system_id
|
|
45
|
+
|
|
46
|
+
return super()._list(
|
|
47
|
+
params=params,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
def get(self, uid: Union[UUID, str]) -> "DataArchive":
|
|
51
|
+
"""Get a data archive by ID."""
|
|
52
|
+
|
|
53
|
+
return super()._get(uid=str(uid))
|
|
54
|
+
|
|
55
|
+
def create(
|
|
56
|
+
self,
|
|
57
|
+
name: str,
|
|
58
|
+
workspace: Union["Workspace", UUID, str],
|
|
59
|
+
orchestration_system: Union["OrchestrationSystem", UUID, str],
|
|
60
|
+
settings: Optional[dict] = None,
|
|
61
|
+
interval: Optional[int] = None,
|
|
62
|
+
interval_units: Optional[Literal["minutes", "hours", "days"]] = None,
|
|
63
|
+
crontab: Optional[str] = None,
|
|
64
|
+
start_time: Optional[datetime] = None,
|
|
65
|
+
end_time: Optional[datetime] = None,
|
|
66
|
+
last_run_successful: Optional[bool] = None,
|
|
67
|
+
last_run_message: Optional[str] = None,
|
|
68
|
+
last_run: Optional[datetime] = None,
|
|
69
|
+
next_run: Optional[datetime] = None,
|
|
70
|
+
paused: bool = False,
|
|
71
|
+
datastreams: Optional[List[Union["Datastream", UUID, str]]] = None,
|
|
72
|
+
) -> "DataArchive":
|
|
73
|
+
"""Create a new data archive."""
|
|
74
|
+
|
|
75
|
+
kwargs = {
|
|
76
|
+
"name": name,
|
|
77
|
+
"workspaceId": str(getattr(workspace, "uid", workspace)),
|
|
78
|
+
"orchestrationSystemId": getattr(
|
|
79
|
+
orchestration_system, "uid", orchestration_system
|
|
80
|
+
),
|
|
81
|
+
"settings": settings,
|
|
82
|
+
"schedule": {
|
|
83
|
+
"interval": interval,
|
|
84
|
+
"intervalUnits": interval_units,
|
|
85
|
+
"crontab": crontab,
|
|
86
|
+
"startTime": start_time,
|
|
87
|
+
"endTime": end_time,
|
|
88
|
+
},
|
|
89
|
+
"status": {
|
|
90
|
+
"lastRunSuccessful": last_run_successful,
|
|
91
|
+
"lastRunMessage": last_run_message,
|
|
92
|
+
"lastRun": last_run,
|
|
93
|
+
"nextRun": next_run,
|
|
94
|
+
"paused": paused,
|
|
95
|
+
},
|
|
96
|
+
"datastreamIds": (
|
|
97
|
+
[
|
|
98
|
+
str(getattr(datastream, "uid", datastream))
|
|
99
|
+
for datastream in datastreams
|
|
100
|
+
]
|
|
101
|
+
if datastreams
|
|
102
|
+
else []
|
|
103
|
+
),
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return super()._create(**kwargs)
|
|
107
|
+
|
|
108
|
+
def update(
|
|
109
|
+
self,
|
|
110
|
+
uid: Union[UUID, str],
|
|
111
|
+
name: str = ...,
|
|
112
|
+
orchestration_system: Union["OrchestrationSystem", UUID, str] = ...,
|
|
113
|
+
settings: Optional[dict] = ...,
|
|
114
|
+
interval: Optional[int] = ...,
|
|
115
|
+
interval_units: Optional[Literal["minutes", "hours", "days"]] = ...,
|
|
116
|
+
crontab: Optional[str] = ...,
|
|
117
|
+
start_time: Optional[datetime] = ...,
|
|
118
|
+
end_time: Optional[datetime] = ...,
|
|
119
|
+
last_run_successful: Optional[bool] = ...,
|
|
120
|
+
last_run_message: Optional[str] = ...,
|
|
121
|
+
last_run: Optional[datetime] = ...,
|
|
122
|
+
next_run: Optional[datetime] = ...,
|
|
123
|
+
paused: bool = ...,
|
|
124
|
+
) -> "DataArchive":
|
|
125
|
+
"""Update a data archive."""
|
|
126
|
+
|
|
127
|
+
status_kwargs = {
|
|
128
|
+
k: v
|
|
129
|
+
for k, v in {
|
|
130
|
+
"lastRunSuccessful": last_run_successful,
|
|
131
|
+
"lastRunMessage": last_run_message,
|
|
132
|
+
"lastRun": last_run,
|
|
133
|
+
"nextRun": next_run,
|
|
134
|
+
"paused": paused,
|
|
135
|
+
}.items()
|
|
136
|
+
if v is not ...
|
|
137
|
+
}
|
|
138
|
+
status_kwargs = status_kwargs if status_kwargs else ...
|
|
139
|
+
|
|
140
|
+
schedule_kwargs = {
|
|
141
|
+
k: v
|
|
142
|
+
for k, v in {
|
|
143
|
+
"interval": interval,
|
|
144
|
+
"intervalUnits": interval_units,
|
|
145
|
+
"crontab": crontab,
|
|
146
|
+
"startTime": start_time,
|
|
147
|
+
"endTime": end_time,
|
|
148
|
+
}.items()
|
|
149
|
+
if v is not ...
|
|
150
|
+
}
|
|
151
|
+
schedule_kwargs = schedule_kwargs if schedule_kwargs else ...
|
|
152
|
+
|
|
153
|
+
kwargs = {
|
|
154
|
+
k: v
|
|
155
|
+
for k, v in {
|
|
156
|
+
"name": name,
|
|
157
|
+
"orchestrationSystemId": getattr(
|
|
158
|
+
orchestration_system, "uid", orchestration_system
|
|
159
|
+
),
|
|
160
|
+
"settings": settings,
|
|
161
|
+
"schedule": schedule_kwargs,
|
|
162
|
+
"status": status_kwargs,
|
|
163
|
+
}.items()
|
|
164
|
+
if v is not ...
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return super()._update(uid=str(uid), **kwargs)
|
|
168
|
+
|
|
169
|
+
def delete(self, uid: Union[UUID, str]) -> None:
|
|
170
|
+
"""Delete a data archive."""
|
|
171
|
+
|
|
172
|
+
super()._delete(uid=str(uid))
|
|
173
|
+
|
|
174
|
+
def add_datastream(
|
|
175
|
+
self, uid: Union[UUID, str], datastream: Union["Datastream", UUID, str]
|
|
176
|
+
) -> None:
|
|
177
|
+
"""Add a datastream to this data archive."""
|
|
178
|
+
|
|
179
|
+
datastream_id = str(getattr(datastream, "uid", datastream))
|
|
180
|
+
|
|
181
|
+
self._connection.request(
|
|
182
|
+
"post",
|
|
183
|
+
f"{self._api_route}/{self._endpoint_route}/{str(uid)}/datastreams/{datastream_id}",
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
def remove_datastream(
|
|
187
|
+
self, uid: Union[UUID, str], datastream: Union["Datastream", UUID, str]
|
|
188
|
+
) -> None:
|
|
189
|
+
"""Remove a datastream from this data archive."""
|
|
190
|
+
|
|
191
|
+
datastream_id = str(getattr(datastream, "uid", datastream))
|
|
192
|
+
|
|
193
|
+
self._connection.request(
|
|
194
|
+
"delete",
|
|
195
|
+
f"{self._api_route}/{self._endpoint_route}/{str(uid)}/datastreams/{datastream_id}",
|
|
196
|
+
)
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from typing import Optional, Literal, Union, List, TYPE_CHECKING
|
|
3
|
+
from uuid import UUID
|
|
4
|
+
from ..base import EndpointService
|
|
5
|
+
from hydroserverpy.api.models import DataSource, Datastream
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from hydroserverpy import HydroServer
|
|
10
|
+
from hydroserverpy.api.models import Workspace, OrchestrationSystem
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class DataSourceService(EndpointService):
|
|
14
|
+
def __init__(self, connection: "HydroServer"):
|
|
15
|
+
self._model = DataSource
|
|
16
|
+
self._api_route = "api/data"
|
|
17
|
+
self._endpoint_route = "data-sources"
|
|
18
|
+
|
|
19
|
+
super().__init__(connection)
|
|
20
|
+
|
|
21
|
+
def list(
|
|
22
|
+
self,
|
|
23
|
+
workspace: Optional[Union["Workspace", UUID, str]] = None,
|
|
24
|
+
orchestration_system: Optional[Union["OrchestrationSystem", UUID, str]] = None,
|
|
25
|
+
) -> List["DataSource"]:
|
|
26
|
+
"""Fetch a collection of data sources."""
|
|
27
|
+
|
|
28
|
+
params = {}
|
|
29
|
+
|
|
30
|
+
workspace_id = getattr(workspace, "uid", workspace)
|
|
31
|
+
workspace_id = str(workspace_id) if workspace_id else None
|
|
32
|
+
|
|
33
|
+
orchestration_system_id = getattr(
|
|
34
|
+
orchestration_system, "uid", orchestration_system
|
|
35
|
+
)
|
|
36
|
+
orchestration_system_id = (
|
|
37
|
+
str(orchestration_system_id) if orchestration_system_id else None
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
if workspace_id:
|
|
41
|
+
params["workspace_id"] = workspace_id
|
|
42
|
+
|
|
43
|
+
if orchestration_system_id:
|
|
44
|
+
params["orchestration_system_id"] = orchestration_system_id
|
|
45
|
+
|
|
46
|
+
return super()._list(
|
|
47
|
+
params=params,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
def get(self, uid: Union[UUID, str]) -> "DataSource":
|
|
51
|
+
"""Get a data source by ID."""
|
|
52
|
+
|
|
53
|
+
return super()._get(uid=str(uid))
|
|
54
|
+
|
|
55
|
+
def create(
|
|
56
|
+
self,
|
|
57
|
+
name: str,
|
|
58
|
+
workspace: Union["Workspace", UUID, str],
|
|
59
|
+
orchestration_system: Union["OrchestrationSystem", UUID, str],
|
|
60
|
+
settings: Optional[dict] = None,
|
|
61
|
+
interval: Optional[int] = None,
|
|
62
|
+
interval_units: Optional[Literal["minutes", "hours", "days"]] = None,
|
|
63
|
+
crontab: Optional[str] = None,
|
|
64
|
+
start_time: Optional[datetime] = None,
|
|
65
|
+
end_time: Optional[datetime] = None,
|
|
66
|
+
last_run_successful: Optional[bool] = None,
|
|
67
|
+
last_run_message: Optional[str] = None,
|
|
68
|
+
last_run: Optional[datetime] = None,
|
|
69
|
+
next_run: Optional[datetime] = None,
|
|
70
|
+
paused: bool = False,
|
|
71
|
+
datastreams: Optional[List[Union["Datastream", UUID, str]]] = None,
|
|
72
|
+
) -> "DataSource":
|
|
73
|
+
"""Create a new data source."""
|
|
74
|
+
|
|
75
|
+
kwargs = {
|
|
76
|
+
"name": name,
|
|
77
|
+
"workspaceId": str(getattr(workspace, "uid", workspace)),
|
|
78
|
+
"orchestrationSystemId": getattr(
|
|
79
|
+
orchestration_system, "uid", orchestration_system
|
|
80
|
+
),
|
|
81
|
+
"settings": settings,
|
|
82
|
+
"schedule": {
|
|
83
|
+
"interval": interval,
|
|
84
|
+
"intervalUnits": interval_units,
|
|
85
|
+
"crontab": crontab,
|
|
86
|
+
"startTime": start_time,
|
|
87
|
+
"endTime": end_time,
|
|
88
|
+
},
|
|
89
|
+
"status": {
|
|
90
|
+
"lastRunSuccessful": last_run_successful,
|
|
91
|
+
"lastRunMessage": last_run_message,
|
|
92
|
+
"lastRun": last_run,
|
|
93
|
+
"nextRun": next_run,
|
|
94
|
+
"paused": paused,
|
|
95
|
+
},
|
|
96
|
+
"datastreamIds": (
|
|
97
|
+
[
|
|
98
|
+
str(getattr(datastream, "uid", datastream))
|
|
99
|
+
for datastream in datastreams
|
|
100
|
+
]
|
|
101
|
+
if datastreams
|
|
102
|
+
else []
|
|
103
|
+
),
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return super()._create(**kwargs)
|
|
107
|
+
|
|
108
|
+
def update(
|
|
109
|
+
self,
|
|
110
|
+
uid: Union[UUID, str],
|
|
111
|
+
name: str = ...,
|
|
112
|
+
orchestration_system: Union["OrchestrationSystem", UUID, str] = ...,
|
|
113
|
+
settings: Optional[dict] = ...,
|
|
114
|
+
interval: Optional[int] = ...,
|
|
115
|
+
interval_units: Optional[Literal["minutes", "hours", "days"]] = ...,
|
|
116
|
+
crontab: Optional[str] = ...,
|
|
117
|
+
start_time: Optional[datetime] = ...,
|
|
118
|
+
end_time: Optional[datetime] = ...,
|
|
119
|
+
last_run_successful: Optional[bool] = ...,
|
|
120
|
+
last_run_message: Optional[str] = ...,
|
|
121
|
+
last_run: Optional[datetime] = ...,
|
|
122
|
+
next_run: Optional[datetime] = ...,
|
|
123
|
+
paused: bool = ...,
|
|
124
|
+
) -> "DataSource":
|
|
125
|
+
"""Update a data source."""
|
|
126
|
+
|
|
127
|
+
status_kwargs = {
|
|
128
|
+
k: v
|
|
129
|
+
for k, v in {
|
|
130
|
+
"lastRunSuccessful": last_run_successful,
|
|
131
|
+
"lastRunMessage": last_run_message,
|
|
132
|
+
"lastRun": last_run,
|
|
133
|
+
"nextRun": next_run,
|
|
134
|
+
"paused": paused,
|
|
135
|
+
}.items()
|
|
136
|
+
if v is not ...
|
|
137
|
+
}
|
|
138
|
+
status_kwargs = status_kwargs if status_kwargs else ...
|
|
139
|
+
|
|
140
|
+
schedule_kwargs = {
|
|
141
|
+
k: v
|
|
142
|
+
for k, v in {
|
|
143
|
+
"interval": interval,
|
|
144
|
+
"intervalUnits": interval_units,
|
|
145
|
+
"crontab": crontab,
|
|
146
|
+
"startTime": start_time,
|
|
147
|
+
"endTime": end_time,
|
|
148
|
+
}.items()
|
|
149
|
+
if v is not ...
|
|
150
|
+
}
|
|
151
|
+
schedule_kwargs = schedule_kwargs if schedule_kwargs else ...
|
|
152
|
+
|
|
153
|
+
kwargs = {
|
|
154
|
+
k: v
|
|
155
|
+
for k, v in {
|
|
156
|
+
"name": name,
|
|
157
|
+
"orchestrationSystemId": getattr(
|
|
158
|
+
orchestration_system, "uid", orchestration_system
|
|
159
|
+
),
|
|
160
|
+
"settings": settings,
|
|
161
|
+
"schedule": schedule_kwargs,
|
|
162
|
+
"status": status_kwargs,
|
|
163
|
+
}.items()
|
|
164
|
+
if v is not ...
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return super()._update(uid=str(uid), **kwargs)
|
|
168
|
+
|
|
169
|
+
def delete(self, uid: Union[UUID, str]) -> None:
|
|
170
|
+
"""Delete a data source."""
|
|
171
|
+
|
|
172
|
+
super()._delete(uid=str(uid))
|
|
173
|
+
|
|
174
|
+
def add_datastream(
|
|
175
|
+
self, uid: Union[UUID, str], datastream: Union["Datastream", UUID, str]
|
|
176
|
+
) -> None:
|
|
177
|
+
"""Add a datastream to this data source."""
|
|
178
|
+
|
|
179
|
+
datastream_id = str(getattr(datastream, "uid", datastream))
|
|
180
|
+
|
|
181
|
+
self._connection.request(
|
|
182
|
+
"post",
|
|
183
|
+
f"{self._api_route}/{self._endpoint_route}/{str(uid)}/datastreams/{datastream_id}",
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
def remove_datastream(
|
|
187
|
+
self, uid: Union[UUID, str], datastream: Union["Datastream", UUID, str]
|
|
188
|
+
) -> None:
|
|
189
|
+
"""Remove a datastream from this data source."""
|
|
190
|
+
|
|
191
|
+
datastream_id = str(getattr(datastream, "uid", datastream))
|
|
192
|
+
|
|
193
|
+
self._connection.request(
|
|
194
|
+
"delete",
|
|
195
|
+
f"{self._api_route}/{self._endpoint_route}/{str(uid)}/datastreams/{datastream_id}",
|
|
196
|
+
)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
from typing import Optional, Union, List, TYPE_CHECKING
|
|
2
|
+
from uuid import UUID
|
|
3
|
+
from ..base import EndpointService
|
|
4
|
+
from hydroserverpy.api.models import OrchestrationSystem
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from hydroserverpy import HydroServer
|
|
9
|
+
from hydroserverpy.api.models import Workspace
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class OrchestrationSystemService(EndpointService):
|
|
13
|
+
def __init__(self, connection: "HydroServer"):
|
|
14
|
+
self._model = OrchestrationSystem
|
|
15
|
+
self._api_route = "api/data"
|
|
16
|
+
self._endpoint_route = "orchestration-systems"
|
|
17
|
+
|
|
18
|
+
super().__init__(connection)
|
|
19
|
+
|
|
20
|
+
def list(
|
|
21
|
+
self,
|
|
22
|
+
workspace: Optional[Union["Workspace", UUID, str]] = None,
|
|
23
|
+
) -> List["OrchestrationSystem"]:
|
|
24
|
+
"""Fetch a collection of orchestration systems."""
|
|
25
|
+
|
|
26
|
+
workspace_id = getattr(workspace, "uid", workspace)
|
|
27
|
+
workspace_id = str(workspace_id) if workspace_id else None
|
|
28
|
+
|
|
29
|
+
return super()._list(
|
|
30
|
+
params={"workspace_id": workspace_id} if workspace_id else {},
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
def get(self, uid: Union[UUID, str]) -> "OrchestrationSystem":
|
|
34
|
+
"""Get an orchestration system by ID."""
|
|
35
|
+
|
|
36
|
+
return super()._get(uid=str(uid))
|
|
37
|
+
|
|
38
|
+
def create(
|
|
39
|
+
self,
|
|
40
|
+
workspace: Union["Workspace", UUID, str],
|
|
41
|
+
name: str,
|
|
42
|
+
orchestration_system_type: str,
|
|
43
|
+
) -> "OrchestrationSystem":
|
|
44
|
+
"""Create a new orchestration system."""
|
|
45
|
+
|
|
46
|
+
kwargs = {
|
|
47
|
+
"name": name,
|
|
48
|
+
"type": orchestration_system_type,
|
|
49
|
+
"workspaceId": str(getattr(workspace, "uid", workspace)),
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return super()._create(**kwargs)
|
|
53
|
+
|
|
54
|
+
def update(
|
|
55
|
+
self,
|
|
56
|
+
uid: Union[UUID, str],
|
|
57
|
+
name: str = ...,
|
|
58
|
+
orchestration_system_type: str = ...,
|
|
59
|
+
) -> "OrchestrationSystem":
|
|
60
|
+
"""Update an orchestration system."""
|
|
61
|
+
|
|
62
|
+
kwargs = {
|
|
63
|
+
"name": name,
|
|
64
|
+
"type": orchestration_system_type,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return super()._update(
|
|
68
|
+
uid=str(uid), **{k: v for k, v in kwargs.items() if v is not ...}
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
def delete(self, uid: Union[UUID, str]) -> None:
|
|
72
|
+
"""Delete an orchestration system."""
|
|
73
|
+
|
|
74
|
+
super()._delete(uid=str(uid))
|
|
File without changes
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING, Union, List
|
|
2
|
+
from pydantic import EmailStr
|
|
3
|
+
from uuid import UUID
|
|
4
|
+
from hydroserverpy.api.models import Workspace, Role, Collaborator
|
|
5
|
+
from ..base import EndpointService
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from hydroserverpy import HydroServer
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class WorkspaceService(EndpointService):
|
|
13
|
+
def __init__(self, connection: "HydroServer"):
|
|
14
|
+
self._model = Workspace
|
|
15
|
+
self._api_route = "api/auth"
|
|
16
|
+
self._endpoint_route = "workspaces"
|
|
17
|
+
|
|
18
|
+
super().__init__(connection)
|
|
19
|
+
|
|
20
|
+
def list(self, associated_only: bool = False) -> List["Workspace"]:
|
|
21
|
+
"""Fetch a collection of HydroServer resources."""
|
|
22
|
+
|
|
23
|
+
return super()._list(params={"associated_only": associated_only})
|
|
24
|
+
|
|
25
|
+
def get(self, uid: Union[UUID, str]) -> "Workspace":
|
|
26
|
+
"""Get a workspace by ID."""
|
|
27
|
+
|
|
28
|
+
return super()._get(uid=str(uid))
|
|
29
|
+
|
|
30
|
+
def create(self, name: str, is_private: bool, **_) -> "Workspace":
|
|
31
|
+
"""Create a new workspace."""
|
|
32
|
+
|
|
33
|
+
kwargs = {"name": name, "isPrivate": is_private}
|
|
34
|
+
|
|
35
|
+
return super()._create(**kwargs)
|
|
36
|
+
|
|
37
|
+
def update(
|
|
38
|
+
self, uid: Union[UUID, str], name: str = ..., is_private: bool = ..., **_
|
|
39
|
+
) -> "Workspace":
|
|
40
|
+
"""Update a workspace."""
|
|
41
|
+
|
|
42
|
+
kwargs = {"name": name, "isPrivate": is_private}
|
|
43
|
+
|
|
44
|
+
return super()._update(
|
|
45
|
+
uid=str(uid), **{k: v for k, v in kwargs.items() if v is not ...}
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
def delete(self, uid: Union[UUID, str]) -> None:
|
|
49
|
+
"""Delete a workspace."""
|
|
50
|
+
|
|
51
|
+
super()._delete(uid=str(uid))
|
|
52
|
+
|
|
53
|
+
def list_roles(self, uid: Union[UUID, str]) -> List["Role"]:
|
|
54
|
+
"""Get all roles that can be assigned within a workspace."""
|
|
55
|
+
|
|
56
|
+
path = f"/{self._api_route}/{self._endpoint_route}/{str(uid)}/roles"
|
|
57
|
+
response = self._connection.request("get", path)
|
|
58
|
+
|
|
59
|
+
return [Role(**obj) for obj in response.json()]
|
|
60
|
+
|
|
61
|
+
def list_collaborators(self, uid: Union[UUID, str]) -> List["Collaborator"]:
|
|
62
|
+
"""Get all collaborators associated with a workspace."""
|
|
63
|
+
|
|
64
|
+
path = f"/{self._api_route}/{self._endpoint_route}/{str(uid)}/collaborators"
|
|
65
|
+
response = self._connection.request("get", path)
|
|
66
|
+
|
|
67
|
+
return [
|
|
68
|
+
Collaborator(_connection=self._connection, workspace_id=uid, **obj)
|
|
69
|
+
for obj in response.json()
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
def add_collaborator(
|
|
73
|
+
self, uid: Union[UUID, str], email: EmailStr, role: Union["Role", UUID, str]
|
|
74
|
+
) -> "Collaborator":
|
|
75
|
+
"""Add a collaborator to a workspace."""
|
|
76
|
+
|
|
77
|
+
path = f"/{self._api_route}/{self._endpoint_route}/{str(uid)}/collaborators"
|
|
78
|
+
response = self._connection.request(
|
|
79
|
+
"post",
|
|
80
|
+
path,
|
|
81
|
+
json={"email": email, "roleId": str(getattr(role, "uid", role))},
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
return Collaborator(
|
|
85
|
+
_connection=self._connection, workspace_id=uid, **response.json()
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
def edit_collaborator_role(
|
|
89
|
+
self, uid: Union[UUID, str], email: EmailStr, role: Union["Role", UUID, str]
|
|
90
|
+
) -> "Collaborator":
|
|
91
|
+
"""Edit the role of a collaborator in a workspace."""
|
|
92
|
+
|
|
93
|
+
path = f"/{self._api_route}/{self._endpoint_route}/{str(uid)}/collaborators"
|
|
94
|
+
response = self._connection.request(
|
|
95
|
+
"put",
|
|
96
|
+
path,
|
|
97
|
+
json={"email": email, "roleId": str(getattr(role, "uid", role))},
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
return Collaborator(
|
|
101
|
+
_connection=self._connection, workspace_id=uid, **response.json()
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
def remove_collaborator(self, uid: Union[UUID, str], email: EmailStr) -> None:
|
|
105
|
+
"""Remove a collaborator from a workspace."""
|
|
106
|
+
|
|
107
|
+
path = f"/{self._api_route}/{self._endpoint_route}/{str(uid)}/collaborators"
|
|
108
|
+
self._connection.request("delete", path, json={"email": email})
|
|
109
|
+
|
|
110
|
+
def transfer_ownership(self, uid: Union[UUID, str], email: str) -> None:
|
|
111
|
+
"""Transfer ownership of a workspace to another HydroServer user."""
|
|
112
|
+
|
|
113
|
+
path = f"/{self._api_route}/{self._endpoint_route}/{str(uid)}/transfer"
|
|
114
|
+
self._connection.request("post", path, json={"newOwner": email})
|
|
115
|
+
|
|
116
|
+
def accept_ownership_transfer(self, uid: Union[UUID, str]) -> None:
|
|
117
|
+
"""Accept ownership transfer of a workspace."""
|
|
118
|
+
|
|
119
|
+
path = f"/{self._api_route}/{self._endpoint_route}/{str(uid)}/transfer"
|
|
120
|
+
self._connection.request("put", path)
|
|
121
|
+
|
|
122
|
+
def cancel_ownership_transfer(self, uid: Union[UUID, str]) -> None:
|
|
123
|
+
"""Cancel ownership transfer of a workspace."""
|
|
124
|
+
|
|
125
|
+
path = f"/{self._api_route}/{self._endpoint_route}/{str(uid)}/transfer"
|
|
126
|
+
self._connection.request("delete", path)
|
|
File without changes
|