Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions scaleway-async/scaleway_async/cockpit/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .types import ListDataSourcesRequestOrderBy
from .types import ListGrafanaUsersRequestOrderBy
from .types import ListPlansRequestOrderBy
from .types import ListProductsRequestOrderBy
from .types import ListTokensRequestOrderBy
from .types import PlanName
from .types import TokenScope
Expand All @@ -22,6 +23,7 @@
from .types import GrafanaProductDashboard
from .types import GrafanaUser
from .types import Plan
from .types import Product
from .types import Token
from .types import Usage
from .types import AlertManager
Expand All @@ -47,6 +49,7 @@
from .types import ListGrafanaProductDashboardsResponse
from .types import ListGrafanaUsersResponse
from .types import ListPlansResponse
from .types import ListProductsResponse
from .types import ListTokensResponse
from .types import RegionalApiCreateContactPointRequest
from .types import RegionalApiCreateDataSourceRequest
Expand All @@ -67,6 +70,7 @@
from .types import RegionalApiListAlertsRequest
from .types import RegionalApiListContactPointsRequest
from .types import RegionalApiListDataSourcesRequest
from .types import RegionalApiListProductsRequest
from .types import RegionalApiListTokensRequest
from .types import RegionalApiTriggerTestAlertRequest
from .types import RegionalApiUpdateContactPointRequest
Expand All @@ -84,6 +88,7 @@
"ListDataSourcesRequestOrderBy",
"ListGrafanaUsersRequestOrderBy",
"ListPlansRequestOrderBy",
"ListProductsRequestOrderBy",
"ListTokensRequestOrderBy",
"PlanName",
"TokenScope",
Expand All @@ -98,6 +103,7 @@
"GrafanaProductDashboard",
"GrafanaUser",
"Plan",
"Product",
"Token",
"Usage",
"AlertManager",
Expand All @@ -123,6 +129,7 @@
"ListGrafanaProductDashboardsResponse",
"ListGrafanaUsersResponse",
"ListPlansResponse",
"ListProductsResponse",
"ListTokensResponse",
"RegionalApiCreateContactPointRequest",
"RegionalApiCreateDataSourceRequest",
Expand All @@ -143,6 +150,7 @@
"RegionalApiListAlertsRequest",
"RegionalApiListContactPointsRequest",
"RegionalApiListDataSourcesRequest",
"RegionalApiListProductsRequest",
"RegionalApiListTokensRequest",
"RegionalApiTriggerTestAlertRequest",
"RegionalApiUpdateContactPointRequest",
Expand Down
77 changes: 77 additions & 0 deletions scaleway-async/scaleway_async/cockpit/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
ListDataSourcesRequestOrderBy,
ListGrafanaUsersRequestOrderBy,
ListPlansRequestOrderBy,
ListProductsRequestOrderBy,
ListTokensRequestOrderBy,
PlanName,
TokenScope,
Expand All @@ -44,8 +45,10 @@
ListGrafanaProductDashboardsResponse,
ListGrafanaUsersResponse,
ListPlansResponse,
ListProductsResponse,
ListTokensResponse,
Plan,
Product,
RegionalApiCreateContactPointRequest,
RegionalApiCreateDataSourceRequest,
RegionalApiCreateTokenRequest,
Expand Down Expand Up @@ -79,6 +82,7 @@
unmarshal_ListGrafanaProductDashboardsResponse,
unmarshal_ListGrafanaUsersResponse,
unmarshal_ListPlansResponse,
unmarshal_ListProductsResponse,
unmarshal_ListTokensResponse,
unmarshal_UsageOverview,
marshal_GlobalApiCreateGrafanaUserRequest,
Expand Down Expand Up @@ -1126,6 +1130,79 @@ async def delete_token(

self._throw_on_error(res)

async def list_products(
self,
*,
region: Optional[ScwRegion] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
order_by: Optional[ListProductsRequestOrderBy] = None,
) -> ListProductsResponse:
"""
List all Scaleway products that send metrics and/or logs to Cockpit.
:param region: Region to target. If none is passed will use default region from the config.
:param page: Page number to return from the paginated results.
:param page_size: Number of products to return per page.
:param order_by: Sort order for products in the response.
:return: :class:`ListProductsResponse <ListProductsResponse>`

Usage:
::

result = await api.list_products()
"""

param_region = validate_path_param(
"region", region or self.client.default_region
)

res = self._request(
"GET",
f"/cockpit/v1/regions/{param_region}/products",
params={
"order_by": order_by,
"page": page,
"page_size": page_size or self.client.default_page_size,
},
)

self._throw_on_error(res)
return unmarshal_ListProductsResponse(res.json())

async def list_products_all(
self,
*,
region: Optional[ScwRegion] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
order_by: Optional[ListProductsRequestOrderBy] = None,
) -> list[Product]:
"""
List all Scaleway products that send metrics and/or logs to Cockpit.
:param region: Region to target. If none is passed will use default region from the config.
:param page: Page number to return from the paginated results.
:param page_size: Number of products to return per page.
:param order_by: Sort order for products in the response.
:return: :class:`list[Product] <list[Product]>`

Usage:
::

result = await api.list_products_all()
"""

return await fetch_all_pages_async(
type=ListProductsResponse,
key="products_list",
fetcher=self.list_products,
args={
"region": region,
"page": page,
"page_size": page_size,
"order_by": order_by,
},
)

async def get_alert_manager(
self,
*,
Expand Down
62 changes: 62 additions & 0 deletions scaleway-async/scaleway_async/cockpit/v1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
ListGrafanaProductDashboardsResponse,
ListGrafanaUsersResponse,
ListPlansResponse,
Product,
ListProductsResponse,
ListTokensResponse,
Usage,
UsageOverview,
Expand Down Expand Up @@ -873,6 +875,66 @@ def unmarshal_ListPlansResponse(data: Any) -> ListPlansResponse:
return ListPlansResponse(**args)


def unmarshal_Product(data: Any) -> Product:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'Product' failed as data isn't a dictionary."
)

args: dict[str, Any] = {}

field = data.get("name", None)
if field is not None:
args["name"] = field
else:
args["name"] = None

field = data.get("display_name", None)
if field is not None:
args["display_name"] = field
else:
args["display_name"] = None

field = data.get("family_name", None)
if field is not None:
args["family_name"] = field
else:
args["family_name"] = None

field = data.get("resource_types", None)
if field is not None:
args["resource_types"] = field
else:
args["resource_types"] = None

return Product(**args)


def unmarshal_ListProductsResponse(data: Any) -> ListProductsResponse:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'ListProductsResponse' failed as data isn't a dictionary."
)

