hydroserverpy 1.2.0__py3-none-any.whl → 1.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of hydroserverpy might be problematic. Click here for more details.

Files changed (47) hide show
  1. hydroserverpy/__init__.py +1 -1
  2. hydroserverpy/api/{main.py → client.py} +52 -22
  3. hydroserverpy/api/models/__init__.py +1 -2
  4. hydroserverpy/api/models/base.py +180 -47
  5. hydroserverpy/api/models/etl/data_archive.py +31 -59
  6. hydroserverpy/api/models/etl/data_source.py +34 -76
  7. hydroserverpy/api/models/etl/orchestration_system.py +23 -38
  8. hydroserverpy/api/models/iam/apikey.py +57 -38
  9. hydroserverpy/api/models/iam/collaborator.py +55 -19
  10. hydroserverpy/api/models/iam/role.py +32 -4
  11. hydroserverpy/api/models/iam/workspace.py +58 -86
  12. hydroserverpy/api/models/sta/datastream.py +122 -214
  13. hydroserverpy/api/models/sta/observation.py +101 -0
  14. hydroserverpy/api/models/sta/observed_property.py +18 -53
  15. hydroserverpy/api/models/sta/processing_level.py +16 -31
  16. hydroserverpy/api/models/sta/result_qualifier.py +16 -31
  17. hydroserverpy/api/models/sta/sensor.py +27 -88
  18. hydroserverpy/api/models/sta/thing.py +48 -152
  19. hydroserverpy/api/models/sta/unit.py +16 -29
  20. hydroserverpy/api/services/__init__.py +1 -0
  21. hydroserverpy/api/services/base.py +92 -76
  22. hydroserverpy/api/services/etl/data_archive.py +42 -72
  23. hydroserverpy/api/services/etl/data_source.py +42 -72
  24. hydroserverpy/api/services/etl/orchestration_system.py +25 -33
  25. hydroserverpy/api/services/iam/role.py +38 -0
  26. hydroserverpy/api/services/iam/workspace.py +96 -99
  27. hydroserverpy/api/services/sta/datastream.py +150 -211
  28. hydroserverpy/api/services/sta/observed_property.py +31 -49
  29. hydroserverpy/api/services/sta/processing_level.py +30 -36
  30. hydroserverpy/api/services/sta/result_qualifier.py +24 -34
  31. hydroserverpy/api/services/sta/sensor.py +34 -48
  32. hydroserverpy/api/services/sta/thing.py +96 -89
  33. hydroserverpy/api/services/sta/unit.py +30 -34
  34. hydroserverpy/api/utils.py +22 -0
  35. hydroserverpy/etl/extractors/base.py +3 -5
  36. hydroserverpy/etl/loaders/hydroserver_loader.py +1 -0
  37. hydroserverpy/etl/timestamp_parser.py +82 -48
  38. hydroserverpy/etl/transformers/base.py +6 -10
  39. hydroserverpy/etl_csv/hydroserver_etl_csv.py +18 -24
  40. {hydroserverpy-1.2.0.dist-info → hydroserverpy-1.3.0.dist-info}/METADATA +1 -1
  41. hydroserverpy-1.3.0.dist-info/RECORD +70 -0
  42. hydroserverpy/api/http.py +0 -22
  43. hydroserverpy-1.2.0.dist-info/RECORD +0 -68
  44. {hydroserverpy-1.2.0.dist-info → hydroserverpy-1.3.0.dist-info}/WHEEL +0 -0
  45. {hydroserverpy-1.2.0.dist-info → hydroserverpy-1.3.0.dist-info}/licenses/LICENSE +0 -0
  46. {hydroserverpy-1.2.0.dist-info → hydroserverpy-1.3.0.dist-info}/top_level.txt +0 -0
  47. {hydroserverpy-1.2.0.dist-info → hydroserverpy-1.3.0.dist-info}/zip-safe +0 -0
@@ -1,8 +1,8 @@
1
- from typing import List, Union, Optional, TYPE_CHECKING
1
+ from typing import List, Union, Optional, ClassVar, TYPE_CHECKING
2
2
  from uuid import UUID
3
3
  from datetime import datetime
4
- from pydantic import BaseModel, Field, EmailStr
5
- from ..base import HydroServerModel
4
+ from pydantic import Field, EmailStr
5
+ from ..base import HydroServerBaseModel
6
6
 
