//native
type Digitalocean = {
token: string;
};
/**
* Update an SSH Key's Name
* To update the name of an SSH key, send a PUT request to either `/v2/account/keys/$SSH_KEY_ID` or `/v2/account/keys/$SSH_KEY_FINGERPRINT`. Set the `name` attribute to the new name you want to use.
*/
export async function main(
auth: Digitalocean,
ssh_key_identifier: string,
body: { name?: string },
) {
const url = new URL(
`https://api.digitalocean.com/v2/account/keys/${ssh_key_identifier}`,
);
const response = await fetch(url, {
method: "PUT",
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 536 days ago