Edits history of script submission #10683 for ' Patch org-level claims (circleci)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Circleci = {
    	token: string
    }
    /**
     * Patch org-level claims
     * Creates/Updates org-level custom claims of OIDC identity tokens
     */
    export async function main(
    	auth: Circleci,
    	orgID: string,
    	body: { audience?: string[]; ttl?: string }
    ) {
    	const url = new URL(`https://circleci.com/api/v2/org/${orgID}/oidc-custom-claims`)
    
    	const response = await fetch(url, {
    		method: 'PATCH',
    		headers: {
    			'Content-Type': 'application/json',
    			'Circle-Token': auth.token
    		},
    		body: JSON.stringify(body)
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 536 days ago