Skip to content

Commit

Permalink
Merge pull request #27 from Omegapoint/feature/tm-pm-tickets
Browse files Browse the repository at this point in the history
TM and PT tickets cannot be set if they are empty strings.
  • Loading branch information
jonathanbokvad authored Oct 5, 2023
2 parents f11bc5b + 524ec56 commit 7e91fcd
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 102 deletions.
68 changes: 34 additions & 34 deletions src/lib/BodyBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = process.env.tmNumberOfActiveTickets || '';
const tmNumberOfClosedTickets: string = process.env.tmNumberOfClosedTickets || '';
const tmNumberOfActiveTickets: string | undefined = process.env?.tmNumberOfActiveTickets
const tmNumberOfClosedTickets: string | undefined = process.env?.tmNumberOfClosedTickets;

const ptNumberOfActiveTickets: string = process.env.ptNumberOfActiveTickets || '';
const ptNumberOfClosedTickets: string = process.env.ptNumberOfClosedTickets || '';
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()
Expand Down
104 changes: 49 additions & 55 deletions src/lib/ResponseBodyBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ export class ResponseBodyBuilder {
}

setThreatModelingDate(
threatModelingDate: string,
tmNumberOfActiveTickets: string,
tmNumberOfClosedTickets: string
threatModelingDate: string | undefined,
tmNumberOfActiveTickets: string | undefined,
tmNumberOfClosedTickets: string | undefined
): this {
if (!threatModelingDate) {
return this;
} else {
if (!tmNumberOfActiveTickets && !tmNumberOfClosedTickets) {
if (tmNumberOfActiveTickets && tmNumberOfClosedTickets) {
this.responseBody.tmNumberOfActiveTickets = tmNumberOfActiveTickets;
this.responseBody.tmNumberOfClosedTickets = tmNumberOfClosedTickets;
}
Expand All @@ -61,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;
Expand All @@ -78,19 +78,19 @@ 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;
} else if (scaTool === 'not specified') {
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;
Expand All @@ -103,7 +103,7 @@ export class ResponseBodyBuilder {
}
}

setSecureScore(secureScore: string): this {
setSecureScore(secureScore: string | undefined): this {
if (!secureScore) {
return this;
} else {
Expand All @@ -113,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;
Expand All @@ -131,11 +131,11 @@ export class ResponseBodyBuilder {
}
}

setPentestDate(pentestDate: string, ptNumberOfActiveTickets: string, ptNumberOfClosedTickets: string): this {
setPentestDate(pentestDate: string | undefined, ptNumberOfActiveTickets: string | undefined, ptNumberOfClosedTickets: string | undefined): this {
if (!pentestDate) {
return this;
} else {
if (!ptNumberOfActiveTickets && !ptNumberOfClosedTickets) {
if (ptNumberOfActiveTickets && ptNumberOfClosedTickets) {
this.responseBody.ptNumberOfActiveTickets = ptNumberOfActiveTickets;
this.responseBody.ptNumberOfClosedTickets = ptNumberOfClosedTickets;
}
Expand All @@ -144,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;
Expand All @@ -192,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;
Expand All @@ -212,18 +206,18 @@ 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;
} else if (sastTool === 'not specified') {
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;
Expand Down
26 changes: 13 additions & 13 deletions src/lib/UrlBodyBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -16,7 +16,7 @@ export class UrlBodyBuilder {
}
}

setNumberOfReviewers(numberOfReviewers: string): this {
setNumberOfReviewers(numberOfReviewers: string | undefined): this {
if (!numberOfReviewers) {
return this;
} else {
Expand All @@ -25,7 +25,7 @@ export class UrlBodyBuilder {
}
}

setScaTool(scaTool: string): this {
setScaTool(scaTool: string | undefined): this {
if (!scaTool) {
return this;
} else {
Expand All @@ -34,7 +34,7 @@ export class UrlBodyBuilder {
}
}

setSastTool(sastTool: string): this {
setSastTool(sastTool: string | undefined): this {
if (!sastTool) {
return this;
} else {
Expand All @@ -43,7 +43,7 @@ export class UrlBodyBuilder {
}
}

setSecureScore(secureScore: string): this {
setSecureScore(secureScore: string | undefined): this {
if (!secureScore) {
return this;
} else {
Expand All @@ -52,7 +52,7 @@ export class UrlBodyBuilder {
}
}

setAllowedLocationPolicy(allowedLocationPolicy: string): this {
setAllowedLocationPolicy(allowedLocationPolicy: string | undefined): this {
if (!allowedLocationPolicy) {
return this;
} else {
Expand All @@ -61,7 +61,7 @@ export class UrlBodyBuilder {
}
}

setPentestDate(pentestDate: string): this {
setPentestDate(pentestDate: string | undefined): this {
if (!pentestDate) {
return this;
} else {
Expand All @@ -70,7 +70,7 @@ export class UrlBodyBuilder {
}
}

setNumberOfDeployedVMs(numberOfDeployedVMs: string): this {
setNumberOfDeployedVMs(numberOfDeployedVMs: string | undefined): this {
if (!numberOfDeployedVMs) {
return this;
} else {
Expand All @@ -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;
Expand All @@ -92,7 +92,7 @@ export class UrlBodyBuilder {
}
}

setNumberOfExposedSecrets(numberOfExposedSecrets: string): this {
setNumberOfExposedSecrets(numberOfExposedSecrets: string | undefined): this {
if (!numberOfExposedSecrets) {
return this;
} else {
Expand All @@ -101,7 +101,7 @@ export class UrlBodyBuilder {
}
}

setCodeQualityTool(codeQualityTool: string): this {
setCodeQualityTool(codeQualityTool: string | undefined): this {
if (!codeQualityTool) {
return this;
} else {
Expand Down

0 comments on commit 7e91fcd

Please sign in to comment.