import {z} from 'zod' export type V1IndexData = {data?: Array | undefined, search_score?: number | undefined, tenant?: string | undefined, will_be_deleted_at?: string | undefined}; export type GoogleprotobufAny = {'@type'?: string | undefined} | {[key: string]: unknown}; export type V1Meta = {annotations?: {[key: string]: string} | undefined, create_time?: string | undefined, created_by?: string | undefined, description?: string | undefined, index_data?: V1IndexData | undefined, kind?: string | undefined, name: string, parent_kind?: string | undefined, parent_uuid?: string | undefined, references?: {[key: string]: GoogleprotobufAny} | undefined, tags?: Array | undefined, update_time?: string | undefined, updated_by?: string | undefined, upsert_time?: string | undefined, version?: string | undefined}; export type V1SystemRole = 'SYSTEM_ROLE_UNSPECIFIED' | 'SYSTEM_ROLE_ADMIN' | 'SYSTEM_ROLE_READ_ONLY' | 'SYSTEM_ROLE_POLICY_EDITOR' | 'SYSTEM_ROLE_CODE_SCANNER' | 'SYSTEM_ROLE_ENDOR_PATCHING' | 'SYSTEM_ROLE_SYNC_ORG' | 'SYSTEM_ROLE_ONPREM_SCHEDULER' | 'SYSTEM_ROLE_ENDOR_PROXY' | 'SYSTEM_ROLE_PACKAGE_FIREWALL' | 'SYSTEM_ROLE_AI_AUDIT' | 'SYSTEM_ROLE_PACKAGE_FIREWALL_MANAGER'; export type V1Method = 'METHOD_UNSPECIFIED' | 'METHOD_READ' | 'METHOD_CREATE' | 'METHOD_UPDATE' | 'METHOD_DELETE' | 'METHOD_ALL'; export type PermissionsMethods = {methods?: Array | undefined}; export type V1Permissions = {except_resources?: Array | undefined, roles?: Array | undefined, rules?: {[key: string]: PermissionsMethods} | undefined}; export type V1AuthorizationPolicySpec = {clause: Array, expiration_time?: string | undefined, is_support_policy?: boolean | undefined, permissions: V1Permissions, propagate: boolean, target_namespaces: Array}; export type AuthorizationPolicyServiceCreateAuthorizationPolicyBody = {meta: V1Meta, propagate?: boolean | undefined, spec: V1AuthorizationPolicySpec, tenant_meta: Record, uuid?: string | undefined}; export type CreateApiV1NamespacesTenantMetaNamespaceAuthorizationPoliciesArgs = {'tenant_meta.namespace': string, body: AuthorizationPolicyServiceCreateAuthorizationPolicyBody}; export type CreateApiV1NamespacesTenantMetaNamespaceAuthorizationPoliciesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const v1IndexData = z.object({data: z.array(z.string()).optional(), search_score: z.number().optional(), tenant: z.string().optional(), will_be_deleted_at: z.string().optional()}); export const googleprotobufAny = z.object({"@type": z.string().optional()}).and(z.record(z.string(), z.unknown())); export const v1Meta = z.object({annotations: z.record(z.string(), z.string()).optional(), create_time: z.string().optional(), created_by: z.string().optional(), description: z.string().optional(), index_data: v1IndexData.optional(), kind: z.string().optional(), name: z.string(), parent_kind: z.string().optional(), parent_uuid: z.string().optional(), references: z.record(z.string(), googleprotobufAny).optional(), tags: z.array(z.string()).optional(), update_time: z.string().optional(), updated_by: z.string().optional(), upsert_time: z.string().optional(), version: z.string().optional()}); export const v1SystemRole = z.enum(["SYSTEM_ROLE_UNSPECIFIED", "SYSTEM_ROLE_ADMIN", "SYSTEM_ROLE_READ_ONLY", "SYSTEM_ROLE_POLICY_EDITOR", "SYSTEM_ROLE_CODE_SCANNER", "SYSTEM_ROLE_ENDOR_PATCHING", "SYSTEM_ROLE_SYNC_ORG", "SYSTEM_ROLE_ONPREM_SCHEDULER", "SYSTEM_ROLE_ENDOR_PROXY", "SYSTEM_ROLE_PACKAGE_FIREWALL", "SYSTEM_ROLE_AI_AUDIT", "SYSTEM_ROLE_PACKAGE_FIREWALL_MANAGER"]); export const v1Method = z.enum(["METHOD_UNSPECIFIED", "METHOD_READ", "METHOD_CREATE", "METHOD_UPDATE", "METHOD_DELETE", "METHOD_ALL"]); export const permissionsMethods = z.object({methods: z.array(v1Method).optional()}); export const v1Permissions = z.object({except_resources: z.array(z.string()).optional(), roles: z.array(v1SystemRole).optional(), rules: z.record(z.string(), permissionsMethods).optional()}); export const v1AuthorizationPolicySpec = z.object({clause: z.array(z.string()), expiration_time: z.string().optional(), is_support_policy: z.boolean().optional(), permissions: v1Permissions, propagate: z.boolean(), target_namespaces: z.array(z.string())}); export const v1TenantMeta = z.object({namespace: z.string()}); export const v1AuthorizationPolicy = z.object({meta: v1Meta, propagate: z.boolean().optional(), spec: v1AuthorizationPolicySpec, tenant_meta: v1TenantMeta, uuid: z.string().optional()}); 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 }; /** * CreateAuthorizationPolicy * * POST /v1/namespaces/{tenant_meta.namespace}/authorization-policies */ export const createApiV1NamespacesTenantMetaNamespaceAuthorizationPolicies = async (args: CreateApiV1NamespacesTenantMetaNamespaceAuthorizationPoliciesArgs, options?: CreateApiV1NamespacesTenantMetaNamespaceAuthorizationPoliciesOptions) => { const {baseUrl = "https://api.endorlabs.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/namespaces/${encodeURIComponent(String(args['tenant_meta.namespace']))}/authorization-policies${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(v1AuthorizationPolicy, await res.json()) };