Edits history of script submission #18318 for ' Get cluster kubeconfig (qovery)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Get cluster kubeconfig
     *
     */
    export async function main(
    	auth: RT.Qovery,
    	organizationId: string,
    	clusterId: string,
    	with_token_from_cli?: string | undefined
    ) {
    	const url = new URL(
    		`https://api.qovery.com/organization/${organizationId}/cluster/${clusterId}/kubeconfig`
    	)
    	for (const [k, v] of [['with_token_from_cli', with_token_from_cli]]) {
    		if (v !== undefined && v !== '') {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: 'Token ' + auth.apiKey
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.text()
    }
    

    Submitted by hugo697 235 days ago