Skip to content

Commit ab1e2a7

Browse files
authored
feat(cockpit): create datasource (#875)
1 parent 7b96fae commit ab1e2a7

File tree

4 files changed

+113
-39
lines changed

4 files changed

+113
-39
lines changed

packages/clients/src/api/cockpit/v1beta1/api.gen.ts

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { COCKPIT_TRANSIENT_STATUSES } from './content.gen'
1212
import {
1313
marshalActivateCockpitRequest,
1414
marshalCreateContactPointRequest,
15+
marshalCreateDatasourceRequest,
1516
marshalCreateGrafanaUserRequest,
1617
marshalCreateTokenRequest,
1718
marshalDeactivateCockpitRequest,
@@ -26,6 +27,7 @@ import {
2627
unmarshalCockpit,
2728
unmarshalCockpitMetrics,
2829
unmarshalContactPoint,
30+
unmarshalDatasource,
2931
unmarshalGrafanaUser,
3032
unmarshalListContactPointsResponse,
3133
unmarshalListGrafanaUsersResponse,
@@ -40,8 +42,10 @@ import type {
4042
CockpitMetrics,
4143
ContactPoint,
4244
CreateContactPointRequest,
45+
CreateDatasourceRequest,
4346
CreateGrafanaUserRequest,
4447
CreateTokenRequest,
48+
Datasource,
4549
DeactivateCockpitRequest,
4650
DeleteContactPointRequest,
4751
DeleteGrafanaUserRequest,
@@ -75,13 +79,13 @@ const jsonContentHeaders = {
7579
/**
7680
* Cockpit API.
7781
*
78-
* Cockpit API. Cockpit's API allows you to activate your Cockpit on your
79-
* Projects. Scaleway's Cockpit stores metrics and logs and provides a dedicated
80-
* Grafana for dashboarding to visualize them.
82+
* Cockpit's API allows you to activate your Cockpit on your Projects.
83+
* Scaleway's Cockpit stores metrics and logs and provides a dedicated Grafana
84+
* for dashboarding to visualize them. Cockpit API.
8185
*/
8286
export class API extends ParentAPI {
8387
/**
84-
* Activate a Cockpit. Activate the Cockpit of the specified Project ID.
88+
* Activate the Cockpit of the specified Project ID.
8589
*
8690
* @param request - The request {@link ActivateCockpitRequest}
8791
* @returns A Promise of Cockpit
@@ -100,7 +104,7 @@ export class API extends ParentAPI {
100104
)
101105

102106
/**
103-
* Get a Cockpit. Retrieve the Cockpit of the specified Project ID.
107+
* Retrieve the Cockpit of the specified Project ID.
104108
*
105109
* @param request - The request {@link GetCockpitRequest}
106110
* @returns A Promise of Cockpit
@@ -139,8 +143,7 @@ export class API extends ParentAPI {
139143
)
140144

141145
/**
142-
* Get Cockpit metrics. Get metrics from your Cockpit with the specified
143-
* Project ID.
146+
* Get metrics from your Cockpit with the specified Project ID.
144147
*
145148
* @param request - The request {@link GetCockpitMetricsRequest}
146149
* @returns A Promise of CockpitMetrics
@@ -164,7 +167,7 @@ export class API extends ParentAPI {
164167
)
165168

166169
/**
167-
* Deactivate a Cockpit. Deactivate the Cockpit of the specified Project ID.
170+
* Deactivate the Cockpit of the specified Project ID.
168171
*
169172
* @param request - The request {@link DeactivateCockpitRequest}
170173
* @returns A Promise of Cockpit
@@ -183,8 +186,7 @@ export class API extends ParentAPI {
183186
)
184187

185188
/**
186-
* Reset a Grafana. Reset your Cockpit's Grafana associated with the specified
187-
* Project ID.
189+
* Reset your Cockpit's Grafana associated with the specified Project ID.
188190
*
189191
* @param request - The request {@link ResetCockpitGrafanaRequest}
190192
* @returns A Promise of Cockpit
@@ -203,7 +205,26 @@ export class API extends ParentAPI {
203205
)
204206

205207
/**
206-
* Create a token. Create a token associated with the specified Project ID.
208+
* Create a datasource for the specified Project ID and the given type.
209+
*
210+
* @param request - The request {@link CreateDatasourceRequest}
211+
* @returns A Promise of Datasource
212+
*/
213+
createDatasource = (request: Readonly<CreateDatasourceRequest>) =>
214+
this.client.fetch<Datasource>(
215+
{
216+
body: JSON.stringify(
217+
marshalCreateDatasourceRequest(request, this.client.settings),
218+
),
219+
headers: jsonContentHeaders,
220+
method: 'POST',
221+
path: `/cockpit/v1beta1/datasources`,
222+
},
223+
unmarshalDatasource,
224+
)
225+
226+
/**
227+
* Create a token associated with the specified Project ID.
207228
*
208229
* @param request - The request {@link CreateTokenRequest}
209230
* @returns A Promise of Token
@@ -243,7 +264,7 @@ export class API extends ParentAPI {
243264
)
244265

245266
/**
246-
* List tokens. Get a list of tokens associated with the specified Project ID.
267+
* Get a list of tokens associated with the specified Project ID.
247268
*
248269
* @param request - The request {@link ListTokensRequest}
249270
* @returns A Promise of ListTokensResponse
@@ -252,7 +273,7 @@ export class API extends ParentAPI {
252273
enrichForPagination('tokens', this.pageOfListTokens, request)
253274

254275
/**
255-
* Get a token. Retrieve the token associated with the specified token ID.
276+
* Retrieve the token associated with the specified token ID.
256277
*
257278
* @param request - The request {@link GetTokenRequest}
258279
* @returns A Promise of Token
@@ -270,7 +291,7 @@ export class API extends ParentAPI {
270291
)
271292

272293
/**
273-
* Delete a token. Delete the token associated with the specified token ID.
294+
* Delete the token associated with the specified token ID.
274295
*
275296
* @param request - The request {@link DeleteTokenRequest}
276297
*/
@@ -284,8 +305,7 @@ export class API extends ParentAPI {
284305
})
285306

286307
/**
287-
* Create a contact point. Create a contact point to receive alerts for the
288-
* default receiver.
308+
* Create a contact point to receive alerts for the default receiver.
289309
*
290310
* @param request - The request {@link CreateContactPointRequest}
291311
* @returns A Promise of ContactPoint
@@ -326,8 +346,8 @@ export class API extends ParentAPI {
326346
)
327347

328348
/**
329-
* List contact points. Get a list of contact points for the Cockpit
330-
* associated with the specified Project ID.
349+
* Get a list of contact points for the Cockpit associated with the specified
350+
* Project ID.
331351
*
332352
* @param request - The request {@link ListContactPointsRequest}
333353
* @returns A Promise of ListContactPointsResponse
@@ -336,8 +356,7 @@ export class API extends ParentAPI {
336356
enrichForPagination('contactPoints', this.pageOfListContactPoints, request)
337357

338358
/**
339-
* Delete an alert contact point. Delete a contact point for the default
340-
* receiver.
359+
* Delete a contact point for the default receiver.
341360
*
342361
* @param request - The request {@link DeleteContactPointRequest}
343362
*/
@@ -352,8 +371,7 @@ export class API extends ParentAPI {
352371
})
353372

354373
/**
355-
* Enable managed alerts. Enable the sending of managed alerts for the
356-
* specified Project's Cockpit.
374+
* Enable the sending of managed alerts for the specified Project's Cockpit.
357375
*
358376
* @param request - The request {@link EnableManagedAlertsRequest}
359377
*/
@@ -368,8 +386,7 @@ export class API extends ParentAPI {
368386
})
369387

370388
/**
371-
* Disable managed alerts. Disable the sending of managed alerts for the
372-
* specified Project's Cockpit.
389+
* Disable the sending of managed alerts for the specified Project's Cockpit.
373390
*
374391
* @param request - The request {@link DisableManagedAlertsRequest}
375392
*/
@@ -386,8 +403,7 @@ export class API extends ParentAPI {
386403
})
387404

388405
/**
389-
* Trigger a test alert. Trigger a test alert to all of the Cockpit's
390-
* receivers.
406+
* Trigger a test alert to all of the Cockpit's receivers.
391407
*
392408
* @param request - The request {@link TriggerTestAlertRequest}
393409
*/
@@ -402,9 +418,8 @@ export class API extends ParentAPI {
402418
})
403419

404420
/**
405-
* Create a Grafana user. Create a Grafana user for your Cockpit's Grafana
406-
* instance. Make sure you save the automatically-generated password and the
407-
* Grafana user ID.
421+
* Create a Grafana user for your Cockpit's Grafana instance. Make sure you
422+
* save the automatically-generated password and the Grafana user ID.
408423
*
409424
* @param request - The request {@link CreateGrafanaUserRequest}
410425
* @returns A Promise of GrafanaUser
@@ -446,8 +461,8 @@ export class API extends ParentAPI {
446461
)
447462

448463
/**
449-
* List Grafana users. Get a list of Grafana users who are able to connect to
450-
* the Cockpit's Grafana instance.
464+
* Get a list of Grafana users who are able to connect to the Cockpit's
465+
* Grafana instance.
451466
*
452467
* @param request - The request {@link ListGrafanaUsersRequest}
453468
* @returns A Promise of ListGrafanaUsersResponse
@@ -456,8 +471,8 @@ export class API extends ParentAPI {
456471
enrichForPagination('grafanaUsers', this.pageOfListGrafanaUsers, request)
457472

458473
/**
459-
* Delete a Grafana user. Delete a Grafana user from a Grafana instance,
460-
* specified by the Cockpit's Project ID and the Grafana user ID.
474+
* Delete a Grafana user from a Grafana instance, specified by the Cockpit's
475+
* Project ID and the Grafana user ID.
461476
*
462477
* @param request - The request {@link DeleteGrafanaUserRequest}
463478
*/
@@ -475,8 +490,8 @@ export class API extends ParentAPI {
475490
})
476491

