type Bitbucket = {
username: string;
password: string;
};
/**
* Update SSH key pair
* Create or update the repository SSH key pair. The private key will be set as a default SSH identity in your build container.
*/
export async function main(
auth: Bitbucket,
workspace: string,
repo_slug: string,
body: { type: string; [k: string]: unknown } & {
private_key?: string;
public_key?: string;
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/pipelines_config/ssh/key_pair`
);
const response = await fetch(url, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
},
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 407 days ago