From 524ec56dbeb15e59088de2e3b0ee058ea03383e0 Mon Sep 17 00:00:00 2001 From: Johanna Ahlskog Date: Thu, 5 Oct 2023 14:07:32 +0200 Subject: [PATCH] changes in pr (again) --- src/lib/BodyBuilder.ts | 68 ++++++++++----------- src/lib/ResponseBodyBuilder.ts | 104 +++++++++++++++------------------ src/lib/UrlBodyBuilder.ts | 26 ++++----- 3 files changed, 94 insertions(+), 104 deletions(-) diff --git a/src/lib/BodyBuilder.ts b/src/lib/BodyBuilder.ts index 414fd5aa..0c1d35ef 100644 --- a/src/lib/BodyBuilder.ts +++ b/src/lib/BodyBuilder.ts @@ -8,48 +8,48 @@ let urls: string = ''; export class BodyBuilder { createBody(teamName: string, codeRepositoryName: string, subscriptionId: string): ResponseBody { - const teamProjectName: string = teamName || ''; - const allowedLocationPolicy: string = process.env.allowedLocationPolicy || ''; - const secureScore: string = process.env.secureScore || ''; - const numberOfDeployedVMs: string = process.env.numberOfDeployedVMs || ''; + const teamProjectName: string = teamName; + const allowedLocationPolicy: string | undefined = process.env?.allowedLocationPolicy; + const secureScore: string | undefined = process.env?.secureScore; + const numberOfDeployedVMs: string | undefined = process.env?.numberOfDeployedVMs; - const threatModelingDate: string = process.env.threatModelingDate || ''; - const scaTool: string = process.env.scaTool || ''; - const sastTool: string = process.env.sastTool || ''; - const pentestDate: string = process.env.pentestDate || ''; - const codeQualityTool: string = process.env.codeQualityTool || ''; - const numberOfExposedSecrets: string = process.env.numberOfExposedSecrets || ''; - const numberOfReviewers: string = process.env.numberOfReviewers || ''; - const branchPolicyUpdateDate: string = process.env.branchPolicyUpdateDate || ''; - const branchPolicyUpdateEmail: string = process.env.branchPolicyUpdateEmail || ''; + const threatModelingDate: string | undefined = process.env?.threatModelingDate; + const scaTool: string | undefined = process.env?.scaTool; + const sastTool: string | undefined = process.env?.sastTool; + const pentestDate: string | undefined = process.env?.pentestDate; + const codeQualityTool: string | undefined = process.env?.codeQualityTool; + const numberOfExposedSecrets: string | undefined = process.env?.numberOfExposedSecrets; + const numberOfReviewers: string | undefined = process.env?.numberOfReviewers; + const branchPolicyUpdateDate: string | undefined = process.env?.branchPolicyUpdateDate; + const branchPolicyUpdateEmail: string | undefined = process.env?.branchPolicyUpdateEmail; - const compliantResources: string = process.env.compliantResources || ''; - const nonCompliantResources: string = process.env.nonCompliantResources || ''; + const compliantResources: string | undefined = process.env?.compliantResources; + const nonCompliantResources: string | undefined = process.env?.nonCompliantResources; - const scaNumberOfSeverity1: string = process.env.SCAnumberOfSeverity1 || ''; - const scaNumberOfSeverity2: string = process.env.SCAnumberOfSeverity2 || ''; - const scaNumberOfSeverity3: string = process.env.SCAnumberOfSeverity3 || ''; - const scaNumberOfSeverity4: string = process.env.SCAnumberOfSeverity4 || ''; + const scaNumberOfSeverity1: string | undefined = process.env?.SCAnumberOfSeverity1; + const scaNumberOfSeverity2: string | undefined = process.env?.SCAnumberOfSeverity2; + const scaNumberOfSeverity3: string | undefined = process.env?.SCAnumberOfSeverity3; + const scaNumberOfSeverity4: string | undefined = process.env?.SCAnumberOfSeverity4; - const cqNumberOfSeverity1: string = process.env.CQnumberOfSeverity1 || ''; - const cqNumberOfSeverity2: string = process.env.CQnumberOfSeverity2 || ''; - const cqNumberOfSeverity3: string = process.env.CQnumberOfSeverity3 || ''; - const cqNumberOfSeverity4: string = process.env.CQnumberOfSeverity4 || ''; - const cqNumberOfSeverity5: string = process.env.CQnumberOfSeverity5 || ''; + const cqNumberOfSeverity1: string | undefined = process.env?.CQnumberOfSeverity1; + const cqNumberOfSeverity2: string | undefined = process.env?.CQnumberOfSeverity2; + const cqNumberOfSeverity3: string | undefined = process.env?.CQnumberOfSeverity3; + const cqNumberOfSeverity4: string| undefined = process.env?.CQnumberOfSeverity4; + const cqNumberOfSeverity5: string | undefined = process.env?.CQnumberOfSeverity5; - const sastNumberOfSeverity1: string = process.env.SASTnumberOfSeverity1 || ''; - const sastNumberOfSeverity2: string = process.env.SASTnumberOfSeverity2 || ''; - const sastNumberOfSeverity3: string = process.env.SASTnumberOfSeverity3 || ''; + const sastNumberOfSeverity1: string | undefined = process.env?.SASTnumberOfSeverity1; + const sastNumberOfSeverity2: string | undefined = process.env.SASTnumberOfSeverity2; + const sastNumberOfSeverity3: string | undefined = process.env?.SASTnumberOfSeverity3; - const tmNumberOfActiveTickets: string | undefined = process.env.tmNumberOfActiveTickets || undefined; - const tmNumberOfClosedTickets: string | undefined = process.env.tmNumberOfClosedTickets || undefined; + const tmNumberOfActiveTickets: string | undefined = process.env?.tmNumberOfActiveTickets + const tmNumberOfClosedTickets: string | undefined = process.env?.tmNumberOfClosedTickets; - const ptNumberOfActiveTickets: string | undefined = process.env.ptNumberOfActiveTickets || undefined; - const ptNumberOfClosedTickets: string | undefined = process.env.ptNumberOfClosedTickets || undefined; + const ptNumberOfActiveTickets: string | undefined = process.env?.ptNumberOfActiveTickets; + const ptNumberOfClosedTickets: string | undefined = process.env?.ptNumberOfClosedTickets; - const numUserInProdSeverity1: string = process.env.numUserInProdSeverity1 || ''; - const numUserInProdSeverity2: string = process.env.numUserInProdSeverity2 || ''; - const numUserInProdSeverity3: string = process.env.numUserInProdSeverity3 || ''; + const numUserInProdSeverity1: string | undefined = process.env.numUserInProdSeverity1; + const numUserInProdSeverity2: string | undefined = process.env.numUserInProdSeverity2; + const numUserInProdSeverity3: string | undefined = process.env.numUserInProdSeverity3; //For printing urls in the pipeline const urlBody: UrlBody = new UrlBodyBuilder() diff --git a/src/lib/ResponseBodyBuilder.ts b/src/lib/ResponseBodyBuilder.ts index 3b6b3117..2a169750 100644 --- a/src/lib/ResponseBodyBuilder.ts +++ b/src/lib/ResponseBodyBuilder.ts @@ -44,17 +44,15 @@ export class ResponseBodyBuilder { } setThreatModelingDate( - threatModelingDate: string, + threatModelingDate: string | undefined, tmNumberOfActiveTickets: string | undefined, tmNumberOfClosedTickets: string | undefined ): this { if (!threatModelingDate) { return this; } else { - if (tmNumberOfActiveTickets !== undefined) { + if (tmNumberOfActiveTickets && tmNumberOfClosedTickets) { this.responseBody.tmNumberOfActiveTickets = tmNumberOfActiveTickets; - } - if (tmNumberOfClosedTickets !== undefined) { this.responseBody.tmNumberOfClosedTickets = tmNumberOfClosedTickets; } this.responseBody.threatModelingDate = threatModelingDate; @@ -63,9 +61,9 @@ export class ResponseBodyBuilder { } setNumberOfReviewers( - numberOfReviewers: string, - branchPolicyUpdateDate: string, - branchPolicyUpdateEmail: string + numberOfReviewers: string | undefined, + branchPolicyUpdateDate: string | undefined, + branchPolicyUpdateEmail: string | undefined ): this { if (!numberOfReviewers) { return this; @@ -80,11 +78,11 @@ export class ResponseBodyBuilder { } setScaTool( - scaTool: string, - scaNumberOfSeverity1: string, - scaNumberOfSeverity2: string, - scaNumberOfSeverity3: string, - scaNumberOfSeverity4: string + scaTool: string | undefined, + scaNumberOfSeverity1: string | undefined, + scaNumberOfSeverity2: string | undefined, + scaNumberOfSeverity3: string | undefined, + scaNumberOfSeverity4: string | undefined ): this { if (!scaTool) { return this; @@ -92,7 +90,7 @@ export class ResponseBodyBuilder { this.responseBody.scaTool = scaTool; return this; } else { - if (!scaNumberOfSeverity1 && !scaNumberOfSeverity2 && !scaNumberOfSeverity3 && !scaNumberOfSeverity4) { + if (scaNumberOfSeverity1 && scaNumberOfSeverity2 && scaNumberOfSeverity3 && scaNumberOfSeverity4) { this.responseBody.scaTool = scaTool; this.responseBody.scaNumberOfSeverity1 = scaNumberOfSeverity1; this.responseBody.scaNumberOfSeverity2 = scaNumberOfSeverity2; @@ -105,7 +103,7 @@ export class ResponseBodyBuilder { } } - setSecureScore(secureScore: string): this { + setSecureScore(secureScore: string | undefined): this { if (!secureScore) { return this; } else { @@ -115,14 +113,14 @@ export class ResponseBodyBuilder { } setAllowedLocationPolicy( - allowedLocationPolicy: string, - compliantResources: string, - nonCompliantResources: string + allowedLocationPolicy: string | undefined, + compliantResources: string | undefined, + nonCompliantResources: string | undefined ): this { if (!allowedLocationPolicy) { return this; } else { - if (compliantResources !== undefined && nonCompliantResources !== undefined) { + if (compliantResources && nonCompliantResources) { this.responseBody.allowedLocationPolicy = allowedLocationPolicy; this.responseBody.compliantResources = compliantResources; this.responseBody.nonCompliantResources = nonCompliantResources; @@ -133,14 +131,12 @@ export class ResponseBodyBuilder { } } - setPentestDate(pentestDate: string, ptNumberOfActiveTickets: string | undefined, ptNumberOfClosedTickets: string | undefined): this { + setPentestDate(pentestDate: string | undefined, ptNumberOfActiveTickets: string | undefined, ptNumberOfClosedTickets: string | undefined): this { if (!pentestDate) { return this; } else { - if (ptNumberOfActiveTickets !== undefined) { + if (ptNumberOfActiveTickets && ptNumberOfClosedTickets) { this.responseBody.ptNumberOfActiveTickets = ptNumberOfActiveTickets; - } - if (ptNumberOfClosedTickets !== undefined) { this.responseBody.ptNumberOfClosedTickets = ptNumberOfClosedTickets; } this.responseBody.pentestDate = pentestDate; @@ -148,46 +144,40 @@ export class ResponseBodyBuilder { } } - setNumberOfDeployedVMs(numberOfDeployedVMs: string): this { - if (!numberOfDeployedVMs) { - return this; - } else { + setNumberOfDeployedVMs(numberOfDeployedVMs: string | undefined): this { + if (numberOfDeployedVMs) { this.responseBody.numberOfDeployedVMs = numberOfDeployedVMs; - return this; } + return this; } setNumberOfHumansInSubscription( - numUserInProdSeverity1: string, - numUserInProdSeverity2: string, - numUserInProdSeverity3: string + numUserInProdSeverity1: string | undefined, + numUserInProdSeverity2: string | undefined, + numUserInProdSeverity3: string | undefined ): this { - if (!numUserInProdSeverity1 || !numUserInProdSeverity2 || !numUserInProdSeverity3) { - return this; - } else { + if (numUserInProdSeverity1 && numUserInProdSeverity2 && numUserInProdSeverity3) { this.responseBody.numUserInProdSeverity1 = numUserInProdSeverity1; this.responseBody.numUserInProdSeverity2 = numUserInProdSeverity2; this.responseBody.numUserInProdSeverity3 = numUserInProdSeverity3; - return this; - } + } + return this; } - setNumberOfExposedSecrets(numberOfExposedSecrets: string): this { - if (!numberOfExposedSecrets) { - return this; - } else { + setNumberOfExposedSecrets(numberOfExposedSecrets: string | undefined): this { + if (numberOfExposedSecrets) { this.responseBody.numberOfExposedSecrets = numberOfExposedSecrets; - return this; - } + } + return this; } setCodeQualityTool( - codeQualityTool: string, - cqNumberOfSeverity1: string, - cqNumberOfSeverity2: string, - cqNumberOfSeverity3: string, - cqNumberOfSeverity4: string, - cqNumberOfSeverity5: string + codeQualityTool: string | undefined, + cqNumberOfSeverity1: string | undefined, + cqNumberOfSeverity2: string | undefined, + cqNumberOfSeverity3: string | undefined, + cqNumberOfSeverity4: string | undefined, + cqNumberOfSeverity5: string | undefined ): this { if (!codeQualityTool) { return this; @@ -196,11 +186,11 @@ export class ResponseBodyBuilder { return this; } else { if ( - !cqNumberOfSeverity1 && - !cqNumberOfSeverity2 && - !cqNumberOfSeverity3 && - !cqNumberOfSeverity4 && - !cqNumberOfSeverity5 + cqNumberOfSeverity1 && + cqNumberOfSeverity2 && + cqNumberOfSeverity3 && + cqNumberOfSeverity4 && + cqNumberOfSeverity5 ) { this.responseBody.codeQualityTool = codeQualityTool; this.responseBody.cqNumberOfSeverity1 = cqNumberOfSeverity1; @@ -216,10 +206,10 @@ export class ResponseBodyBuilder { } setSastTool( - sastTool: string, - sastNumberOfSeverity1: string, - sastNumberOfSeverity2: string, - sastNumberOfSeverity3: string + sastTool: string | undefined, + sastNumberOfSeverity1: string | undefined, + sastNumberOfSeverity2: string | undefined, + sastNumberOfSeverity3: string | undefined ): this { if (!sastTool) { return this; @@ -227,7 +217,7 @@ export class ResponseBodyBuilder { this.responseBody.sastTool = sastTool; return this; } else { - if (!sastNumberOfSeverity3 && !sastNumberOfSeverity2 && !sastNumberOfSeverity1) { + if (sastNumberOfSeverity3 && sastNumberOfSeverity2 && sastNumberOfSeverity1) { this.responseBody.sastTool = sastTool; this.responseBody.sastNumberOfSeverity3 = sastNumberOfSeverity3; this.responseBody.sastNumberOfSeverity2 = sastNumberOfSeverity2; diff --git a/src/lib/UrlBodyBuilder.ts b/src/lib/UrlBodyBuilder.ts index 0f2e8c3f..edaf074b 100644 --- a/src/lib/UrlBodyBuilder.ts +++ b/src/lib/UrlBodyBuilder.ts @@ -7,7 +7,7 @@ export class UrlBodyBuilder { this.url = new UrlBody(); } - setThreatModelingDate(threatModelingDate: string): this { + setThreatModelingDate(threatModelingDate: string | undefined ): this { if (!threatModelingDate) { return this; } else { @@ -16,7 +16,7 @@ export class UrlBodyBuilder { } } - setNumberOfReviewers(numberOfReviewers: string): this { + setNumberOfReviewers(numberOfReviewers: string | undefined): this { if (!numberOfReviewers) { return this; } else { @@ -25,7 +25,7 @@ export class UrlBodyBuilder { } } - setScaTool(scaTool: string): this { + setScaTool(scaTool: string | undefined): this { if (!scaTool) { return this; } else { @@ -34,7 +34,7 @@ export class UrlBodyBuilder { } } - setSastTool(sastTool: string): this { + setSastTool(sastTool: string | undefined): this { if (!sastTool) { return this; } else { @@ -43,7 +43,7 @@ export class UrlBodyBuilder { } } - setSecureScore(secureScore: string): this { + setSecureScore(secureScore: string | undefined): this { if (!secureScore) { return this; } else { @@ -52,7 +52,7 @@ export class UrlBodyBuilder { } } - setAllowedLocationPolicy(allowedLocationPolicy: string): this { + setAllowedLocationPolicy(allowedLocationPolicy: string | undefined): this { if (!allowedLocationPolicy) { return this; } else { @@ -61,7 +61,7 @@ export class UrlBodyBuilder { } } - setPentestDate(pentestDate: string): this { + setPentestDate(pentestDate: string | undefined): this { if (!pentestDate) { return this; } else { @@ -70,7 +70,7 @@ export class UrlBodyBuilder { } } - setNumberOfDeployedVMs(numberOfDeployedVMs: string): this { + setNumberOfDeployedVMs(numberOfDeployedVMs: string | undefined): this { if (!numberOfDeployedVMs) { return this; } else { @@ -80,9 +80,9 @@ export class UrlBodyBuilder { } setNumberOfHumansInSubscription( - numUserInProdSeverity1: string, - numUserInProdSeverity2: string, - numUserInProdSeverity3: string + numUserInProdSeverity1: string | undefined, + numUserInProdSeverity2: string | undefined, + numUserInProdSeverity3: string | undefined ): this { if (!numUserInProdSeverity1 || !numUserInProdSeverity2 || !numUserInProdSeverity3) { return this; @@ -92,7 +92,7 @@ export class UrlBodyBuilder { } } - setNumberOfExposedSecrets(numberOfExposedSecrets: string): this { + setNumberOfExposedSecrets(numberOfExposedSecrets: string | undefined): this { if (!numberOfExposedSecrets) { return this; } else { @@ -101,7 +101,7 @@ export class UrlBodyBuilder { } } - setCodeQualityTool(codeQualityTool: string): this { + setCodeQualityTool(codeQualityTool: string | undefined): this { if (!codeQualityTool) { return this; } else {