477492
/**
478-
* Reset a Grafana user's password. Reset a Grafana user's password specified
479-
* by the Cockpit's Project ID and the Grafana user ID.
493+
* Reset a Grafana user's password specified by the Cockpit's Project ID and
494+
* the Grafana user ID.
480495
*
481496
* @param request - The request {@link ResetGrafanaUserPasswordRequest}
482497
* @returns A Promise of GrafanaUser
@@ -517,7 +532,7 @@ export class API extends ParentAPI {
517532
)
518533

519534
/**
520-
* List pricing plans. Get a list of all pricing plans available.
535+
* Get a list of all pricing plans available.
521536
*
522537
* @param request - The request {@link ListPlansRequest}
523538
* @returns A Promise of ListPlansResponse
@@ -526,9 +541,8 @@ export class API extends ParentAPI {
526541
enrichForPagination('plans', this.pageOfListPlans, request)
527542

528543
/**
529-
* Select pricing plan. Select your chosen pricing plan for your Cockpit,
530-
* specifying the Cockpit's Project ID and the pricing plan's ID in the
531-
* request.
544+
* Select your chosen pricing plan for your Cockpit, specifying the Cockpit's
545+
* Project ID and the pricing plan's ID in the request.
532546
*
533547
* @param request - The request {@link SelectPlanRequest}
534548
* @returns A Promise of SelectPlanResponse

packages/clients/src/api/cockpit/v1beta1/index.gen.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ export type {
1111
ContactPoint,
1212
ContactPointEmail,
1313
CreateContactPointRequest,
14+
CreateDatasourceRequest,
1415
CreateGrafanaUserRequest,
1516
CreateTokenRequest,
17+
Datasource,
18+
DatasourceType,
1619
DeactivateCockpitRequest,
1720
DeleteContactPointRequest,
1821
DeleteGrafanaUserRequest,

packages/clients/src/api/cockpit/v1beta1/marshalling.gen.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ import type {
1717
ContactPoint,
1818
ContactPointEmail,
1919
CreateContactPointRequest,
20+
CreateDatasourceRequest,
2021
CreateGrafanaUserRequest,
2122
CreateTokenRequest,
23+
Datasource,
2224
DeactivateCockpitRequest,
2325
DeleteContactPointRequest,
2426
DeleteGrafanaUserRequest,
@@ -179,6 +181,22 @@ export const unmarshalCockpitMetrics = (data: unknown) => {
179181
} as CockpitMetrics
180182
}
181183

184+
export const unmarshalDatasource = (data: unknown) => {
185+
if (!isJSONObject(data)) {
186+
throw new TypeError(
187+
`Unmarshalling the type 'Datasource' failed as data isn't a dictionary.`,
188+
)
189+
}
190+
191+
return {
192+
id: data.id,
193+
name: data.name,
194+
projectId: data.project_id,
195+
type: data.type,
196+
url: data.url,
197+
} as Datasource
198+
}
199+
182200
export const unmarshalListContactPointsResponse = (data: unknown) => {
183201
if (!isJSONObject(data)) {
184202
throw new TypeError(
@@ -302,6 +320,15 @@ export const marshalCreateContactPointRequest = (
302320
project_id: request.projectId ?? defaults.defaultProjectId,
303321
})
304322

323+
export const marshalCreateDatasourceRequest = (
324+
request: CreateDatasourceRequest,
325+
defaults: DefaultValues,
326+
): Record<string, unknown> => ({
327+
name: request.name,
328+
project_id: request.projectId ?? defaults.defaultProjectId,
329+
type: request.type ?? 'unknown_datasource_type',
330+
})
331+
305332
export const marshalCreateGrafanaUserRequest = (
306333
request: CreateGrafanaUserRequest,
307334
defaults: DefaultValues,

packages/clients/src/api/cockpit/v1beta1/types.gen.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ export type CockpitStatus =
1010
| 'updating'
1111
| 'error'
1212

13+
export type DatasourceType =
14+
| 'unknown_datasource_type'
15+
| 'metrics'
16+
| 'logs'
17+
| 'traces'
18+
| 'alerts'
19+
1320
export type GrafanaUserRole = 'unknown_role' | 'editor' | 'viewer'
1421

1522
export type ListGrafanaUsersRequestOrderBy = 'login_asc' | 'login_desc'
@@ -74,6 +81,20 @@ export interface ContactPointEmail {
7481
to: string
7582
}
7683

84+
/** Datasource. */
85+
export interface Datasource {
86+
/** ID of the datasource. */
87+
id: string
88+
/** ID of the Project the Cockpit belongs to. */
89+
projectId: string
90+
/** Datasource name. */
91+
name: string
92+
/** Datasource URL. */
93+
url: string
94+
/** Datasource type. */
95+
type: DatasourceType
96+
}
97+
7798
/** Grafana user. */
7899
export interface GrafanaUser {
79100
/** ID of the Grafana user. */
@@ -217,6 +238,15 @@ export type ResetCockpitGrafanaRequest = {
217238
projectId?: string
218239
}
219240

241+
export type CreateDatasourceRequest = {
242+
/** ID of the Project the Cockpit belongs to. */
243+
projectId?: string
244+
/** Datasource name. */
245+
name: string
246+
/** Datasource type. */
247+
type?: DatasourceType
248+
}
249+
220250
export type CreateTokenRequest = {
221251
/** ID of the Project. */
222252
projectId?: string

0 commit comments

Comments
 (0)