0

Validate a Container Registry Name

by
Published Dec 20, 2024

To validate that a container registry name is available for use, send a POST request to `/v2/registry/validate-name`. If the name is both formatted correctly and available, the response code will be 204 and contain no body. If the name is already in use, the response will be a 409 Conflict.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Validate a Container Registry Name
7
 * To validate that a container registry name is available for use, send a POST
8
request to `/v2/registry/validate-name`.
9

10
If the name is both formatted correctly and available, the response code will
11
be 204 and contain no body. If the name is already in use, the response will
12
be a 409 Conflict.
13

14
 */
15
export async function main(auth: Digitalocean, body: { name: string }) {
16
  const url = new URL(`https://api.digitalocean.com/v2/registry/validate-name`);
17

18
  const response = await fetch(url, {
19
    method: "POST",
20
    headers: {
21
      "Content-Type": "application/json",
22
      Authorization: "Bearer " + auth.token,
23
    },
24
    body: JSON.stringify(body),
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