Skip to content

Commit

Permalink
Add NewUnsafeRequest for hardware settings
Browse files Browse the repository at this point in the history
Signed-off-by: Petr "Stone" Hracek <[email protected]>
  • Loading branch information
phracek committed Apr 8, 2024
1 parent 8b522d6 commit 0278474
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
About,
Composes,
NewRequest,
NewUnsafeRequest,
NewRequestResponse,
Ranch,
Request,
Expand All @@ -21,6 +22,7 @@ import {
ranchSchema,
newRequestResponseSchema,
newRequestSchema,
newUnsafeRequestSchema,
requestIdSchema,
requestSchema,
} from './schema';
Expand All @@ -29,6 +31,7 @@ export type {
Ranch,
NewRequest,
NewRequestResponse,
NewUnsafeRequest,
Request,
Composes,
About,
Expand All @@ -44,6 +47,7 @@ export {
urlSchema,
ranchSchema,
newRequestSchema,
newUnsafeRequestSchema,
requestIdSchema,
};

Expand All @@ -66,6 +70,12 @@ export default class TestingFarmAPI {

async newRequest(request: NewRequest): Promise<NewRequestResponse>;
async newRequest(request: NewRequest, strict: boolean): Promise<unknown>;
async newUnsafeRequest(request: NewUnsafeRequest, strict: boolean): Promise<unknown> {
const data = newUnsafeRequestSchema.parse(request);
return newRequestResponseSchema.parse(
await this.link.post('requests', data)
);
}
async newRequest(request: NewRequest, strict?: boolean): Promise<unknown> {
const data = newRequestSchema.parse(request);

Expand Down
68 changes: 68 additions & 0 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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<typeof newRequestSchema>;
export type NewUnsafeRequest = z.infer<typeof newUnsafeRequestSchema>;

export const newRequestResponseSchema = z.object({
id: requestIdSchema,
Expand Down

0 comments on commit 0278474

Please sign in to comment.