diff --git a/packages/clients/src/api/cockpit/v1beta1/api.gen.ts b/packages/clients/src/api/cockpit/v1beta1/api.gen.ts index c0d7d53cc..8619259d6 100644 --- a/packages/clients/src/api/cockpit/v1beta1/api.gen.ts +++ b/packages/clients/src/api/cockpit/v1beta1/api.gen.ts @@ -28,9 +28,11 @@ import { unmarshalCockpitMetrics, unmarshalContactPoint, unmarshalDatasource, + unmarshalGrafanaProductDashboard, unmarshalGrafanaUser, unmarshalListContactPointsResponse, unmarshalListDatasourcesResponse, + unmarshalListGrafanaProductDashboardsResponse, unmarshalListGrafanaUsersResponse, unmarshalListPlansResponse, unmarshalListTokensResponse, @@ -55,12 +57,16 @@ import type { EnableManagedAlertsRequest, GetCockpitMetricsRequest, GetCockpitRequest, + GetGrafanaProductDashboardRequest, GetTokenRequest, + GrafanaProductDashboard, GrafanaUser, ListContactPointsRequest, ListContactPointsResponse, ListDatasourcesRequest, ListDatasourcesResponse, + ListGrafanaProductDashboardsRequest, + ListGrafanaProductDashboardsResponse, ListGrafanaUsersRequest, ListGrafanaUsersResponse, ListPlansRequest, @@ -595,4 +601,67 @@ export class API extends ParentAPI { }, unmarshalSelectPlanResponse, ) + + protected pageOfListGrafanaProductDashboards = ( + request: Readonly = {}, + ) => + this.client.fetch( + { + method: 'GET', + path: `/cockpit/v1beta1/grafana-product-dashboards`, + urlParams: urlParams( + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + [ + 'project_id', + request.projectId ?? this.client.settings.defaultProjectId, + ], + ['tags', request.tags], + ), + }, + unmarshalListGrafanaProductDashboardsResponse, + ) + + /** + * List product dashboards. Get a list of available product dashboards. + * + * @param request - The request {@link ListGrafanaProductDashboardsRequest} + * @returns A Promise of ListGrafanaProductDashboardsResponse + */ + listGrafanaProductDashboards = ( + request: Readonly = {}, + ) => + enrichForPagination( + 'dashboards', + this.pageOfListGrafanaProductDashboards, + request, + ) + + /** + * Get a product dashboard. Get a product dashboard specified by the dashboard + * ID. + * + * @param request - The request {@link GetGrafanaProductDashboardRequest} + * @returns A Promise of GrafanaProductDashboard + */ + getGrafanaProductDashboard = ( + request: Readonly, + ) => + this.client.fetch( + { + method: 'GET', + path: `/cockpit/v1beta1/grafana-product-dashboards/${validatePathParam( + 'dashboardName', + request.dashboardName, + )}`, + urlParams: urlParams([ + 'project_id', + request.projectId ?? this.client.settings.defaultProjectId, + ]), + }, + unmarshalGrafanaProductDashboard, + ) } diff --git a/packages/clients/src/api/cockpit/v1beta1/index.gen.ts b/packages/clients/src/api/cockpit/v1beta1/index.gen.ts index 94685839d..076a94d1a 100644 --- a/packages/clients/src/api/cockpit/v1beta1/index.gen.ts +++ b/packages/clients/src/api/cockpit/v1beta1/index.gen.ts @@ -24,7 +24,9 @@ export type { EnableManagedAlertsRequest, GetCockpitMetricsRequest, GetCockpitRequest, + GetGrafanaProductDashboardRequest, GetTokenRequest, + GrafanaProductDashboard, GrafanaUser, GrafanaUserRole, ListContactPointsRequest, @@ -32,6 +34,8 @@ export type { ListDatasourcesRequest, ListDatasourcesRequestOrderBy, ListDatasourcesResponse, + ListGrafanaProductDashboardsRequest, + ListGrafanaProductDashboardsResponse, 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 17a428a39..af92fbbc5 100644 --- a/packages/clients/src/api/cockpit/v1beta1/marshalling.gen.ts +++ b/packages/clients/src/api/cockpit/v1beta1/marshalling.gen.ts @@ -26,9 +26,11 @@ import type { DeleteGrafanaUserRequest, DisableManagedAlertsRequest, EnableManagedAlertsRequest, + GrafanaProductDashboard, GrafanaUser, ListContactPointsResponse, ListDatasourcesResponse, + ListGrafanaProductDashboardsResponse, ListGrafanaUsersResponse, ListPlansResponse, ListTokensResponse, @@ -115,6 +117,22 @@ export const unmarshalDatasource = (data: unknown) => { } as Datasource } +export const unmarshalGrafanaProductDashboard = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'GrafanaProductDashboard' failed as data isn't a dictionary.`, + ) + } + + return { + dashboardName: data.dashboard_name, + tags: data.tags, + title: data.title, + url: data.url, + variables: data.variables, + } as GrafanaProductDashboard +} + export const unmarshalGrafanaUser = (data: unknown) => { if (!isJSONObject(data)) { throw new TypeError( @@ -229,6 +247,24 @@ export const unmarshalListDatasourcesResponse = (data: unknown) => { } as ListDatasourcesResponse } +export const unmarshalListGrafanaProductDashboardsResponse = ( + data: unknown, +) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListGrafanaProductDashboardsResponse' failed as data isn't a dictionary.`, + ) + } + + return { + dashboards: unmarshalArrayOfObject( + data.dashboards, + unmarshalGrafanaProductDashboard, + ), + totalCount: data.total_count, + } as ListGrafanaProductDashboardsResponse +} + 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 b0c3176f2..b83dc2511 100644 --- a/packages/clients/src/api/cockpit/v1beta1/types.gen.ts +++ b/packages/clients/src/api/cockpit/v1beta1/types.gen.ts @@ -101,6 +101,20 @@ export interface Datasource { type: DatasourceType } +/** Grafana dashboard. Grafana product dashboard. */ +export interface GrafanaProductDashboard { + /** Name of the dashboard. */ + dashboardName: string + /** Title of the dashboard. */ + title: string + /** URL of the dashboard. */ + url: string + /** Tags of the dashboard. */ + tags: string[] + /** Variables of the dashboard. */ + variables: string[] +} + /** Grafana user. */ export interface GrafanaUser { /** ID of the Grafana user. */ @@ -136,6 +150,17 @@ export interface ListDatasourcesResponse { datasources: Datasource[] } +/** + * Response returned when getting a list of dashboards. List grafana product + * dashboards response. + */ +export interface ListGrafanaProductDashboardsResponse { + /** Count of grafana dasboards. */ + totalCount: number + /** Information on grafana dashboards. */ + dashboards: GrafanaProductDashboard[] +} + /** Response returned when listing Grafana users. List grafana users response. */ export interface ListGrafanaUsersResponse { /** Count of all Grafana users. */ @@ -388,3 +413,21 @@ export type SelectPlanRequest = { /** ID of the pricing plan. */ planId: string } + +export type ListGrafanaProductDashboardsRequest = { + /** ID of the Project. */ + projectId?: string + /** Page number. */ + page?: number + /** Page size. */ + pageSize?: number + /** Tags to filter the dashboards. */ + tags?: string[] +} + +export type GetGrafanaProductDashboardRequest = { + /** Name of the dashboard. */ + dashboardName: string + /** ID of the Project. */ + projectId?: string +}