0

Retrieve the Public Certificate

by
Published Dec 20, 2024

To retrieve the public certificate used to secure the connection to the database cluster send a GET request to `/v2/databases/$DATABASE_ID/ca`. The response will be a JSON object with a `ca` key. This will be set to an object containing the base64 encoding of the public key certificate.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Retrieve the Public Certificate
7
 * To retrieve the public certificate used to secure the connection to the database cluster send a GET request to
8
`/v2/databases/$DATABASE_ID/ca`.
9

10
The response will be a JSON object with a `ca` key. This will be set to an object
11
containing the base64 encoding of the public key certificate.
12

13
 */
14
export async function main(auth: Digitalocean, database_cluster_uuid: string) {
15
  const url = new URL(
16
    `https://api.digitalocean.com/v2/databases/${database_cluster_uuid}/ca`,
17
  );
18

19
  const response = await fetch(url, {
20
    method: "GET",
21
    headers: {
22
      Authorization: "Bearer " + auth.token,
23
    },
24
    body: undefined,
25
  });
26
  if (!response.ok) {
27
    const text = await response.text();
28
    throw new Error(`${response.status} ${text}`);
29
  }
30
  return await response.json();
31
}
32