Skip to content

Commit 0a00a67

Browse files
authored
feat(cockpit): add list datasource endpoint (#318)
1 parent db7dead commit 0a00a67

File tree

8 files changed

+380
-58
lines changed

8 files changed

+380
-58
lines changed

scaleway-async/scaleway_async/cockpit/v1beta1/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from .types import CockpitStatus
44
from .types import DatasourceType
55
from .types import GrafanaUserRole
6+
from .types import ListDatasourcesRequestOrderBy
67
from .types import ListGrafanaUsersRequestOrderBy
78
from .types import ListPlansRequestOrderBy
89
from .types import ListTokensRequestOrderBy
@@ -15,6 +16,7 @@
1516
from .types import Datasource
1617
from .types import GrafanaUser
1718
from .types import ListContactPointsResponse
19+
from .types import ListDatasourcesResponse
1820
from .types import ListGrafanaUsersResponse
1921
from .types import ListPlansResponse
2022
from .types import ListTokensResponse
@@ -29,6 +31,7 @@
2931
"CockpitStatus",
3032
"DatasourceType",
3133
"GrafanaUserRole",
34+
"ListDatasourcesRequestOrderBy",
3235
"ListGrafanaUsersRequestOrderBy",
3336
"ListPlansRequestOrderBy",
3437
"ListTokensRequestOrderBy",
@@ -41,6 +44,7 @@
4144
"Datasource",
4245
"GrafanaUser",
4346
"ListContactPointsResponse",
47+
"ListDatasourcesResponse",
4448
"ListGrafanaUsersResponse",
4549
"ListPlansResponse",
4650
"ListTokensResponse",

scaleway-async/scaleway_async/cockpit/v1beta1/api.py

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from .types import (
1616
DatasourceType,
1717
GrafanaUserRole,
18+
ListDatasourcesRequestOrderBy,
1819
ListGrafanaUsersRequestOrderBy,
1920
ListPlansRequestOrderBy,
2021
ListTokensRequestOrderBy,
@@ -24,6 +25,7 @@
2425
Datasource,
2526
GrafanaUser,
2627
ListContactPointsResponse,
28+
ListDatasourcesResponse,
2729
ListGrafanaUsersResponse,
2830
ListPlansResponse,
2931
ListTokensResponse,
@@ -65,12 +67,13 @@
6567
marshal_SelectPlanRequest,
6668
marshal_TriggerTestAlertRequest,
6769
unmarshal_ContactPoint,
70+
unmarshal_Datasource,
6871
unmarshal_GrafanaUser,
6972
unmarshal_Token,
7073
unmarshal_Cockpit,
7174
unmarshal_CockpitMetrics,
72-
unmarshal_Datasource,
7375
unmarshal_ListContactPointsResponse,
76+
unmarshal_ListDatasourcesResponse,
7477
unmarshal_ListGrafanaUsersResponse,
7578
unmarshal_ListPlansResponse,
7679
unmarshal_ListTokensResponse,
@@ -310,6 +313,82 @@ async def create_datasource(
310313
self._throw_on_error(res)
311314
return unmarshal_Datasource(res.json())
312315

316+
async def list_datasources(
317+
self,
318+
*,
319+
page: Optional[int] = None,
320+
page_size: Optional[int] = None,
321+
order_by: ListDatasourcesRequestOrderBy = ListDatasourcesRequestOrderBy.CREATED_AT_ASC,
322+
project_id: Optional[str] = None,
323+
types: Optional[List[DatasourceType]] = None,
324+
) -> ListDatasourcesResponse:
325+
"""
326+
Get a list of datasources for the specified Project ID.
327+
:param page: Page number.
328+
:param page_size: Page size.
329+
:param order_by: How the response is ordered.
330+
:param project_id: ID of the Project.
331+
:param types: Filter by datasource types.
332+
:return: :class:`ListDatasourcesResponse <ListDatasourcesResponse>`
333+
334+
Usage:
335+
::
336+
337+
result = await api.list_datasources()
338+
"""
339+
340+
res = self._request(
341+
"GET",
342+
f"/cockpit/v1beta1/datasources",
343+
params={
344+
"order_by": order_by,
345+
"page": page,
346+
"page_size": page_size or self.client.default_page_size,
347+
"project_id": project_id or self.client.default_project_id,
348+
"types": types,
349+
},
350+
)
351+
352+
self._throw_on_error(res)
353+
return unmarshal_ListDatasourcesResponse(res.json())
354+
355+
async def list_datasources_all(
356+
self,
357+
*,
358+
page: Optional[int] = None,
359+
page_size: Optional[int] = None,
360+
order_by: Optional[ListDatasourcesRequestOrderBy] = None,
361+
project_id: Optional[str] = None,
362+
types: Optional[List[DatasourceType]] = None,
363+
) -> List[Datasource]:
364+
"""
365+
Get a list of datasources for the specified Project ID.
366+
:param page: Page number.
367+
:param page_size: Page size.
368+
:param order_by: How the response is ordered.
369+
:param project_id: ID of the Project.
370+
:param types: Filter by datasource types.
371+
:return: :class:`List[ListDatasourcesResponse] <List[ListDatasourcesResponse]>`
372+
373+
Usage:
374+
::
375+
376+
result = await api.list_datasources_all()
377+
"""
378+
379+
return await fetch_all_pages_async(
380+
type=ListDatasourcesResponse,
381+
key="datasources",
382+
fetcher=self.list_datasources,
383+
args={
384+
"page": page,
385+
"page_size": page_size,
386+
"order_by": order_by,
387+
"project_id": project_id,
388+
"types": types,
389+
},
390+
)
391+
313392
async def create_token(
314393
self,
315394
*,
@@ -358,7 +437,7 @@ async def list_tokens(
358437
Get a list of tokens associated with the specified Project ID.
359438
:param page: Page number.
360439
:param page_size: Page size.
361-
:param order_by:
440+
:param order_by: How the response is ordered.
362441
:param project_id: ID of the Project.
363442
:return: :class:`ListTokensResponse <ListTokensResponse>`
364443
@@ -394,7 +473,7 @@ async def list_tokens_all(
394473
Get a list of tokens associated with the specified Project ID.
395474
:param page: Page number.
396475
:param page_size: Page size.
397-
:param order_by:
476+
:param order_by: How the response is ordered.
398477
:param project_id: ID of the Project.
399478
:return: :class:`List[ListTokensResponse] <List[ListTokensResponse]>`
400479

scaleway-async/scaleway_async/cockpit/v1beta1/marshalling.py

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
Datasource,
2424
GrafanaUser,
2525
ListContactPointsResponse,
26+
ListDatasourcesResponse,
2627
ListGrafanaUsersResponse,
2728
ListPlansResponse,
2829
ListTokensResponse,
@@ -136,6 +137,32 @@ def unmarshal_ContactPoint(data: Any) -> ContactPoint:
136137
return ContactPoint(**args)
137138

138139

140+
def unmarshal_Datasource(data: Any) -> Datasource:
141+
if type(data) is not dict:
142+
raise TypeError(
143+
f"Unmarshalling the type 'Datasource' failed as data isn't a dictionary."
144+
)
145+
146+
args: Dict[str, Any] = {}
147+
148+
field = data.get("id", None)
149+
args["id"] = field
150+
151+
field = data.get("name", None)
152+
args["name"] = field
153+
154+
field = data.get("project_id", None)
155+
args["project_id"] = field
156+
157+
field = data.get("type", None)
158+
args["type_"] = field
159+
160+
field = data.get("url", None)
161+
args["url"] = field
162+
163+
return Datasource(**args)
164+
165+
139166
def unmarshal_GrafanaUser(data: Any) -> GrafanaUser:
140167
if type(data) is not dict:
141168
raise TypeError(
@@ -271,32 +298,6 @@ def unmarshal_CockpitMetrics(data: Any) -> CockpitMetrics:
271298
return CockpitMetrics(**args)
272299

273300

274-
def unmarshal_Datasource(data: Any) -> Datasource:
275-
if type(data) is not dict:
276-
raise TypeError(
277-
f"Unmarshalling the type 'Datasource' failed as data isn't a dictionary."
278-
)
279-
280-
args: Dict[str, Any] = {}
281-
282-
field = data.get("id", None)
283-
args["id"] = field
284-
285-
field = data.get("name", None)
286-
args["name"] = field
287-
288-
field = data.get("project_id", None)
289-
args["project_id"] = field
290-
291-
field = data.get("type", None)
292-
args["type_"] = field
293-
294-
field = data.get("url", None)
295-
args["url"] = field
296-
297-
return Datasource(**args)
298-
299-
300301
def unmarshal_ListContactPointsResponse(data: Any) -> ListContactPointsResponse:
301302
if type(data) is not dict:
302303
raise TypeError(
@@ -322,6 +323,25 @@ def unmarshal_ListContactPointsResponse(data: Any) -> ListContactPointsResponse:
322323
return ListContactPointsResponse(**args)
323324

324325

326+
def unmarshal_ListDatasourcesResponse(data: Any) -> ListDatasourcesResponse:
327+
if type(data) is not dict:
328+
raise TypeError(
329+
f"Unmarshalling the type 'ListDatasourcesResponse' failed as data isn't a dictionary."
330+
)
331+
332+
args: Dict[str, Any] = {}
333+
334+
field = data.get("datasources", None)
335+
args["datasources"] = (
336+
[unmarshal_Datasource(v) for v in field] if field is not None else None
337+
)
338+
339+
field = data.get("total_count", None)
340+
args["total_count"] = field
341+
342+
return ListDatasourcesResponse(**args)
343+
344+
325345
def unmarshal_ListGrafanaUsersResponse(data: Any) -> ListGrafanaUsersResponse:
326346
if type(data) is not dict:
327347
raise TypeError(

scaleway-async/scaleway_async/cockpit/v1beta1/types.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ def __str__(self) -> str:
4747
return str(self.value)
4848

4949

50+
class ListDatasourcesRequestOrderBy(str, Enum, metaclass=StrEnumMeta):
51+
CREATED_AT_ASC = "created_at_asc"
52+
CREATED_AT_DESC = "created_at_desc"
53+
NAME_ASC = "name_asc"
54+
NAME_DESC = "name_desc"
55+
56+
def __str__(self) -> str:
57+
return str(self.value)
58+
59+
5060
class ListGrafanaUsersRequestOrderBy(str, Enum, metaclass=StrEnumMeta):
5161
LOGIN_ASC = "login_asc"
5262
LOGIN_DESC = "login_desc"
@@ -271,6 +281,23 @@ class ListContactPointsResponse:
271281
"""
272282

273283

284+
@dataclass
285+
class ListDatasourcesResponse:
286+
"""
287+
List datasources response.
288+
"""
289+
290+
total_count: int
291+
"""
292+
Count of all datasources corresponding to the request.
293+
"""
294+
295+
datasources: List[Datasource]
296+
"""
297+
List of the datasources within the pagination.
298+
"""
299+
300+
274301
@dataclass
275302
class ListGrafanaUsersResponse:
276303
"""
@@ -542,6 +569,34 @@ class CreateDatasourceRequest:
542569
"""
543570

544571

572+
@dataclass
573+
class ListDatasourcesRequest:
574+
page: Optional[int]
575+
"""
576+
Page number.
577+
"""
578+
579+
page_size: Optional[int]
580+
"""
581+
Page size.
582+
"""
583+
584+
order_by: Optional[ListDatasourcesRequestOrderBy]
585+
"""
586+
How the response is ordered.
587+
"""
588+
589+
project_id: Optional[str]
590+
"""
591+
ID of the Project.
592+
"""
593+
594+
types: Optional[List[DatasourceType]]
595+
"""
596+
Filter by datasource types.
597+
"""
598+
599+
545600
@dataclass
546601
class CreateTokenRequest:
547602
project_id: Optional[str]
@@ -573,6 +628,9 @@ class ListTokensRequest:
573628
"""
574629

575630
order_by: Optional[ListTokensRequestOrderBy]
631+
"""
632+
How the response is ordered.
633+
"""
576634

577635
project_id: Optional[str]
578636
"""

scaleway/scaleway/cockpit/v1beta1/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from .types import CockpitStatus
44
from .types import DatasourceType
55
from .types import GrafanaUserRole
6+
from .types import ListDatasourcesRequestOrderBy
67
from .types import ListGrafanaUsersRequestOrderBy
78
from .types import ListPlansRequestOrderBy
89
from .types import ListTokensRequestOrderBy
@@ -15,6 +16,7 @@
1516
from .types import Datasource
1617
from .types import GrafanaUser
1718
from .types import ListContactPointsResponse
19+
from .types import ListDatasourcesResponse
1820
from .types import ListGrafanaUsersResponse
1921
from .types import ListPlansResponse
2022
from .types import ListTokensResponse
@@ -29,6 +31,7 @@
2931
"CockpitStatus",
3032
"DatasourceType",
3133
"GrafanaUserRole",
34+
"ListDatasourcesRequestOrderBy",
3235
"ListGrafanaUsersRequestOrderBy",
3336
"ListPlansRequestOrderBy",
3437
"ListTokensRequestOrderBy",
@@ -41,6 +44,7 @@
4144
"Datasource",
4245
"GrafanaUser",
4346
"ListContactPointsResponse",
47+
"ListDatasourcesResponse",
4448
"ListGrafanaUsersResponse",
4549
"ListPlansResponse",
4650
"ListTokensResponse",

0 commit comments

Comments
 (0)