diff --git a/scaleway-async/scaleway_async/cockpit/v1/__init__.py b/scaleway-async/scaleway_async/cockpit/v1/__init__.py index 42495d8e3..17d22f1c9 100644 --- a/scaleway-async/scaleway_async/cockpit/v1/__init__.py +++ b/scaleway-async/scaleway_async/cockpit/v1/__init__.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -84,6 +88,7 @@ "ListDataSourcesRequestOrderBy", "ListGrafanaUsersRequestOrderBy", "ListPlansRequestOrderBy", + "ListProductsRequestOrderBy", "ListTokensRequestOrderBy", "PlanName", "TokenScope", @@ -98,6 +103,7 @@ "GrafanaProductDashboard", "GrafanaUser", "Plan", + "Product", "Token", "Usage", "AlertManager", @@ -123,6 +129,7 @@ "ListGrafanaProductDashboardsResponse", "ListGrafanaUsersResponse", "ListPlansResponse", + "ListProductsResponse", "ListTokensResponse", "RegionalApiCreateContactPointRequest", "RegionalApiCreateDataSourceRequest", @@ -143,6 +150,7 @@ "RegionalApiListAlertsRequest", "RegionalApiListContactPointsRequest", "RegionalApiListDataSourcesRequest", + "RegionalApiListProductsRequest", "RegionalApiListTokensRequest", "RegionalApiTriggerTestAlertRequest", "RegionalApiUpdateContactPointRequest", diff --git a/scaleway-async/scaleway_async/cockpit/v1/api.py b/scaleway-async/scaleway_async/cockpit/v1/api.py index 9e9be7753..eb98c80c9 100644 --- a/scaleway-async/scaleway_async/cockpit/v1/api.py +++ b/scaleway-async/scaleway_async/cockpit/v1/api.py @@ -20,6 +20,7 @@ ListDataSourcesRequestOrderBy, ListGrafanaUsersRequestOrderBy, ListPlansRequestOrderBy, + ListProductsRequestOrderBy, ListTokensRequestOrderBy, PlanName, TokenScope, @@ -44,8 +45,10 @@ ListGrafanaProductDashboardsResponse, ListGrafanaUsersResponse, ListPlansResponse, + ListProductsResponse, ListTokensResponse, Plan, + Product, RegionalApiCreateContactPointRequest, RegionalApiCreateDataSourceRequest, RegionalApiCreateTokenRequest, @@ -79,6 +82,7 @@ unmarshal_ListGrafanaProductDashboardsResponse, unmarshal_ListGrafanaUsersResponse, unmarshal_ListPlansResponse, + unmarshal_ListProductsResponse, unmarshal_ListTokensResponse, unmarshal_UsageOverview, marshal_GlobalApiCreateGrafanaUserRequest, @@ -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 ` + + 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] ` + + 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, *, diff --git a/scaleway-async/scaleway_async/cockpit/v1/marshalling.py b/scaleway-async/scaleway_async/cockpit/v1/marshalling.py index f9e65477f..ba829fbbf 100644 --- a/scaleway-async/scaleway_async/cockpit/v1/marshalling.py +++ b/scaleway-async/scaleway_async/cockpit/v1/marshalling.py @@ -41,6 +41,8 @@ ListGrafanaProductDashboardsResponse, ListGrafanaUsersResponse, ListPlansResponse, + Product, + ListProductsResponse, ListTokensResponse, Usage, UsageOverview, @@ -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( diff --git a/scaleway-async/scaleway_async/cockpit/v1/types.py b/scaleway-async/scaleway_async/cockpit/v1/types.py index c145d75d5..32d5aa9b0 100644 --- a/scaleway-async/scaleway_async/cockpit/v1/types.py +++ b/scaleway-async/scaleway_async/cockpit/v1/types.py @@ -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" @@ -444,6 +456,14 @@ class Plan: """ +@dataclass +class Product: + name: str + display_name: str + family_name: str + resource_types: list[str] + + @dataclass class Token: """ @@ -964,6 +984,12 @@ class ListPlansResponse: """ +@dataclass +class ListProductsResponse: + products_list: list[Product] + total_count: int + + @dataclass class ListTokensResponse: """ @@ -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: """ diff --git a/scaleway/scaleway/cockpit/v1/__init__.py b/scaleway/scaleway/cockpit/v1/__init__.py index 42495d8e3..17d22f1c9 100644 --- a/scaleway/scaleway/cockpit/v1/__init__.py +++ b/scaleway/scaleway/cockpit/v1/__init__.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -84,6 +88,7 @@ "ListDataSourcesRequestOrderBy", "ListGrafanaUsersRequestOrderBy", "ListPlansRequestOrderBy", + "ListProductsRequestOrderBy", "ListTokensRequestOrderBy", "PlanName", "TokenScope", @@ -98,6 +103,7 @@ "GrafanaProductDashboard", "GrafanaUser", "Plan", + "Product", "Token", "Usage", "AlertManager", @@ -123,6 +129,7 @@ "ListGrafanaProductDashboardsResponse", "ListGrafanaUsersResponse", "ListPlansResponse", + "ListProductsResponse", "ListTokensResponse", "RegionalApiCreateContactPointRequest", "RegionalApiCreateDataSourceRequest", @@ -143,6 +150,7 @@ "RegionalApiListAlertsRequest", "RegionalApiListContactPointsRequest", "RegionalApiListDataSourcesRequest", + "RegionalApiListProductsRequest", "RegionalApiListTokensRequest", "RegionalApiTriggerTestAlertRequest", "RegionalApiUpdateContactPointRequest", diff --git a/scaleway/scaleway/cockpit/v1/api.py b/scaleway/scaleway/cockpit/v1/api.py index 9094ea30b..a7de142e3 100644 --- a/scaleway/scaleway/cockpit/v1/api.py +++ b/scaleway/scaleway/cockpit/v1/api.py @@ -20,6 +20,7 @@ ListDataSourcesRequestOrderBy, ListGrafanaUsersRequestOrderBy, ListPlansRequestOrderBy, + ListProductsRequestOrderBy, ListTokensRequestOrderBy, PlanName, TokenScope, @@ -44,8 +45,10 @@ ListGrafanaProductDashboardsResponse, ListGrafanaUsersResponse, ListPlansResponse, + ListProductsResponse, ListTokensResponse, Plan, + Product, RegionalApiCreateContactPointRequest, RegionalApiCreateDataSourceRequest, RegionalApiCreateTokenRequest, @@ -79,6 +82,7 @@ unmarshal_ListGrafanaProductDashboardsResponse, unmarshal_ListGrafanaUsersResponse, unmarshal_ListPlansResponse, + unmarshal_ListProductsResponse, unmarshal_ListTokensResponse, unmarshal_UsageOverview, marshal_GlobalApiCreateGrafanaUserRequest, @@ -1126,6 +1130,79 @@ def delete_token( self._throw_on_error(res) + 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 ` + + Usage: + :: + + result = 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()) + + 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] ` + + Usage: + :: + + result = api.list_products_all() + """ + + return fetch_all_pages( + type=ListProductsResponse, + key="products_list", + fetcher=self.list_products, + args={ + "region": region, + "page": page, + "page_size": page_size, + "order_by": order_by, + }, + ) + def get_alert_manager( self, *, diff --git a/scaleway/scaleway/cockpit/v1/marshalling.py b/scaleway/scaleway/cockpit/v1/marshalling.py index f9e65477f..ba829fbbf 100644 --- a/scaleway/scaleway/cockpit/v1/marshalling.py +++ b/scaleway/scaleway/cockpit/v1/marshalling.py @@ -41,6 +41,8 @@ ListGrafanaProductDashboardsResponse, ListGrafanaUsersResponse, ListPlansResponse, + Product, + ListProductsResponse, ListTokensResponse, Usage, UsageOverview, @@ -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( diff --git a/scaleway/scaleway/cockpit/v1/types.py b/scaleway/scaleway/cockpit/v1/types.py index c145d75d5..32d5aa9b0 100644 --- a/scaleway/scaleway/cockpit/v1/types.py +++ b/scaleway/scaleway/cockpit/v1/types.py @@ -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" @@ -444,6 +456,14 @@ class Plan: """ +@dataclass +class Product: + name: str + display_name: str + family_name: str + resource_types: list[str] + + @dataclass class Token: """ @@ -964,6 +984,12 @@ class ListPlansResponse: """ +@dataclass +class ListProductsResponse: + products_list: list[Product] + total_count: int + + @dataclass class ListTokensResponse: """ @@ -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: """