Skip to content

Commit

Permalink
feature/cb2-12310: Update linting (#182)
Browse files Browse the repository at this point in the history
* Standardise linting to biome

* resolved snyk vulnerabilities
  • Loading branch information
me-matt authored Sep 26, 2024
1 parent 2ac2b7d commit 9e5c900
Show file tree
Hide file tree
Showing 22 changed files with 2,149 additions and 2,250 deletions.
25 changes: 25 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": ["@dvsa/biome-config/biome"],
"linter": {
"rules": {
"suspicious": {
"noExplicitAny": "off"
},
"complexity": {
"noForEach": "off",
"noUselessCatch": "off",
"noThisInStatic": "off"
},
"correctness": {
"noSwitchDeclarations": "off"
},
"style": {
"noUnusedTemplateLiteral": "off",
"noNonNullAssertion": "off",
"noUselessElse": "off",
"useTemplate": "off",
"useNodejsImportProtocol": "off"
}
}
}
}
59 changes: 55 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"test:unit": "BRANCH=local AWS_XRAY_CONTEXT_MISSING=LOG_ERROR jest --testMatch=\"**/*.unitTest.ts\" --runInBand",
"test": "npm run test:unit -- --coveragePathIgnorePatterns='<rootDir>/tests/' --coverage",
"test-i": "BRANCH=local jest --testMatch=\"**/*.intTest.ts\" --runInBand",
"lint": "tslint src/**/*.ts tests/**/*.ts -q",
"lint-fix": "tslint src/**/*.ts tests/**/*.ts -q --fix",
"lint": "biome check src",
"lint:fix": "npm run lint -- --write",
"security-checks": "git secrets --scan",
"prepush": "npm run test && npm run build && npm run test-i",
"sonar-scanner": "npm run test && sonar-scanner",
Expand Down Expand Up @@ -50,10 +50,10 @@
"license": "ISC",
"dependencies": {
"@aws-lambda-powertools/parameters": "^2.0.2",
"@aws-sdk/client-appconfigdata": "^3.525.0",
"@aws-sdk/client-lambda": "^3.548.0",
"@aws-sdk/client-s3": "^3.540.0",
"@aws-sdk/client-secrets-manager": "^3.543.0",
"@aws-sdk/client-appconfigdata": "^3.564.0",
"@aws-sdk/client-lambda": "^3.564.0",
"@aws-sdk/client-s3": "^3.564.0",
"@aws-sdk/client-secrets-manager": "^3.564.0",
"@dvsa/cvs-feature-flags": "^0.13.0",
"@dvsa/cvs-type-definitions": "^2.1.11",
"@smithy/types": "^2.12.0",
Expand All @@ -67,8 +67,10 @@
"ts-node-register": "^1.0.0"
},
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@commitlint/cli": "^19.2.1",
"@commitlint/config-conventional": "^19.1.0",
"@dvsa/biome-config": "^0.1.0",
"@types/aws-lambda": "^8.10.34",
"@types/jest": "^28.1.8",
"@types/jest-plugin-context": "^2.9.2",
Expand Down Expand Up @@ -106,4 +108,4 @@
"pre-push": "npm run prepush"
}
}
}
}
102 changes: 43 additions & 59 deletions src/functions/certGen.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { DeleteObjectCommandOutput, PutObjectCommandOutput } from "@aws-sdk/client-s3";
import { Callback, Context, Handler, SQSEvent, SQSRecord } from "aws-lambda";
import { ERRORS } from "../models/Enums";
import { Injector } from "../models/injector/Injector";
import {
CertificateGenerationService,
IGeneratedCertificateResponse,
} from "../services/CertificateGenerationService";
import { CertificateUploadService } from "../services/CertificateUploadService";
import { DeleteObjectCommandOutput, PutObjectCommandOutput } from '@aws-sdk/client-s3';
import { Callback, Context, Handler, SQSEvent, SQSRecord } from 'aws-lambda';
import { ERRORS } from '../models/Enums';
import { Injector } from '../models/injector/Injector';
import { CertificateGenerationService, IGeneratedCertificateResponse } from '../services/CertificateGenerationService';
import { CertificateUploadService } from '../services/CertificateUploadService';

type CertGenReturn = PutObjectCommandOutput | DeleteObjectCommandOutput;

