//native
type Cockroachdb = {
token: string;
};
/**
* Create a service account
* Can be used by the following roles assigned at the organization scope:
- ORG_ADMIN
- CLUSTER_ADMIN
*/
export async function main(
auth: Cockroachdb,
body: {
description: string;
name: string;
roles: {
name:
| "BILLING_COORDINATOR"
| "ORG_ADMIN"
| "ORG_MEMBER"
| "CLUSTER_ADMIN"
| "CLUSTER_OPERATOR_WRITER"
| "CLUSTER_DEVELOPER"
| "CLUSTER_CREATOR"
| "FOLDER_ADMIN"
| "FOLDER_MOVER";
resource: { id?: string; type: "ORGANIZATION" | "CLUSTER" | "FOLDER" };
}[];
},
) {
const url = new URL(`https://cockroachlabs.cloud/api/v1/service-accounts`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + 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 235 days ago