//native
type Cockroachdb = {
token: string;
};
/**
* Enable CMEK for a cluster
* Can be used by the following roles assigned at the organization, folder or cluster scope:
- CLUSTER_ADMIN
- CLUSTER_OPERATOR_WRITER
*/
export async function main(
auth: Cockroachdb,
cluster_id: string,
body: {
region_specs: {
key_spec?: {
auth_principal?: string;
type?: "AWS_KMS" | "GCP_CLOUD_KMS" | "NULL_KMS";
uri?: string;
};
region?: string;
}[];
},
) {
const url = new URL(
`https://cockroachlabs.cloud/api/v1/clusters/${cluster_id}/cmek`,
);
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