Expand All @@ -16,60 +13,47 @@ type CertGenReturn = PutObjectCommandOutput | DeleteObjectCommandOutput;
* @param context - λ Context
* @param callback - callback function
*/
const certGen: Handler = async (
event: SQSEvent,
context?: Context,
callback?: Callback
): Promise<CertGenReturn[]> => {
if (
!event ||
!event.Records ||
!Array.isArray(event.Records) ||
!event.Records.length
) {
console.error("ERROR: event is not defined.");
throw new Error("Event is empty");
}
const certGen: Handler = async (event: SQSEvent, context?: Context, callback?: Callback): Promise<CertGenReturn[]> => {
if (!event || !event.Records || !Array.isArray(event.Records) || !event.Records.length) {
console.error('ERROR: event is not defined.');
throw new Error('Event is empty');
}

const certificateGenerationService: CertificateGenerationService =
Injector.resolve<CertificateGenerationService>(
CertificateGenerationService
);
const certificateUploadService: CertificateUploadService =
Injector.resolve<CertificateUploadService>(CertificateUploadService);
const certificateUploadPromises: Array<Promise<CertGenReturn>> = [];
const certificateGenerationService: CertificateGenerationService =
Injector.resolve<CertificateGenerationService>(CertificateGenerationService);
const certificateUploadService: CertificateUploadService =
Injector.resolve<CertificateUploadService>(CertificateUploadService);
const certificateUploadPromises: Array<Promise<CertGenReturn>> = [];

event.Records.forEach((record: SQSRecord) => {
const testResult: any = JSON.parse(record.body);
console.log(`parsed test result is ${testResult.testResultId} with the system number ${testResult.systemNumber}`);
if (testResult.testStatus === "cancelled") {
const s3DeletePromise =
certificateUploadService.removeCertificate(testResult);
certificateUploadPromises.push(s3DeletePromise);
} else if (
testResult.testResultId.match(
"\\b[a-zA-Z0-9]{8}\\b-\\b[a-zA-Z0-9]{4}\\b-\\b[a-zA-Z0-9]{4}\\b-\\b[a-zA-Z0-9]{4}\\b-\\b[a-zA-Z0-9]{12}\\b"
)
) {
// Check for retroError flag for a testResult and cvsTestUpdated for the test-type and do not generate certificates if set to true
const generatedCertificateResponse: Promise<PutObjectCommandOutput> =
certificateGenerationService
.generateCertificate(testResult)
.then((response: IGeneratedCertificateResponse) => {
return certificateUploadService.uploadCertificate(response);
});
event.Records.forEach((record: SQSRecord) => {
const testResult: any = JSON.parse(record.body);
console.log(`parsed test result is ${testResult.testResultId} with the system number ${testResult.systemNumber}`);
if (testResult.testStatus === 'cancelled') {
const s3DeletePromise = certificateUploadService.removeCertificate(testResult);
certificateUploadPromises.push(s3DeletePromise);
} else if (
testResult.testResultId.match(
'\\b[a-zA-Z0-9]{8}\\b-\\b[a-zA-Z0-9]{4}\\b-\\b[a-zA-Z0-9]{4}\\b-\\b[a-zA-Z0-9]{4}\\b-\\b[a-zA-Z0-9]{12}\\b'
)
) {
// Check for retroError flag for a testResult and cvsTestUpdated for the test-type and do not generate certificates if set to true
const generatedCertificateResponse: Promise<PutObjectCommandOutput> = certificateGenerationService
.generateCertificate(testResult)
.then((response: IGeneratedCertificateResponse) => {
return certificateUploadService.uploadCertificate(response);
});

certificateUploadPromises.push(generatedCertificateResponse);
} else {
console.error(`${ERRORS.TESTRESULT_ID}`, testResult.testResultId);
throw new Error("Bad Test Record: " + testResult.testResultId);
}
});
certificateUploadPromises.push(generatedCertificateResponse);
} else {
console.error(`${ERRORS.TESTRESULT_ID}`, testResult.testResultId);
throw new Error('Bad Test Record: ' + testResult.testResultId);
}
});

return Promise.all(certificateUploadPromises).catch((error: Error) => {
console.error(error);
throw error;
});
return Promise.all(certificateUploadPromises).catch((error: Error) => {
console.error(error);
throw error;
});
};

export { certGen };
13 changes: 6 additions & 7 deletions src/handler.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { certGen } from "./functions/certGen";
import { certGen } from './functions/certGen';

const isOffline: boolean =
!process.env.BRANCH || process.env.BRANCH === "local";
const isOffline: boolean = !process.env.BRANCH || process.env.BRANCH === 'local';

let credentials = {};

if (isOffline) {
credentials = {
accessKeyId: "accessKey1",
secretAccessKey: "verySecretKey1",
};
credentials = {
accessKeyId: 'accessKey1',
secretAccessKey: 'verySecretKey1',
};
}

export { credentials };
Expand Down
Loading

0 comments on commit 9e5c900

Please sign in to comment.