7
7
  if TYPE_CHECKING:
8
8
  from hydroserverpy import HydroServer
@@ -24,21 +24,21 @@ if TYPE_CHECKING:
24
24
  )
25
25
 
26
26
 
27
- class WorkspaceFields(BaseModel):
27
+ class Workspace(HydroServerBaseModel):
28
28
  name: str = Field(..., max_length=255)
29
29
  is_private: bool
30
- owner: "Account" = Field(..., json_schema_extra={"read_only": True})
30
+ owner: "Account"
31
31
  collaborator_role: Optional["Role"] = None
32
32
  pending_transfer_to: Optional["Account"] = None
33
33
 
34
+ _editable_fields: ClassVar[set[str]] = {"name", "is_private"}
35
+
36
+ def __init__(self, client: "HydroServer", **data):
37
+ super().__init__(client=client, service=client.workspaces, **data)
34
38
 
35
- class Workspace(HydroServerModel, WorkspaceFields):
36
- def __init__(self, _connection: "HydroServer", _uid: Union[UUID, str], **data):
37
- super().__init__(
38
- _connection=_connection, _model_ref="workspaces", _uid=_uid, **data
39
- )
40
39
  self._roles = None
41
40
  self._collaborators = None
41
+ self._apikeys = None
42
42
  self._things = None
43
43
  self._observedproperties = None
44
44
  self._processinglevels = None
@@ -50,12 +50,16 @@ class Workspace(HydroServerModel, WorkspaceFields):
50
50
  self._datasources = None
51
51
  self._dataarchives = None
52
52
 
53
+ @classmethod
54
+ def get_route(cls):
55
+ return "workspaces"
56
+
53
57
  @property
54
58
  def roles(self) -> List["Role"]:
55
59
  """The roles that can be assigned for this workspace."""
56
60
 
57
61
  if self._roles is None:
58
- self._roles = self._connection.workspaces.list_roles(uid=self.uid)
62
+ self._roles = self.client.roles.list(workspace=self.uid, fetch_all=True).items
59
63
 
60
64
  return self._roles
61
65
 
@@ -64,18 +68,25 @@ class Workspace(HydroServerModel, WorkspaceFields):
64
68
  """The collaborators associated with this workspace."""
65
69
 
66
70
  if self._collaborators is None:
67
- self._collaborators = self._connection.workspaces.list_collaborators(
68
- uid=self.uid
69
- )
71
+ self._collaborators = self.client.workspaces.list_collaborators(uid=self.uid)
70
72
 
71
73
  return self._collaborators
72
74
 
75
+ @property
76
+ def apikeys(self) -> List["APIKey"]:
77
+ """The API keys associated with this workspace."""
78
+
79
+ if self._apikeys is None:
80
+ self._apikeys = self.client.workspaces.list_api_keys(uid=self.uid)
81
+
82
+ return self._apikeys
83
+
73
84
  @property
74
85
  def things(self) -> List["Thing"]:
75
86
  """The things associated with this workspace."""
76
87
 
77
88
  if self._things is None:
78
- self._things = self._connection.things.list(workspace=self.uid)
89
+ self._things = self.client.things.list(workspace=self.uid, fetch_all=True).items
79
90
 
80
91
  return self._things
81
92
 
@@ -84,9 +95,7 @@ class Workspace(HydroServerModel, WorkspaceFields):
84
95
  """The observed properties associated with this workspace."""
85
96
 
86
97
  if self._observedproperties is None:
87
- self._observedproperties = self._connection.observedproperties.list(
88
- workspace=self.uid
89
- )
98
+ self._observedproperties = self.client.observedproperties.list(workspace=self.uid, fetch_all=True).items
90
99
 
91
100
  return self._observedproperties
92
101
 
@@ -95,9 +104,7 @@ class Workspace(HydroServerModel, WorkspaceFields):
95
104
  """The processing levels associated with this workspace."""
96
105
 
97
106
  if self._processinglevels is None:
98
- self._processinglevels = self._connection.processinglevels.list(
99
- workspace=self.uid
100
- )
107
+ self._processinglevels = self.client.processinglevels.list(workspace=self.uid, fetch_all=True).items
101
108
 
102
109
  return self._processinglevels
103
110
 
@@ -106,9 +113,7 @@ class Workspace(HydroServerModel, WorkspaceFields):
106
113
  """The result qualifiers associated with this workspace."""
