export type GetApiKubeconfigSaNmeArgs = {saNme: string}; export type GetApiKubeconfigSaNmeOptions = {baseUrl: string, idToken?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get kubeconfig generated from the latest service account token * * GET /kubeconfig/{saNme} */ export const getApiKubeconfigSaNme = async (args: GetApiKubeconfigSaNmeArgs, options: GetApiKubeconfigSaNmeOptions) => { const {baseUrl, fetch: fetchFn = fetch, idToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/yaml") if (idToken !== undefined) headers.set('authorization', `Bearer ${idToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/kubeconfig/${encodeURIComponent(String(args.saNme))}${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 res.blob() };