diff --git a/packages/clients/src/api/cockpit/v1beta1/api.gen.ts b/packages/clients/src/api/cockpit/v1beta1/api.gen.ts index 72d1370ed..c0d7d53cc 100644 --- a/packages/clients/src/api/cockpit/v1beta1/api.gen.ts +++ b/packages/clients/src/api/cockpit/v1beta1/api.gen.ts @@ -30,6 +30,7 @@ import { unmarshalDatasource, unmarshalGrafanaUser, unmarshalListContactPointsResponse, + unmarshalListDatasourcesResponse, unmarshalListGrafanaUsersResponse, unmarshalListPlansResponse, unmarshalListTokensResponse, @@ -58,6 +59,8 @@ import type { GrafanaUser, ListContactPointsRequest, ListContactPointsResponse, + ListDatasourcesRequest, + ListDatasourcesResponse, ListGrafanaUsersRequest, ListGrafanaUsersResponse, ListPlansRequest, @@ -223,6 +226,39 @@ export class API extends ParentAPI { unmarshalDatasource, ) + protected pageOfListDatasources = ( + request: Readonly = {}, + ) => + this.client.fetch( + { + method: 'GET', + path: `/cockpit/v1beta1/datasources`, + urlParams: urlParams( + ['order_by', request.orderBy ?? 'created_at_asc'], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + [ + 'project_id', + request.projectId ?? this.client.settings.defaultProjectId, + ], + ['types', request.types], + ), + }, + unmarshalListDatasourcesResponse, + ) + + /** + * Get a list of datasources for the specified Project ID. + * + * @param request - The request {@link ListDatasourcesRequest} + * @returns A Promise of ListDatasourcesResponse + */ + listDatasources = (request: Readonly = {}) => + enrichForPagination('datasources', this.pageOfListDatasources, request) + /** * Create a token associated with the specified Project ID. * diff --git a/packages/clients/src/api/cockpit/v1beta1/index.gen.ts b/packages/clients/src/api/cockpit/v1beta1/index.gen.ts index 95f2bee92..94685839d 100644 --- a/packages/clients/src/api/cockpit/v1beta1/index.gen.ts +++ b/packages/clients/src/api/cockpit/v1beta1/index.gen.ts @@ -29,6 +29,9 @@ export type { GrafanaUserRole, ListContactPointsRequest, ListContactPointsResponse, + ListDatasourcesRequest, + ListDatasourcesRequestOrderBy, + ListDatasourcesResponse, ListGrafanaUsersRequest, ListGrafanaUsersRequestOrderBy, ListGrafanaUsersResponse, diff --git a/packages/clients/src/api/cockpit/v1beta1/marshalling.gen.ts b/packages/clients/src/api/cockpit/v1beta1/marshalling.gen.ts index 6e7cdb909..17a428a39 100644 --- a/packages/clients/src/api/cockpit/v1beta1/marshalling.gen.ts +++ b/packages/clients/src/api/cockpit/v1beta1/marshalling.gen.ts @@ -28,6 +28,7 @@ import type { EnableManagedAlertsRequest, GrafanaUser, ListContactPointsResponse, + ListDatasourcesResponse, ListGrafanaUsersResponse, ListPlansResponse, ListTokensResponse, @@ -98,6 +99,22 @@ export const unmarshalContactPoint = (data: unknown) => { } as ContactPoint } +export const unmarshalDatasource = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Datasource' failed as data isn't a dictionary.`, + ) + } + + return { + id: data.id, + name: data.name, + projectId: data.project_id, + type: data.type, + url: data.url, + } as Datasource +} + export const unmarshalGrafanaUser = (data: unknown) => { if (!isJSONObject(data)) { throw new TypeError( @@ -181,22 +198,6 @@ export const unmarshalCockpitMetrics = (data: unknown) => { } as CockpitMetrics } -export const unmarshalDatasource = (data: unknown) => { - if (!isJSONObject(data)) { - throw new TypeError( - `Unmarshalling the type 'Datasource' failed as data isn't a dictionary.`, - ) - } - - return { - id: data.id, - name: data.name, - projectId: data.project_id, - type: data.type, - url: data.url, - } as Datasource -} - export const unmarshalListContactPointsResponse = (data: unknown) => { if (!isJSONObject(data)) { throw new TypeError( @@ -215,6 +216,19 @@ export const unmarshalListContactPointsResponse = (data: unknown) => { } as ListContactPointsResponse } +export const unmarshalListDatasourcesResponse = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListDatasourcesResponse' failed as data isn't a dictionary.`, + ) + } + + return { + datasources: unmarshalArrayOfObject(data.datasources, unmarshalDatasource), + totalCount: data.total_count, + } as ListDatasourcesResponse +} + export const unmarshalListGrafanaUsersResponse = (data: unknown) => { if (!isJSONObject(data)) { throw new TypeError( diff --git a/packages/clients/src/api/cockpit/v1beta1/types.gen.ts b/packages/clients/src/api/cockpit/v1beta1/types.gen.ts index 4a028cce9..b0c3176f2 100644 --- a/packages/clients/src/api/cockpit/v1beta1/types.gen.ts +++ b/packages/clients/src/api/cockpit/v1beta1/types.gen.ts @@ -19,6 +19,12 @@ export type DatasourceType = export type GrafanaUserRole = 'unknown_role' | 'editor' | 'viewer' +export type ListDatasourcesRequestOrderBy = + | 'created_at_asc' + | 'created_at_desc' + | 'name_asc' + | 'name_desc' + export type ListGrafanaUsersRequestOrderBy = 'login_asc' | 'login_desc' export type ListPlansRequestOrderBy = 'name_asc' | 'name_desc' @@ -122,6 +128,14 @@ export interface ListContactPointsResponse { hasAdditionalContactPoints: boolean } +/** List datasources response. */ +export interface ListDatasourcesResponse { + /** Count of all datasources corresponding to the request. */ + totalCount: number + /** List of the datasources within the pagination. */ + datasources: Datasource[] +} + /** Response returned when listing Grafana users. List grafana users response. */ export interface ListGrafanaUsersResponse { /** Count of all Grafana users. */ @@ -247,6 +261,19 @@ export type CreateDatasourceRequest = { type?: DatasourceType } +export type ListDatasourcesRequest = { + /** Page number. */ + page?: number + /** Page size. */ + pageSize?: number + /** How the response is ordered. */ + orderBy?: ListDatasourcesRequestOrderBy + /** ID of the Project. */ + projectId?: string + /** Filter by datasource types. */ + types?: DatasourceType[] +} + export type CreateTokenRequest = { /** ID of the Project. */ projectId?: string @@ -261,6 +288,7 @@ export type ListTokensRequest = { page?: number /** Page size. */ pageSize?: number + /** How the response is ordered. */ orderBy?: ListTokensRequestOrderBy /** ID of the Project. */ projectId?: string