import {z} from 'zod' export type GetApiWorkloadIdentityProvidersWorkloadIdentityProviderArgs = {workload_identity_provider: string}; export type GetApiWorkloadIdentityProvidersWorkloadIdentityProviderOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const workloadIdentityProvider = z.object({attributes: z.object({"allowed-audiences": z.array(z.string()), "created-at": z.string().optional(), "created-by-email": z.string().nullable().optional(), name: z.string().max(255), status: z.enum(["pending", "active", "invalid_provider_settings", "fetch_jwks_error", "not_supported_jwks", "internal_error"]).optional(), url: z.string().max(255)}), id: z.string().optional(), links: z.record(z.string(), z.string()).optional(), relationships: z.object({"assume-service-account-policies": z.object({data: z.array(z.object({id: z.string(), type: z.enum(["assume-service-account-policies", ""])})).nullable()}).optional()}).optional(), type: z.literal("workload-identity-providers")}); export const workloadIdentityProviderDocument = z.object({data: workloadIdentityProvider.optional(), included: z.array(z.object({})).optional(), meta: z.object({}).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 }; /** * Get Workload Identity Provider * * GET /workload-identity-providers/{workload_identity_provider} */ export const getApiWorkloadIdentityProvidersWorkloadIdentityProvider = async (args: GetApiWorkloadIdentityProvidersWorkloadIdentityProviderArgs, options?: GetApiWorkloadIdentityProvidersWorkloadIdentityProviderOptions) => { const {baseUrl = "https://example.scalr.io/api/iacp/v3", fetch: fetchFn = fetch, APIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/vnd.api+json") if (APIKey !== undefined) headers.set('authorization', `Bearer ${APIKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/workload-identity-providers/${encodeURIComponent(String(args.workload_identity_provider))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(workloadIdentityProviderDocument, await res.json()) };