From 0278474997ac16a9f44276c3373a27daba04fbe1 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Mon, 8 Apr 2024 14:22:11 +0200 Subject: [PATCH] Add NewUnsafeRequest for hardware settings Signed-off-by: Petr "Stone" Hracek --- src/index.ts | 10 ++++++++ src/schema.ts | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/src/index.ts b/src/index.ts index 5531b97..f6aa25e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,7 @@ import { About, Composes, NewRequest, + NewUnsafeRequest, NewRequestResponse, Ranch, Request, @@ -21,6 +22,7 @@ import { ranchSchema, newRequestResponseSchema, newRequestSchema, + newUnsafeRequestSchema, requestIdSchema, requestSchema, } from './schema'; @@ -29,6 +31,7 @@ export type { Ranch, NewRequest, NewRequestResponse, + NewUnsafeRequest, Request, Composes, About, @@ -44,6 +47,7 @@ export { urlSchema, ranchSchema, newRequestSchema, + newUnsafeRequestSchema, requestIdSchema, }; @@ -66,6 +70,12 @@ export default class TestingFarmAPI { async newRequest(request: NewRequest): Promise; async newRequest(request: NewRequest, strict: boolean): Promise; + async newUnsafeRequest(request: NewUnsafeRequest, strict: boolean): Promise { + const data = newUnsafeRequestSchema.parse(request); + return newRequestResponseSchema.parse( + await this.link.post('requests', data) + ); + } async newRequest(request: NewRequest, strict?: boolean): Promise { const data = newRequestSchema.parse(request); diff --git a/src/schema.ts b/src/schema.ts index 6895270..f522a0f 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -97,6 +97,66 @@ const environmentSchema = z.object({ kickstart: z.any().optional(), }); +const environmentHardwareUnsafeSchema = z.object({ + arch: z.string().min(1), + os: z + .object({ + compose: z.string().min(1), + }) + .optional(), + pool: z.string().min(1).optional().nullable(), + variables: z.record(z.string()).optional(), + secrets: z.record(z.string()).optional(), + artifacts: z + .array( + z.object({ + id: z.string().min(1), + type: z.string().min(1), + packages: z.array(z.string().min(1)).optional(), + }) + ) + .optional(), + hardware: z.any() + .optional() + .nullable(), + settings: z + .object({ + pipeline: z + .object({ + skip_guest_setup: z.boolean().optional(), + }) + .optional() + .nullable(), + provisioning: z + .object({ + post_install_script: z.string().min(1).optional(), + tags: z.record(z.string()).optional(), + }) + .optional() + .nullable(), + }) + .optional(), + tmt: z + .object({ + // https://tmt.readthedocs.io/en/stable/spec/context.html#dimension + context: z + .object({ + distro: z.string().min(1).optional(), + variant: z.string().min(1).optional(), + arch: z.string().min(1).optional(), + component: z.string().min(1).optional(), + collection: z.string().min(1).optional(), + module: z.string().min(1).optional(), + initiator: z.string().min(1).optional(), + trigger: z.string().min(1).optional(), + }) + .optional() + .nullable(), + }) + .optional(), + kickstart: z.any().optional(), +}); + const notificationSchema = z.object({ webhook: z .object({ @@ -136,7 +196,15 @@ export const newRequestSchema = z.object({ settings: settingsSchema.optional().nullable(), }); +export const newUnsafeRequestSchema = z.object({ + api_key: z.any(), + test: testObjectSchema, + environments: z.array(environmentHardwareUnsafeSchema).optional(), + notification: notificationSchema.optional().nullable(), + settings: settingsSchema.optional().nullable(), +}); export type NewRequest = z.infer; +export type NewUnsafeRequest = z.infer; export const newRequestResponseSchema = z.object({ id: requestIdSchema,