export type RESTAdmRuleCriterion = {name: string, op: string, value: string, sub_criteria?: Array | undefined}; export type RESTAdmissionRuleConfig = {id: number, category: string, comment?: string | undefined, criteria?: Array | undefined, disable?: boolean | undefined, actions?: Array | undefined, cfg_type: string, rule_type: string}; export type RESTAdmissionRuleConfigData = {config: RESTAdmissionRuleConfig}; export type PatchApiAdmissionRuleArgs = {'X-Auth-Token': string, body: RESTAdmissionRuleConfigData}; export type PatchApiAdmissionRuleOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Update admission rule * * PATCH /admission/rule */ export const patchApiAdmissionRule = async (args: PatchApiAdmissionRuleArgs, options: PatchApiAdmissionRuleOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['X-Auth-Token'] != null) headers.set("X-Auth-Token", String(args['X-Auth-Token'])) const url = `${baseUrl.replace(/\/+$/, '')}/admission/rule${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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 undefined };