107
114
 
108
115
  if self._resultqualifiers is None:
109
- self._resultqualifiers = self._connection.resultqualifiers.list(
110
- workspace=self.uid
111
- )
116
+ self._resultqualifiers = self.client.resultqualifiers.list(workspace=self.uid, fetch_all=True).items
112
117
 
113
118
  return self._resultqualifiers
114
119
 
@@ -117,7 +122,7 @@ class Workspace(HydroServerModel, WorkspaceFields):
117
122
  """The units associated with this workspace."""
118
123
 
119
124
  if self._units is None:
120
- self._units = self._connection.units.list(workspace=self.uid)
125
+ self._units = self.client.units.list(workspace=self.uid, fetch_all=True).items
121
126
 
122
127
  return self._units
123
128
 
@@ -126,7 +131,7 @@ class Workspace(HydroServerModel, WorkspaceFields):
126
131
  """The sensors associated with this workspace."""
127
132
 
128
133
  if self._sensors is None:
129
- self._sensors = self._connection.sensors.list(workspace=self.uid)
134
+ self._sensors = self.client.sensors.list(workspace=self.uid, fetch_all=True).items
130
135
 
131
136
  return self._sensors
132
137
 
@@ -135,7 +140,7 @@ class Workspace(HydroServerModel, WorkspaceFields):
135
140
  """The datastreams associated with this workspace."""
136
141
 
137
142
  if self._datastreams is None:
138
- self._datastreams = self._connection.datastreams.list(workspace=self.uid)
143
+ self._datastreams = self.client.datastreams.list(workspace=self.uid, fetch_all=True).items
139
144
 
140
145
  return self._datastreams
141
146
 
@@ -144,9 +149,7 @@ class Workspace(HydroServerModel, WorkspaceFields):
144
149
  """The orchestration systems associated with this workspace."""
145
150
 
146
151
  if self._orchestrationsystems is None:
147
- self._orchestrationsystems = self._connection.orchestrationsystems.list(
148
- workspace=self.uid
149
- )
152
+ self._orchestrationsystems = self.client.orchestrationsystems.list(workspace=self.uid, fetch_all=True).items
150
153
 
151
154
  return self._orchestrationsystems
152
155
 
@@ -155,7 +158,7 @@ class Workspace(HydroServerModel, WorkspaceFields):
155
158
  """The data sources associated with this workspace."""
156
159
 
157
160
  if self._datasources is None:
158
- self._datasources = self._connection.datasources.list(workspace=self.uid)
161
+ self._datasources = self.client.datasources.list(workspace=self.uid, fetch_all=True).items
159
162
 
160
163
  return self._datasources
161
164
 
@@ -164,46 +167,10 @@ class Workspace(HydroServerModel, WorkspaceFields):
164
167
  """The data archives associated with this workspace."""
165
168
 
166
169
  if self._dataarchives is None:
167
- self._dataarchives = self._connection.dataarchives.list(workspace=self.uid)
170
+ self._dataarchives = self.client.dataarchives.list(workspace=self.uid, fetch_all=True).items
168
171
 
169
172
  return self._dataarchives
170
173
 
171
- def refresh(self) -> None:
172
- """Refresh the workspace details from HydroServer."""
173
-
174
- self._roles = None
175
- self._collaborators = None
176
- self._things = None
177
- self._observedproperties = None
178
- self._processinglevels = None
179
- self._units = None
180
- self._sensors = None
181
- self._datastreams = None
182
- super()._refresh()
183
-
184
- def save(self):
185
- """Save changes to this workspace to HydroServer."""
186
-
187
- super()._save()
188
-
189
- def delete(self):
190
- """Delete this workspace from HydroServer."""
191
-
192
- super()._delete()
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
174
  def create_api_key(
208
175
  self,
209
176
  role: Union["Role", UUID, str],
@@ -214,7 +181,7 @@ class Workspace(HydroServerModel, WorkspaceFields):
214
181
  ):
215
182
  """Create an API key associated with this workspace."""
216
183
 
217
- api_key, key = self._connection.workspaces.create_api_key(
184
+ response, key = self.client.workspaces.create_api_key(
218
185
  uid=self.uid,
219
186
  role=role,
220
187
  name=name,
@@ -222,21 +189,22 @@ class Workspace(HydroServerModel, WorkspaceFields):
222
189
  is_active=is_active,
223
190
  expires_at=expires_at
224
191
  )
192
+ self._apikeys = None
225
193
 
226
- return api_key, key
194
+ return response, key
227
195
 
228
196
  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] = ...
