Skip to content

Commit 5af6be9

Browse files
authored
feat(cockpit): add new Data-exporter endpoints + types (#2577)
1 parent b1e0e4d commit 5af6be9

File tree

5 files changed

+120
-0
lines changed

5 files changed

+120
-0
lines changed

packages_generated/cockpit/src/v1/api.gen.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
unmarshalListGrafanaProductDashboardsResponse,
4141
unmarshalListGrafanaUsersResponse,
4242
unmarshalListPlansResponse,
43+
unmarshalListProductsResponse,
4344
unmarshalListTokensResponse,
4445
unmarshalPlan,
4546
unmarshalToken,
@@ -73,6 +74,7 @@ import type {
7374
ListGrafanaProductDashboardsResponse,
7475
ListGrafanaUsersResponse,
7576
ListPlansResponse,
77+
ListProductsResponse,
7678
ListTokensResponse,
7779
Plan,
7880
RegionalApiCreateContactPointRequest,
@@ -94,6 +96,7 @@ import type {
9496
RegionalApiListAlertsRequest,
9597
RegionalApiListContactPointsRequest,
9698
RegionalApiListDataSourcesRequest,
99+
RegionalApiListProductsRequest,
97100
RegionalApiListTokensRequest,
98101
RegionalApiTriggerTestAlertRequest,
99102
RegionalApiUpdateContactPointRequest,
@@ -627,6 +630,34 @@ You can filter tokens by Project ID and token scopes.
627630
path: `/cockpit/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/tokens/${validatePathParam('tokenId', request.tokenId)}`,
628631
})
629632

633+
protected pageOfListProducts = (
634+
request: Readonly<RegionalApiListProductsRequest> = {},
635+
) =>
636+
this.client.fetch<ListProductsResponse>(
637+
{
638+
method: 'GET',
639+
path: `/cockpit/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/products`,
640+
urlParams: urlParams(
641+
['order_by', request.orderBy],
642+
['page', request.page],
643+
[
644+
'page_size',
645+
request.pageSize ?? this.client.settings.defaultPageSize,
646+
],
647+
),
648+
},
649+
unmarshalListProductsResponse,
650+
)
651+
652+
/**
653+
* List all Scaleway products that send metrics and/or logs to Cockpit.. List all Scaleway products that send metrics and/or logs to Cockpit.
654+
*
655+
* @param request - The request {@link RegionalApiListProductsRequest}
656+
* @returns A Promise of ListProductsResponse
657+
*/
658+
listProducts = (request: Readonly<RegionalApiListProductsRequest> = {}) =>
659+
enrichForPagination('productsList', this.pageOfListProducts, request)
660+
630661
/**
631662
* Get the Alert manager. Retrieve information about the Alert manager which is unique per Project and region. By default the Alert manager is disabled.
632663
The output returned displays a URL to access the Alert manager, and whether the Alert manager and managed alerts are enabled.

packages_generated/cockpit/src/v1/index.gen.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,14 @@ export type {
4444
ListGrafanaUsersResponse,
4545
ListPlansRequestOrderBy,
4646
ListPlansResponse,
47+
ListProductsRequestOrderBy,
48+
ListProductsResponse,
4749
ListTokensRequestOrderBy,
4850
ListTokensResponse,
4951
Plan,
5052
PlanName,
5153
PreconfiguredAlertData,
54+
Product,
5255
RegionalApiCreateContactPointRequest,
5356
RegionalApiCreateDataSourceRequest,
5457
RegionalApiCreateTokenRequest,
@@ -68,6 +71,7 @@ export type {
6871
RegionalApiListAlertsRequest,
6972
RegionalApiListContactPointsRequest,
7073
RegionalApiListDataSourcesRequest,
74+
RegionalApiListProductsRequest,
7175
RegionalApiListTokensRequest,
7276
RegionalApiTriggerTestAlertRequest,
7377
RegionalApiUpdateContactPointRequest,

packages_generated/cockpit/src/v1/marshalling.gen.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ import type {
3131
ListGrafanaProductDashboardsResponse,
3232
ListGrafanaUsersResponse,
3333
ListPlansResponse,
34+
ListProductsResponse,
3435
ListTokensResponse,
3536
Plan,
3637
PreconfiguredAlertData,
38+
Product,
3739
RegionalApiCreateContactPointRequest,
3840
RegionalApiCreateDataSourceRequest,
3941
RegionalApiCreateTokenRequest,
@@ -444,6 +446,36 @@ export const unmarshalListPlansResponse = (
444446
} as ListPlansResponse
445447
}
446448

449+
const unmarshalProduct = (data: unknown): Product => {
450+
if (!isJSONObject(data)) {
451+
throw new TypeError(
452+
`Unmarshalling the type 'Product' failed as data isn't a dictionary.`,
453+
)
454+
}
455+
456+
return {
457+
displayName: data.display_name,
458+
familyName: data.family_name,
459+
name: data.name,
460+
resourceTypes: data.resource_types,
461+
} as Product
462+
}
463+
464+
export const unmarshalListProductsResponse = (
465+
data: unknown,
466+
): ListProductsResponse => {
467+
if (!isJSONObject(data)) {
468+
throw new TypeError(
469+
`Unmarshalling the type 'ListProductsResponse' failed as data isn't a dictionary.`,
470+
)
471+
}
472+
473+
return {
474+
productsList: unmarshalArrayOfObject(data.products_list, unmarshalProduct),
475+
totalCount: data.total_count,
476+
} as ListProductsResponse
477+
}
478+
447479
export const unmarshalListTokensResponse = (
448480
data: unknown,
449481
): ListTokensResponse => {

packages_generated/cockpit/src/v1/types.gen.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ export type ListGrafanaUsersRequestOrderBy = 'login_asc' | 'login_desc'
3333

3434
export type ListPlansRequestOrderBy = 'name_asc' | 'name_desc'
3535

36+
export type ListProductsRequestOrderBy =
37+
| 'created_at_asc'
38+
| 'created_at_desc'
39+
| 'display_name_asc'
40+
| 'display_name_desc'
41+
| 'family_name_asc'
42+
| 'family_name_desc'
43+
3644
export type ListTokensRequestOrderBy =
3745
| 'created_at_asc'
3846
| 'created_at_desc'
@@ -308,6 +316,13 @@ export interface Plan {
308316
monthlyPrice: number
309317
}
310318

319+
export interface Product {
320+
name: string
321+
displayName: string
322+
familyName: string
323+
resourceTypes: string[]
324+
}
325+
311326
/**
312327
* Token.
313328
*/
@@ -732,6 +747,11 @@ export interface ListPlansResponse {
732747
plans: Plan[]
733748
}
734749

750+
export interface ListProductsResponse {
751+
productsList: Product[]
752+
totalCount: number
753+
}
754+
735755
/**
736756
* Response returned when listing tokens.
737757
*/
@@ -1082,6 +1102,28 @@ export type RegionalApiListDataSourcesRequest = {
10821102
types?: DataSourceType[]
10831103
}
10841104

1105+
/**
1106+
* List all Scaleway products that send metrics and/or logs to Cockpit.
1107+
*/
1108+
export type RegionalApiListProductsRequest = {
1109+
/**
1110+
* Region to target. If none is passed will use default region from the config.
1111+
*/
1112+
region?: ScwRegion
1113+
/**
1114+
* Page number to return from the paginated results.
1115+
*/
1116+
page?: number
1117+
/**
1118+
* Number of products to return per page.
1119+
*/
1120+
pageSize?: number
1121+
/**
1122+
* Sort order for products in the response.
1123+
*/
1124+
orderBy?: ListProductsRequestOrderBy
1125+
}
1126+
10851127
/**
10861128
* List tokens.
10871129
*/

packages_generated/cockpit/src/v1/validation-rules.gen.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ export const RegionalApiListDataSourcesRequest = {
4242
},
4343
}
4444

45+
export const RegionalApiListProductsRequest = {
46+
page: {
47+
greaterThanOrEqual: 1,
48+
lessThanOrEqual: 10000,
49+
},
50+
pageSize: {
51+
greaterThanOrEqual: 1,
52+
lessThanOrEqual: 100,
53+
},
54+
}
55+
4556
export const RegionalApiListTokensRequest = {
4657
page: {
4758
greaterThanOrEqual: 1,

0 commit comments

Comments
 (0)