0

Update Database Clusters' Metrics Endpoint Credentials

by
Published Dec 20, 2024

To update the credentials for all database clusters' metrics endpoints, send a PUT request to `/v2/databases/metrics/credentials`. A successful request will receive a 204 No Content status code with no body in response.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Update Database Clusters' Metrics Endpoint Credentials
7
 * To update the credentials for all database clusters' metrics endpoints, send a PUT request to `/v2/databases/metrics/credentials`. A successful request will receive a 204 No Content status code  with no body in response.
8
 */
9
export async function main(
10
  auth: Digitalocean,
11
  body: {
12
    credentials?: {
13
      basic_auth_username?: string;
14
      basic_auth_password?: string;
15
    };
16
  },
17
) {
18
  const url = new URL(
19
    `https://api.digitalocean.com/v2/databases/metrics/credentials`,
20
  );
21

22
  const response = await fetch(url, {
23
    method: "PUT",
24
    headers: {
25
      "Content-Type": "application/json",
26
      Authorization: "Bearer " + auth.token,
27
    },
28
    body: JSON.stringify(body),
29
  });
30
  if (!response.ok) {
31
    const text = await response.text();
32
    throw new Error(`${response.status} ${text}`);
33
  }
34
  return await response.json();
35
}
36