Skip to content

Commit

Permalink
Fix/deployment key recreation must allways recreate keys
Browse files Browse the repository at this point in the history
  • Loading branch information
mms-gianni committed Dec 13, 2022
1 parent 6392805 commit 63d91b3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 62 deletions.
21 changes: 1 addition & 20 deletions src/git/gitea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
22 changes: 1 addition & 21 deletions src/git/gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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({
Expand Down
22 changes: 1 addition & 21 deletions src/git/gogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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, {
Expand Down

0 comments on commit 63d91b3

Please sign in to comment.