args: dict[str, Any] = {}

field = data.get("products_list", None)
if field is not None:
args["products_list"] = (
[unmarshal_Product(v) for v in field] if field is not None else None
)
else:
args["products_list"] = None

field = data.get("total_count", None)
if field is not None:
args["total_count"] = field
else:
args["total_count"] = None

return ListProductsResponse(**args)


def unmarshal_ListTokensResponse(data: Any) -> ListTokensResponse:
if not isinstance(data, dict):
raise TypeError(
Expand Down
55 changes: 55 additions & 0 deletions scaleway-async/scaleway_async/cockpit/v1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ def __str__(self) -> str:
return str(self.value)


class ListProductsRequestOrderBy(str, Enum, metaclass=StrEnumMeta):
CREATED_AT_ASC = "created_at_asc"
CREATED_AT_DESC = "created_at_desc"
DISPLAY_NAME_ASC = "display_name_asc"
DISPLAY_NAME_DESC = "display_name_desc"
FAMILY_NAME_ASC = "family_name_asc"
FAMILY_NAME_DESC = "family_name_desc"

def __str__(self) -> str:
return str(self.value)


class ListTokensRequestOrderBy(str, Enum, metaclass=StrEnumMeta):
CREATED_AT_ASC = "created_at_asc"
CREATED_AT_DESC = "created_at_desc"
Expand Down Expand Up @@ -444,6 +456,14 @@ class Plan:
"""


@dataclass
class Product:
name: str
display_name: str
family_name: str
resource_types: list[str]


@dataclass
class Token:
"""
Expand Down Expand Up @@ -964,6 +984,12 @@ class ListPlansResponse:
"""


@dataclass
class ListProductsResponse:
products_list: list[Product]
total_count: int


@dataclass
class ListTokensResponse:
"""
Expand Down Expand Up @@ -1382,6 +1408,35 @@ class RegionalApiListDataSourcesRequest:
"""


@dataclass
class RegionalApiListProductsRequest:
"""
List all Scaleway products that send metrics and/or logs to Cockpit.
"""

region: Optional[ScwRegion] = None
"""
Region to target. If none is passed will use default region from the config.
"""

page: Optional[int] = 0
"""
Page number to return from the paginated results.
"""

page_size: Optional[int] = 0
"""
Number of products to return per page.
"""

order_by: Optional[ListProductsRequestOrderBy] = (
ListProductsRequestOrderBy.CREATED_AT_ASC
)
"""
Sort order for products in the response.
"""


@dataclass
class RegionalApiListTokensRequest:
"""
Expand Down
8 changes: 8 additions & 0 deletions scaleway/scaleway/cockpit/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .types import ListDataSourcesRequestOrderBy
from .types import ListGrafanaUsersRequestOrderBy
from .types import ListPlansRequestOrderBy
from .types import ListProductsRequestOrderBy
from .types import ListTokensRequestOrderBy
from .types import PlanName
from .types import TokenScope
Expand All @@ -22,6 +23,7 @@
from .types import GrafanaProductDashboard
from .types import GrafanaUser
from .types import Plan
from .types import Product
from .types import Token
from .types import Usage
from .types import AlertManager
Expand All @@ -47,6 +49,7 @@
from .types import ListGrafanaProductDashboardsResponse
from .types import ListGrafanaUsersResponse
from .types import ListPlansResponse
from .types import ListProductsResponse
from .types import ListTokensResponse
from .types import RegionalApiCreateContactPointRequest
from .types import RegionalApiCreateDataSourceRequest
Expand All @@ -67,6 +70,7 @@
from .types import RegionalApiListAlertsRequest
from .types import RegionalApiListContactPointsRequest
from .types import RegionalApiListDataSourcesRequest
from .types import RegionalApiListProductsRequest
from .types import RegionalApiListTokensRequest
from .types import RegionalApiTriggerTestAlertRequest
from .types import RegionalApiUpdateContactPointRequest
Expand All @@ -84,6 +88,7 @@
"ListDataSourcesRequestOrderBy",
"ListGrafanaUsersRequestOrderBy",
"ListPlansRequestOrderBy",
"ListProductsRequestOrderBy",
"ListTokensRequestOrderBy",
"PlanName",
"TokenScope",
Expand All @@ -98,6 +103,7 @@
"GrafanaProductDashboard",
"GrafanaUser",
"Plan",
"Product",
"Token",
"Usage",
"AlertManager",
Expand All @@ -123,6 +129,7 @@
"ListGrafanaProductDashboardsResponse",
"ListGrafanaUsersResponse",
"ListPlansResponse",
"ListProductsResponse",
"ListTokensResponse",
"RegionalApiCreateContactPointRequest",
"RegionalApiCreateDataSourceRequest",
Expand All @@ -143,6 +150,7 @@
"RegionalApiListAlertsRequest",
"RegionalApiListContactPointsRequest",
"RegionalApiListDataSourcesRequest",
"RegionalApiListProductsRequest",
"RegionalApiListTokensRequest",
"RegionalApiTriggerTestAlertRequest",
"RegionalApiUpdateContactPointRequest",
Expand Down
Loading