import {z} from 'zod' export type C1ApiWorkloadFederationV1WorkloadFederationServiceCreateTrustRequestInput = {allowSourceCidrs?: (Array | null) | undefined, conditionExpression?: string | undefined, description?: string | undefined, displayName?: string | undefined, passthroughClaims?: (Array | null) | undefined, providerId?: string | undefined, scopedRoleIds?: (Array | null) | undefined}; export type CreateApiApiV1ServicePrincipalsServicePrincipalIdTrustsArgs = {service_principal_id: string, body: C1ApiWorkloadFederationV1WorkloadFederationServiceCreateTrustRequestInput}; export type CreateApiApiV1ServicePrincipalsServicePrincipalIdTrustsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, oauth?: string | undefined, fetch?: typeof fetch | undefined}; export const c1ApiWorkloadFederationV1C1EdgeService = z.object({appId: z.string().optional(), resourceId: z.string().optional(), resourceKind: z.enum(["C1_EDGE_RESOURCE_KIND_UNSPECIFIED", "C1_EDGE_RESOURCE_KIND_EDGE", "C1_EDGE_RESOURCE_KIND_AUTHZEN_SERVER"]).optional()}); export const c1ApiWorkloadFederationV1WorkloadFederationTrust = z.object({allowSourceCidrs: z.array(z.string()).nullable().optional(), c1EdgeService: c1ApiWorkloadFederationV1C1EdgeService.nullable().optional(), clientId: z.string().optional(), conditionExpression: z.string().optional(), createdAt: z.string().nullable().optional(), description: z.string().optional(), disabled: z.boolean().optional(), displayName: z.string().optional(), passthroughClaims: z.array(z.string()).nullable().optional(), providerId: z.string().optional(), scopedRoleIds: z.array(z.string()).nullable().optional(), servicePrincipalId: z.string().optional(), updatedAt: z.string().nullable().optional()}); export const c1ApiWorkloadFederationV1WorkloadFederationServiceCreateTrustResponse = z.object({trust: c1ApiWorkloadFederationV1WorkloadFederationTrust.nullable().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 }; /** * Create Trust * * POST /api/v1/service_principals/{service_principal_id}/trusts */ export const createApiApiV1ServicePrincipalsServicePrincipalIdTrusts = async (args: CreateApiApiV1ServicePrincipalsServicePrincipalIdTrustsArgs, options?: CreateApiApiV1ServicePrincipalsServicePrincipalIdTrustsOptions) => { const {baseUrl = "https://example.conductor.one", fetch: fetchFn = fetch, bearerAuth, oauth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) if (oauth !== undefined) headers.set('authorization', `Bearer ${oauth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/service_principals/${encodeURIComponent(String(args.service_principal_id))}/trusts${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(c1ApiWorkloadFederationV1WorkloadFederationServiceCreateTrustResponse, await res.json()) };