197
+ self,
198
+ api_key_id: Union[UUID, str],
199
+ role: Union["Role", UUID, str] = ...,
200
+ name: str = ...,
201
+ description: Optional[str] = ...,
202
+ is_active: bool = ...,
203
+ expires_at: Optional[datetime] = ...
236
204
  ):
237
205
  """Create an API key associated with this workspace."""
238
206
 
239
- return self._connection.workspaces.update_api_key(
207
+ response = self.client.workspaces.update_api_key(
240
208
  uid=self.uid,
241
209
  api_key_id=api_key_id,
242
210
  role=role,
@@ -245,19 +213,23 @@ class Workspace(HydroServerModel, WorkspaceFields):
245
213
  is_active=is_active,
246
214
  expires_at=expires_at
247
215
  )
216
+ self._apikeys = None
217
+
218
+ return response
248
219
 
249
220
  def delete_api_key(self, api_key_id: Union[UUID, str]):
250
221
  """Delete an API key associated with this workspace."""
251
222
 
252
- return self._connection.workspaces.delete_api_key(
223
+ self.client.workspaces.delete_api_key(
253
224
  uid=self.uid,
254
225
  api_key_id=api_key_id
255
226
  )
227
+ self._apikeys = None
256
228
 
257
229
  def regenerate_api_key(self, api_key_id: Union[UUID, str]):
258
230
  """Regenerate an API key associated with this workspace."""
259
231
 
260
- api_key, key = self._connection.workspaces.regenerate_api_key(
232
+ api_key, key = self.client.workspaces.regenerate_api_key(
261
233
  uid=self.uid,
262
234
  api_key_id=api_key_id
263
235
  )
@@ -269,7 +241,7 @@ class Workspace(HydroServerModel, WorkspaceFields):
269
241
  ) -> "Collaborator":
270
242
  """Add a new collaborator to the workspace."""
271
243
 
272
- response = self._connection.workspaces.add_collaborator(
244
+ response = self.client.workspaces.add_collaborator(
273
245
  uid=self.uid, email=email, role=role
274
246
  )
275
247
  self._collaborators = None
@@ -281,7 +253,7 @@ class Workspace(HydroServerModel, WorkspaceFields):
281
253
  ) -> "Collaborator":
282
254
  """Edit a collaborator's role in this workspace."""
283
255
 
284
- response = self._connection.workspaces.edit_collaborator_role(
256
+ response = self.client.workspaces.edit_collaborator_role(
285
257
  uid=self.uid, email=email, role=role
286
258
  )
287
259
  self._collaborators = None
@@ -291,23 +263,23 @@ class Workspace(HydroServerModel, WorkspaceFields):
291
263
  def remove_collaborator(self, email: EmailStr) -> None:
292
264
  """Remove a collaborator from the workspace."""
293
265
 
294
- self._connection.workspaces.remove_collaborator(uid=self.uid, email=email)
266
+ self.client.workspaces.remove_collaborator(uid=self.uid, email=email)
295
267
  self._collaborators = None
296
268
 
297
269
  def transfer_ownership(self, email: EmailStr) -> None:
298
270
  """Transfer ownership of this workspace to another HydroServer user."""
299
271
 
300
- self._connection.workspaces.transfer_ownership(uid=self.uid, email=email)
272
+ self.client.workspaces.transfer_ownership(uid=self.uid, email=email)
301
273
  self.refresh()
302
274
 
303
275
  def accept_ownership_transfer(self) -> None:
304
276
  """Accept ownership transfer of this workspace."""
305
277
 
306
- self._connection.workspaces.accept_ownership_transfer(uid=self.uid)
278
+ self.client.workspaces.accept_ownership_transfer(uid=self.uid)
307
279
  self.refresh()
308
280
 
309
281
  def cancel_ownership_transfer(self) -> None:
310
282
  """Cancel ownership transfer of this workspace."""
311
283
 
312
- self._connection.workspaces.cancel_ownership_transfer(uid=self.uid)
284
+ self.client.workspaces.cancel_ownership_transfer(uid=self.uid)
313
285
  self.refresh()