Skip to content

Commit

Permalink
add function that deletes SSH key in github account (#20891)
Browse files Browse the repository at this point in the history
  • Loading branch information
SkorikSergey authored Dec 7, 2021
1 parent 0a9cb74 commit fcb04b7
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/e2e/utils/VCS/github/GitHubUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,25 @@ export class GitHubUtil {
}
}

async deletePublicSshKeyByName(authToken: string, keyName: string) {
const gitHubApiSshURL: string = GitHubUtil.GITHUB_API_ENTRIPOINT_URL + 'user/keys';
const authHeader = { headers: { 'Authorization': 'token ' + authToken, 'Content-Type': 'application/json' } };
try {
const response = await axios.get(gitHubApiSshURL, authHeader);
const stringified = JSON.stringify(response.data);
const arrayOfPublicKeys = JSON.parse(stringified);
for (let entry of arrayOfPublicKeys) {
if (entry.title === keyName) {
this.removePublicSshKey(authToken, entry.id);
break;
}
}
} catch (error) {
console.error('Cannot delete the ' + keyName + ' public key from the GitHub account');
console.error(error);
throw error;
}
}

async removeAllPublicSshKeys(authToken: string) {
try {
Expand Down

0 comments on commit fcb04b7

Please sign in to comment.