//native
type Digitalocean = {
token: string;
};
/**
* Get Docker Credentials for Container Registry
* In order to access your container registry with the Docker client or from a
Kubernetes cluster, you will need to configure authentication.
*/
export async function main(
auth: Digitalocean,
expiry_seconds: string | undefined,
read_write: string | undefined,
) {
const url = new URL(
`https://api.digitalocean.com/v2/registry/docker-credentials`,
);
for (const [k, v] of [
["expiry_seconds", expiry_seconds],
["read_write", read_write],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 536 days ago