Skip to content

Commit

Permalink
Improve git +ssh test (#17306)
Browse files Browse the repository at this point in the history
* improve git test
  • Loading branch information
musienko-maxim authored Dec 4, 2020
1 parent c55ddf2 commit 135edf8
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/e2e/utils/VCS/github/GitHubUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,48 @@ export class GitHubUtil {
}
}

async getPublicSshKeys(authToken: string): Promise<Array<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 arrayOfWorkspaces = JSON.parse(stringified);
const idOfRunningWorkspace: Array<string> = new Array();
for (let entry of arrayOfWorkspaces) {
idOfRunningWorkspace.push(entry.id);
}
return idOfRunningWorkspace;
} catch (error) {
console.error('Cannot get public Keys from github: ' + gitHubApiSshURL);
console.error(error);
throw error;
}
}

async removePublicSshKey(authToken: string, keyId: string) {
const gitHubApiSshURL: string = GitHubUtil.GITHUB_API_ENTRIPOINT_URL + 'user/keys/' + keyId;
const authHeader = { headers: { 'Authorization': 'token ' + authToken, 'Content-Type': 'application/json' } };
try { await axios.delete(gitHubApiSshURL, authHeader); } catch (error) {
console.error('Cannot delete the public key from the GitHub account: ');
console.error(error);
throw error;
}
}


async removeAllPublicSshKeys(authToken: string) {
try {
const idList: string[] = await this.getPublicSshKeys(authToken);
for (let id of idList) {
this.removePublicSshKey(authToken, id);
}

} catch (error) {
console.error('Cannot delete the public key from the GitHub account: ');
console.error(error);
throw error;
}
}

}

0 comments on commit 135edf8

Please sign in to comment.