//native
type Digitalocean = {
token: string;
};
/**
* Create a New Certificate
* To upload new SSL certificate which you have previously generated, send a POST
request to `/v2/certificates`.
When uploading a user-generated certificate, the `private_key`,
`leaf_certificate`, and optionally the `certificate_chain` attributes should
be provided. The type must be set to `custom`.
When using Let's Encrypt to create a certificate, the `dns_names` attribute
must be provided, and the type must be set to `lets_encrypt`.
*/
export async function main(
auth: Digitalocean,
body:
| ({ name: string; type?: "custom" | "lets_encrypt" } & {
dns_names: string[];
})
| ({ name: string; type?: "custom" | "lets_encrypt" } & {
private_key: string;
leaf_certificate: string;
certificate_chain?: string;
}),
) {
const url = new URL(`https://api.digitalocean.com/v2/certificates`);
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