//native
type Digitalocean = {
token: string;
};
/**
* Reset a Database User's Password or Authentication Method
* To reset the password for a database user, send a POST request to
`/v2/databases/$DATABASE_ID/users/$USERNAME/reset_auth`.
For `mysql` databases, the authentication method can be specifying by
including a key in the JSON body called `mysql_settings` with the `auth_plugin`
value specified.
The response will be a JSON object with a `user` key. This will be set to an
object containing the standard database user attributes.
*/
export async function main(
auth: Digitalocean,
database_cluster_uuid: string,
username: string,
body: {
mysql_settings?: {
auth_plugin: "mysql_native_password" | "caching_sha2_password";
};
},
) {
const url = new URL(
`https://api.digitalocean.com/v2/databases/${database_cluster_uuid}/users/${username}/reset_auth`,
);
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