Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
chore: lint code and update dependencies (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsmayda authored Oct 11, 2021
1 parent 3c4c57e commit c9a2c78
Show file tree
Hide file tree
Showing 17 changed files with 3,262 additions and 2,976 deletions.
9 changes: 5 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -7,7 +7,7 @@ module.exports = {
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
extends: [
'airbnb-base',
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'prettier', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
plugins: ['@typescript-eslint'],
Expand All @@ -24,9 +24,9 @@ module.exports = {
'@typescript-eslint/no-useless-constructor': 'error',
'no-empty-function': 'off',
'@typescript-eslint/no-empty-function': 'error',
'import/no-extraneous-dependencies': ['error', {'devDependencies': ['**/*.test.ts', 'integration-tests/*']}],
'import/no-extraneous-dependencies': ['error', { devDependencies: ['**/*.test.ts', 'integration-tests/*'] }],
'no-shadow': 'off', // replaced by ts-eslint rule below
'@typescript-eslint/no-shadow': 'error'
'@typescript-eslint/no-shadow': 'error',
},
settings: {
'import/resolver': {
Expand All @@ -38,4 +38,5 @@ module.exports = {
env: {
jest: true,
},
root: true,
};
7 changes: 4 additions & 3 deletions auditLogMover/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -7,7 +7,7 @@ module.exports = {
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
extends: [
'airbnb-base',
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'prettier', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
plugins: ['@typescript-eslint'],
Expand All @@ -17,7 +17,7 @@ module.exports = {
},
rules: {
'import/extensions': ['error', 'ignorePackages', { ts: 'never' }],
'no-console': ['warn', { allow: ["log", "error"] }],
'no-console': ['warn', { allow: ['log', 'error'] }],
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'error',
},
Expand All @@ -31,4 +31,5 @@ module.exports = {
env: {
jest: true,
},
root: true,
};
6 changes: 3 additions & 3 deletions auditLogMover/auditLogMoverHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('getEachDayInTimeFrame', () => {

const days = AuditLogMoverHelper.getEachDayInTimeFrame(startDate, endDate);

const dates = days.map(day => {
const dates = days.map((day) => {
return day.format('GGGG-MM-DD');
});

Expand All @@ -26,7 +26,7 @@ describe('getEachDayInTimeFrame', () => {

const days = AuditLogMoverHelper.getEachDayInTimeFrame(startDate, endDate);

const dates = days.map(day => {
const dates = days.map((day) => {
return day.format('GGGG-MM-DD');
});

Expand All @@ -40,7 +40,7 @@ describe('getEachDayInTimeFrame', () => {
try {
AuditLogMoverHelper.getEachDayInTimeFrame(startDate, endDate);
} catch (e) {
expect(e.message).toEqual('startTime can not be later than endTime');
expect((e as any).message).toEqual('startTime can not be later than endTime');
}
});
});
8 changes: 4 additions & 4 deletions auditLogMover/auditLogMoverHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ export class AuditLogMoverHelper {
static async doesEachDayHaveS3Directory(eachDayInTimeFrame: string[], auditLogBucket: string) {
const yearAndMonthPrefixOfDates = Array.from(
new Set(
eachDayInTimeFrame.map(date => {
eachDayInTimeFrame.map((date) => {
return date.substring(0, 7); // Only grab the year and month
}),
),
);
const directoriesInS3 = await this.getDirectoriesInS3GivenPrefixes(yearAndMonthPrefixOfDates, auditLogBucket);

const dateWithoutDirectory = eachDayInTimeFrame.filter(date => !directoriesInS3.includes(date));
const dateWithoutDirectory = eachDayInTimeFrame.filter((date) => !directoriesInS3.includes(date));

return dateWithoutDirectory.length === 0;
}
Expand All @@ -47,7 +47,7 @@ export class AuditLogMoverHelper {
private static async getDirectoriesInS3GivenPrefixes(prefixes: string[], auditLogBucket: string) {
const S3 = new AWS.S3();
const listS3Responses: ListObjectsV2Output[] = await Promise.all(
prefixes.map(prefix => {
prefixes.map((prefix) => {
const s3params: any = {
Bucket: auditLogBucket,
MaxKeys: 31,
Expand All @@ -61,7 +61,7 @@ export class AuditLogMoverHelper {
const directoriesInS3: string[] = [];
listS3Responses.forEach((response: ListObjectsV2Output) => {
if (response.CommonPrefixes) {
response.CommonPrefixes.forEach(commonPrefix => {
response.CommonPrefixes.forEach((commonPrefix) => {
// Format of Prefix is 2020-07-04/
// Therefore we need to remove the '/' at the end
if (commonPrefix.Prefix) {
Expand Down
22 changes: 6 additions & 16 deletions auditLogMover/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ describe('exportCloudwatchLogs', () => {
// CHECK
expect(createExportTaskSpy.calledOnce).toBeTruthy();

const sevenDaysAgo = moment
.utc()
.subtract(7, 'days')
.format('YYYY-MM-DD');
const sevenDaysAgo = moment.utc().subtract(7, 'days').format('YYYY-MM-DD');

const expectedCreateExportParams = {
destinationPrefix: sevenDaysAgo,
Expand Down Expand Up @@ -118,13 +115,10 @@ describe('exportCloudwatchLogs', () => {
await exportCloudwatchLogs();
} catch (e) {
// CHECK
expect(e.message).toEqual('Failed to kick off all export tasks');
expect((e as any).message).toEqual('Failed to kick off all export tasks');
expect(createExportTaskSpy.calledOnce).toBeTruthy();

const sevenDaysAgo = moment
.utc()
.subtract(7, 'days')
.format('YYYY-MM-DD');
const sevenDaysAgo = moment.utc().subtract(7, 'days').format('YYYY-MM-DD');

const params = {
destinationPrefix: sevenDaysAgo,
Expand Down Expand Up @@ -162,12 +156,8 @@ describe('deleteCloudwatchLogs', () => {
logStreams: [
{
logStreamName,
firstEventTimestamp: moment('2020-07-04')
.add(1, 'minutes')
.valueOf(),
lastEventTimestamp: moment('2020-07-04')
.add(2, 'minutes')
.valueOf(),
firstEventTimestamp: moment('2020-07-04').add(1, 'minutes').valueOf(),
lastEventTimestamp: moment('2020-07-04').add(2, 'minutes').valueOf(),
},
],
});
Expand Down Expand Up @@ -223,7 +213,7 @@ describe('deleteCloudwatchLogs', () => {
});
} catch (e) {
// CHECK
expect(e.message).toEqual(
expect((e as any).message).toEqual(
'Failed to delete Cloudwatch Logs because some Cloudwatch Logs have not been exported to S3',
);
checkEmitMetrics('deleteCloudwatchLogs', false);
Expand Down
11 changes: 4 additions & 7 deletions auditLogMover/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ exports.exportCloudwatchLogs = async () => {
// CWLogs needs to be initialized inside the function for 'aws-sdk-mock' to mock this object correctly during
// unit testing
const cloudwatchLogs = new AWS.CloudWatchLogs();
const beginTimeMoment = moment
.utc()
.subtract(NUMBER_OF_DAYS_KEEP_CWLOGS_BEFORE_ARCHIVING, 'days')
.startOf('day');
const beginTimeMoment = moment.utc().subtract(NUMBER_OF_DAYS_KEEP_CWLOGS_BEFORE_ARCHIVING, 'days').startOf('day');
const endTimeMoment = beginTimeMoment.endOf('day');

const eachDayInTimeFrame: moment.Moment[] = AuditLogMoverHelper.getEachDayInTimeFrame(
Expand All @@ -36,7 +33,7 @@ exports.exportCloudwatchLogs = async () => {

const exportTaskPromises: any[] = [];
const daysExported: string[] = [];
eachDayInTimeFrame.forEach(dayAsMoment => {
eachDayInTimeFrame.forEach((dayAsMoment) => {
const dateStringOfDayExported = dayAsMoment.format(DATE_FORMAT);
const params: any = {
destination: AUDIT_LOG_BUCKET,
Expand Down Expand Up @@ -88,15 +85,15 @@ exports.deleteCloudwatchLogs = async (event: any) => {
const lastDayInTimeFrame = eachDayInTimeFrame[eachDayInTimeFrame.length - 1];
const beginTimeMoment = moment(firstDayInTimeFrame).startOf('day');
const endTimeMoment = moment(lastDayInTimeFrame).endOf('day');
const logStreamsToDelete = logStreams.filter(logStream => {
const logStreamsToDelete = logStreams.filter((logStream) => {
return (
logStream.firstEventTimestamp >= beginTimeMoment.valueOf() &&
logStream.lastEventTimestamp <= endTimeMoment.valueOf()
);
});

const deleteLogstreamPromises: any[] = [];
logStreamsToDelete.forEach(logStream => {
logStreamsToDelete.forEach((logStream) => {
const params: any = {
logGroupName: CLOUDWATCH_EXECUTION_LOG_GROUP,
logStreamName: logStream.logStreamName,
Expand Down
18 changes: 9 additions & 9 deletions auditLogMover/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
"main": "index.js",
"license": "Apache-2.0",
"dependencies": {
"aws-sdk": "^2.785.0",
"aws-sdk": "^2.1000.0",
"axios": "^0.21.4",
"moment": "^2.26.0"
},
"devDependencies": {
"@types/jest": "^26.0.19",
"@typescript-eslint/eslint-plugin": "^4.11.1",
"@typescript-eslint/parser": "^4.11.1",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"aws-sdk-mock": "^5.1.0",
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.1.2",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^26.6.3",
"serverless": "^1.73.1",
"serverless": "2.29.0",
"serverless-bundle": "4.0.1",
"serverless-step-functions": "^2.27.1",
"sinon": "^9.0.2",
Expand Down
Loading

0 comments on commit c9a2c78

Please sign in to comment.