Skip to content
Merged
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
36 changes: 36 additions & 0 deletions packages/clients/src/api/cockpit/v1beta1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
unmarshalDatasource,
unmarshalGrafanaUser,
unmarshalListContactPointsResponse,
unmarshalListDatasourcesResponse,
unmarshalListGrafanaUsersResponse,
unmarshalListPlansResponse,
unmarshalListTokensResponse,
Expand Down Expand Up @@ -58,6 +59,8 @@ import type {
GrafanaUser,
ListContactPointsRequest,
ListContactPointsResponse,
ListDatasourcesRequest,
ListDatasourcesResponse,
ListGrafanaUsersRequest,
ListGrafanaUsersResponse,
ListPlansRequest,
Expand Down Expand Up @@ -223,6 +226,39 @@ export class API extends ParentAPI {
unmarshalDatasource,
)

protected pageOfListDatasources = (
request: Readonly<ListDatasourcesRequest> = {},
) =>
this.client.fetch<ListDatasourcesResponse>(
{
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<ListDatasourcesRequest> = {}) =>
enrichForPagination('datasources', this.pageOfListDatasources, request)

/**
* Create a token associated with the specified Project ID.
*
Expand Down
3 changes: 3 additions & 0 deletions packages/clients/src/api/cockpit/v1beta1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export type {
GrafanaUserRole,
ListContactPointsRequest,
ListContactPointsResponse,
ListDatasourcesRequest,
ListDatasourcesRequestOrderBy,
ListDatasourcesResponse,
ListGrafanaUsersRequest,
ListGrafanaUsersRequestOrderBy,
ListGrafanaUsersResponse,
Expand Down
46 changes: 30 additions & 16 deletions packages/clients/src/api/cockpit/v1beta1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import type {
EnableManagedAlertsRequest,
GrafanaUser,
ListContactPointsResponse,
ListDatasourcesResponse,
ListGrafanaUsersResponse,
ListPlansResponse,
ListTokensResponse,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down
28 changes: 28 additions & 0 deletions packages/clients/src/api/cockpit/v1beta1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down