//native
type Digitalocean = {
token: string;
};
/**
* Create a New SSH Key
* To add a new SSH public key to your DigitalOcean account, send a POST request to `/v2/account/keys`. Set the `name` attribute to the name you wish to use and the `public_key` attribute to the full public key you are adding.
*/
export async function main(
auth: Digitalocean,
body: { id?: number; fingerprint?: string; public_key: string; name: string },
) {
const url = new URL(`https://api.digitalocean.com/v2/account/keys`);
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 536 days ago