0
List SSH keys
One script reply has been approved by the moderators Verified

Returns a paginated list of the user's SSH public keys.

Created by hugo697 425 days ago Viewed 9165 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 425 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * List SSH keys
7
 * Returns a paginated list of the user's SSH public keys.
8
 */
9
export async function main(auth: Bitbucket, selected_user: string) {
10
  const url = new URL(
11
    `https://api.bitbucket.org/2.0/users/${selected_user}/ssh-keys`
12
  );
13

14
  const response = await fetch(url, {
15
    method: "GET",
16
    headers: {
17
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
18
    },
19
    body: undefined,
20
  });
21
  if (!response.ok) {
22
    const text = await response.text();
23
    throw new Error(`${response.status} ${text}`);
24
  }
25
  return await response.json();
26
}
27