From 63d91b33079b4b561e15ac403d242514597c926d Mon Sep 17 00:00:00 2001 From: Gianni Carafa Date: Tue, 13 Dec 2022 14:12:17 +0100 Subject: [PATCH] Fix/deployment key recreation must allways recreate keys --- src/git/gitea.ts | 21 +-------------------- src/git/gitlab.ts | 22 +--------------------- src/git/gogs.ts | 22 +--------------------- 3 files changed, 3 insertions(+), 62 deletions(-) diff --git a/src/git/gitea.ts b/src/git/gitea.ts index 421970e1..70964b85 100644 --- a/src/git/gitea.ts +++ b/src/git/gitea.ts @@ -143,7 +143,7 @@ export class GiteaApi extends Repo { const keyPair = this.createDeployKeyPair(); - const title: string = "bot@kubero"; + const title: string = "bot@kubero."+crypto.randomBytes(4).toString('hex'); let ret: IDeploykeyR = { status: 500, @@ -159,25 +159,6 @@ export class GiteaApi extends Repo { priv: keyPair.privKeyBase64 } } - //https://try.gitea.io/api/swagger#/repository/repoListKeys - const keysList = await this.gitea.repos.repoListKeys(owner, repo) - .catch((error: any) => { - console.log(error) - return ret; - }) - - // try to find the key - for (let key of keysList.data) { - if (key.title === title && - key.read_only === true) { - ret = { - status: 200, - statusText: 'found', - data: key, - } - return ret; - } - } try { //https://try.gitea.io/api/swagger#/repository/repoCreateKey diff --git a/src/git/gitlab.ts b/src/git/gitlab.ts index 299b7f17..822ed522 100644 --- a/src/git/gitlab.ts +++ b/src/git/gitlab.ts @@ -159,7 +159,7 @@ export class GitlabApi extends Repo { const keyPair = this.createDeployKeyPair(); - const title: string = "bot@kubero"; + const title: string = "bot@kubero."+Date.now(); let ret: IDeploykeyR = { status: 500, @@ -175,26 +175,6 @@ export class GitlabApi extends Repo { priv: keyPair.privKeyBase64 } } - // https://docs.gitlab.com/ee/api/deploy_keys.html#list-deploy-keys-for-project - const keysList:any = await this.gitlab.get(`projects/${owner}%2F${repo}/deploy_keys`) - .catch((error: any) => { - console.log(error) - return ret; - }) - - // try to find the key - for (let key of keysList) { - if (key.title === title && - key.read_only === true) { - ret = { - status: 422, - statusText: 'found', - data: key, - } - return ret; - } - } - try { // https://docs.gitlab.com/ee/api/deploy_keys.html#add-deploy-key let res:any = await this.gitlab.post(`projects/${owner}%2F${repo}/deploy_keys`, JSON.stringify({ diff --git a/src/git/gogs.ts b/src/git/gogs.ts index b338d5a2..fba9405b 100644 --- a/src/git/gogs.ts +++ b/src/git/gogs.ts @@ -143,7 +143,7 @@ export class GogsApi extends Repo { const keyPair = this.createDeployKeyPair(); - const title: string = "bot@kubero"; + const title: string = "bot@kubero."+crypto.randomBytes(4).toString('hex'); let ret: IDeploykeyR = { status: 500, @@ -159,26 +159,6 @@ export class GogsApi extends Repo { priv: keyPair.privKeyBase64 } } - //https://try.gitea.io/api/swagger#/repository/repoListKeys - const keysList = await this.gitea.repos.repoListKeys(owner, repo) - .catch((error: any) => { - console.log(error) - return ret; - }) - - // try to find the key - for (let key of keysList.data) { - if (key.title === title && - key.read_only === true) { - ret = { - status: 422, - statusText: 'found', - data: key, - } - return ret; - } - } - try { //https://try.gitea.io/api/swagger#/repository/repoCreateKey let res = await this.gitea.repos.repoCreateKey(owner, repo, {