import {z} from 'zod' export type DeleteApiOrgsOrgNameGovernancePoliciesPolicyIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const scope = z.object({teams: z.array(z.string()).optional()}); export const ruleActions = z.array(z.enum(["connect:tcp", "connect:udp", "read", "write", "request:get", "request:post", "request:put", "request:delete", "request:patch", "request:head", "request:options", "request:connect", "request:trace"])); export const ruleResources = z.array(z.string()); export const hTTPResource = z.object({host: z.string().min(1), port: z.number().int().gte(1).lte(65535).optional(), path: z.string()}); export const hTTPResources = z.array(hTTPResource); export const ruleDecision = z.enum(["allow", "deny"]); export const rule = z.union([z.object({id: z.string(), name: z.string(), actions: ruleActions, resources: ruleResources, http_resources: hTTPResources.optional(), decision: ruleDecision}), z.object({id: z.string(), name: z.string(), actions: ruleActions, resources: ruleResources.optional(), http_resources: hTTPResources, decision: ruleDecision})]); export const allowlistV0 = z.object({domain: z.enum(["network", "filesystem"]).optional(), rules: z.array(rule)}); export const cedarV1Policy = z.object({text: z.string(), schema_url: z.string()}); export const policy = z.object({id: z.string(), name: z.string(), org: z.string(), scope: scope, created_at: z.string(), updated_at: z.string(), allowlist_v0: allowlistV0.optional(), cedar_v1: cedarV1Policy.optional()}); export const deletePolicyResponse = z.object({deleted: policy}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Delete policy * * DELETE /orgs/{org_name}/governance/policies/{policy_id} */ export const deleteApiOrgsOrgNameGovernancePoliciesPolicyId = async (options?: DeleteApiOrgsOrgNameGovernancePoliciesPolicyIdOptions) => { const {baseUrl = "https://hub.docker.com/v2", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/orgs/${encodeURIComponent(String(args.org_name))}/governance/policies/${encodeURIComponent(String(args.policy_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(deletePolicyResponse, await res.json()) };