From 10f9d06cb0741b97abe3812061ea89b0c8eaaac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Bokvad=20Engar=C3=A5s?= Date: Thu, 5 Oct 2023 16:13:34 +0200 Subject: [PATCH 1/3] refactor project --- src/Pentest/PentestService.ts | 2 +- src/helpfunctions/JsonService.ts | 46 ++++++++++----------- src/threatmodeling/ThreatModelingService.ts | 2 +- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/Pentest/PentestService.ts b/src/Pentest/PentestService.ts index 0e88f08e..68f4534f 100644 --- a/src/Pentest/PentestService.ts +++ b/src/Pentest/PentestService.ts @@ -1,7 +1,7 @@ import * as core from '@actions/core'; export class PentestService { - public static async getStateOfPentest(pentest: { date: string; boardsTag: string }): Promise { + public static async getStateOfPentest(pentest: { date: string; boardsTag?: string }): Promise { if (process.env.pentestDate) { core.exportVariable('pentestDate', process.env.pentestDate); } else { diff --git a/src/helpfunctions/JsonService.ts b/src/helpfunctions/JsonService.ts index 27a5b90d..35b83915 100644 --- a/src/helpfunctions/JsonService.ts +++ b/src/helpfunctions/JsonService.ts @@ -20,41 +20,41 @@ export function getContentOfFile(jsonPath: string): CyDigConfig { export function validateConfig(config: unknown): void { const schema: Joi.ObjectSchema = Joi.object({ teamName: Joi.string().required(), - usingAzure: Joi.boolean().required(), + usingAzure: Joi.boolean(), threatModeling: Joi.object({ - date: Joi.string().required(), - boardsTag: Joi.string().required(), - }).required(), + date: Joi.string(), + boardsTag: Joi.string(), + }), pentest: Joi.object({ - date: Joi.string().required(), - boardsTag: Joi.string().required(), - }).required(), + date: Joi.string(), + boardsTag: Joi.string(), + }), github: Joi.object({ - usingRepos: Joi.boolean().required(), + usingRepos: Joi.boolean(), repos: Joi.object({ - username: Joi.string().required(), - }).required(), - usingBoards: Joi.boolean().required(), + username: Joi.string(), + }), + usingBoards: Joi.boolean(), boards: Joi.object({ - nameOfBoard: Joi.string().required(), - }).required(), - }).required(), + nameOfBoard: Joi.string(), + }), + }), scaTool: Joi.object({ - nameOfTool: Joi.string().required(), + nameOfTool: Joi.string(), owaspDependencyCheck: Joi.object({ - reportPath: Joi.string().required(), + reportPath: Joi.string(), csvPath: Joi.string().optional(), }), - }).required(), + }), sastTool: Joi.object({ - nameOfTool: Joi.string().required(), + nameOfTool: Joi.string(), semgrep: Joi.object({ - reportPath: Joi.string().required(), - }).required(), - }).required(), + reportPath: Joi.string(), + }), + }), codeQualityTool: Joi.object({ - nameOfTool: Joi.string().required(), - }).required(), + nameOfTool: Joi.string(), + }), reposToExclude: Joi.object({ nameOfRepos: Joi.string().optional(), }), diff --git a/src/threatmodeling/ThreatModelingService.ts b/src/threatmodeling/ThreatModelingService.ts index 9b210e6c..d9fe3192 100644 --- a/src/threatmodeling/ThreatModelingService.ts +++ b/src/threatmodeling/ThreatModelingService.ts @@ -1,6 +1,6 @@ import * as core from '@actions/core'; export class ThreatModelingService { - public static async getStateOfThreatModeling(threatModeling: { date: string; boardsTag: string }): Promise { + public static async getStateOfThreatModeling(threatModeling: { date: string; boardsTag?: string }): Promise { if (process.env.threatModelingDate) { core.exportVariable('threatModelingDate', process.env.threatModelingDate); } else { From f30fe5ab196ff76724cc7beb0f04f6442cecc243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Bokvad=20Engar=C3=A5s?= Date: Thu, 5 Oct 2023 16:14:00 +0200 Subject: [PATCH 2/3] refactor project --- src/Pentest/PentestService.ts | 196 ++++++++++---------- src/threatmodeling/ThreatModelingService.ts | 4 +- 2 files changed, 100 insertions(+), 100 deletions(-) diff --git a/src/Pentest/PentestService.ts b/src/Pentest/PentestService.ts index 68f4534f..229bdf01 100644 --- a/src/Pentest/PentestService.ts +++ b/src/Pentest/PentestService.ts @@ -1,120 +1,120 @@ import * as core from '@actions/core'; export class PentestService { - public static async getStateOfPentest(pentest: { date: string; boardsTag?: string }): Promise { + public static async getStateOfPentest(pentest: { date: string }): Promise { if (process.env.pentestDate) { - core.exportVariable('pentestDate', process.env.pentestDate); + core.exportVariable('pentestDate', process.env.pentestDate); } else { if (!pentest.date || pentest.date === 'date-of-pentest') { core.warning('Pentest Date is not set!'); return; } - core.exportVariable('pentestDate', pentest.date); + core.exportVariable('pentestDate', pentest.date); } } } - //console.log('Pentest Date is set', pentestDate.date); +//console.log('Pentest Date is set', pentestDate.date); - // const token = core.getInput('repo-token'); - // console.log('Got the token'); +// const token = core.getInput('repo-token'); +// console.log('Got the token'); - // const octokit = github.getOctokit(token); - // console.log('octoKit authenticated'); +// const octokit = github.getOctokit(token); +// console.log('octoKit authenticated'); - // const { owner, repo } = github.context.repo; - // console.log(`Owner: ${owner}`); - // console.log(`Repo: ${repo}`); +// const { owner, repo } = github.context.repo; +// console.log(`Owner: ${owner}`); +// console.log(`Repo: ${repo}`); - // console.log('Going to get Pentest tickets from github boards'); +// console.log('Going to get Pentest tickets from github boards'); - // await octokit.rest.projects - // .createForRepo({ - // owner: owner, - // repo: repo, - // name: 'Projects Jonathan B', - // }) - // .then(async (response) => { - // console.log('Got the column for repo'); - // console.log(response.data); - // }) - // .catch((error) => { - // core.warning('Error getting column!'); - // console.log('Error: ', error); - // }); - // await octokit.rest.projects - // .listForOrg({ - // org: owner, - // }) - // .then(async (response) => { - // console.log('Got the projects for org'); - // console.log(response.data); - // }) - // .catch((error) => { - // core.warning('Error getting projects for org!'); - // console.log('Error: ', error); - // }); +// await octokit.rest.projects +// .createForRepo({ +// owner: owner, +// repo: repo, +// name: 'Projects Jonathan B', +// }) +// .then(async (response) => { +// console.log('Got the column for repo'); +// console.log(response.data); +// }) +// .catch((error) => { +// core.warning('Error getting column!'); +// console.log('Error: ', error); +// }); +// await octokit.rest.projects +// .listForOrg({ +// org: owner, +// }) +// .then(async (response) => { +// console.log('Got the projects for org'); +// console.log(response.data); +// }) +// .catch((error) => { +// core.warning('Error getting projects for org!'); +// console.log('Error: ', error); +// }); - // const customLabelIssues = await octokit.rest.issues - // .listForRepo({ - // owner: owner, - // repo: repo, - // }) - // .then(async (response) => { - // const issues = response.data; - // console.log('Got the issues'); - // console.log('Number of issues: ', issues.length); - // const customLabelIssues = issues.filter((issue) => { - // console.log('issue', issue.title); - // return issue.labels.some((label: any) => label.name === pentestDate.boardsTag); - // }); - // console.log('customLabelIssues', customLabelIssues.length); - // return customLabelIssues; - // }) - // .catch((error) => { - // core.warning('Error getting project for repo!'); - // console.log('Error: ', error); - // }); +// const customLabelIssues = await octokit.rest.issues +// .listForRepo({ +// owner: owner, +// repo: repo, +// }) +// .then(async (response) => { +// const issues = response.data; +// console.log('Got the issues'); +// console.log('Number of issues: ', issues.length); +// const customLabelIssues = issues.filter((issue) => { +// console.log('issue', issue.title); +// return issue.labels.some((label: any) => label.name === pentestDate.boardsTag); +// }); +// console.log('customLabelIssues', customLabelIssues.length); +// return customLabelIssues; +// }) +// .catch((error) => { +// core.warning('Error getting project for repo!'); +// console.log('Error: ', error); +// }); - // await octokit.rest.projects - // .listCards({ - // owner: owner, - // repo: repo, - // column_id: 24, - // }) - // .then(async (response) => { - // console.log('Got the cards'); - // const projectCards = response.data; - // // const customLabelCards = projectCards.filter((card) => { - // // return card.note?.includes(pentestDate.boardsTag); - // // }); +// await octokit.rest.projects +// .listCards({ +// owner: owner, +// repo: repo, +// column_id: 24, +// }) +// .then(async (response) => { +// console.log('Got the cards'); +// const projectCards = response.data; +// // const customLabelCards = projectCards.filter((card) => { +// // return card.note?.includes(pentestDate.boardsTag); +// // }); - // const customLabelCards = []; - // console.log('projectCards', projectCards); - // for (const card of projectCards) { - // // Get the associated issue or pull request for the card - // console.log('card', card); - // const contentResponse = await octokit.request(card.content_url); - // console.log('contentResponse', contentResponse); - // if (contentResponse.data.labels.some((label: any) => label.name === pentestDate.boardsTag)) { - // customLabelCards.push(card); - // } - // } +// const customLabelCards = []; +// console.log('projectCards', projectCards); +// for (const card of projectCards) { +// // Get the associated issue or pull request for the card +// console.log('card', card); +// const contentResponse = await octokit.request(card.content_url); +// console.log('contentResponse', contentResponse); +// if (contentResponse.data.labels.some((label: any) => label.name === pentestDate.boardsTag)) { +// customLabelCards.push(card); +// } +// } - // console.log('customLabelCards', customLabelCards); - // return customLabelCards; - // }) - // .catch((error) => { - // core.warning('Error getting cards!'); - // console.log('Error: ', error); - // }); +// console.log('customLabelCards', customLabelCards); +// return customLabelCards; +// }) +// .catch((error) => { +// core.warning('Error getting cards!'); +// console.log('Error: ', error); +// }); - // owner: owner, - // repo: repo, - // branch: 'main', - // }).then((response) => { - // console.log("Got the branch protection"); - // console.log(response.data); - // }).catch((error) => { - // core.warning("Error getting branch protection!"); - // core.warning("Error: ", error.message); - // }); +// owner: owner, +// repo: repo, +// branch: 'main', +// }).then((response) => { +// console.log("Got the branch protection"); +// console.log(response.data); +// }).catch((error) => { +// core.warning("Error getting branch protection!"); +// core.warning("Error: ", error.message); +// }); diff --git a/src/threatmodeling/ThreatModelingService.ts b/src/threatmodeling/ThreatModelingService.ts index d9fe3192..5278c85c 100644 --- a/src/threatmodeling/ThreatModelingService.ts +++ b/src/threatmodeling/ThreatModelingService.ts @@ -2,13 +2,13 @@ import * as core from '@actions/core'; export class ThreatModelingService { public static async getStateOfThreatModeling(threatModeling: { date: string; boardsTag?: string }): Promise { if (process.env.threatModelingDate) { - core.exportVariable('threatModelingDate', process.env.threatModelingDate); + core.exportVariable('threatModelingDate', process.env.threatModelingDate); } else { if (!threatModeling.date || threatModeling.date === 'date-of-threat-modeling') { core.warning('Threat Modeling Date is not set!'); return; } - core.exportVariable('threatModelingDate', threatModeling.date); + core.exportVariable('threatModelingDate', threatModeling.date); } } } From 3146e9e8ea6c653fbe56ed44254aba3a6266a5da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Bokvad=20Engar=C3=A5s?= Date: Thu, 5 Oct 2023 16:14:56 +0200 Subject: [PATCH 3/3] refactor project --- src/Pentest/PentestService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pentest/PentestService.ts b/src/Pentest/PentestService.ts index 229bdf01..cec71ab2 100644 --- a/src/Pentest/PentestService.ts +++ b/src/Pentest/PentestService.ts @@ -1,7 +1,7 @@ import * as core from '@actions/core'; export class PentestService { - public static async getStateOfPentest(pentest: { date: string }): Promise { + public static async getStateOfPentest(pentest: { date: string; boardsTag?: string }): Promise { if (process.env.pentestDate) { core.exportVariable('pentestDate', process.env.pentestDate); } else {