Skip to content

Commit

Permalink
chore: more lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
asharonbaltazar committed Aug 5, 2024
1 parent 8b3f2bc commit 9575802
Show file tree
Hide file tree
Showing 23 changed files with 76 additions and 111 deletions.
2 changes: 1 addition & 1 deletion bin/cli/src/lib/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class LabeledProcessRunner {
private sanitizeInput(input) {
// A basic pattern that allows letters, numbers, dashes, underscores, and periods
// Adjust the pattern to fit the expected input format
const sanitizedInput = input.replace(/[^a-zA-Z0-9-_\.]/g, "");
const sanitizedInput = input.replace(/[^a-zA-Z0-9-_.]/g, "");
return sanitizedInput;
}

Expand Down
2 changes: 1 addition & 1 deletion bin/cli/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ yargs
.command(getCost)
.strict()
.scriptName("run")
.demandCommand(1, "").argv;
.demandCommand(1, "");
2 changes: 1 addition & 1 deletion docs/_deploy-metrics/components/CheckboxFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type CheckboxFilterProps = Omit<UI.CheckboxGroupProps, "onChange"> & {
};

export const CheckboxFilter = (props: CheckboxFilterProps) => {
const { options, label, spacing = "2", showSearch, ...rest } = props;
const { options, label, spacing = "2", ...rest } = props;

return (
<UI.Stack as="fieldset" spacing={spacing}>
Expand Down
4 changes: 2 additions & 2 deletions lib/lambda/getUploadUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe("Handler for generating signed URL", () => {
key: "123e4567-e89b-12d3-a456-426614174000.pdf",
},
});
expect(getSignedUrl).toHaveBeenCalled;
expect(getSignedUrl).toHaveBeenCalled();
});

it("should return 500 if an error occurs during processing", async () => {
Expand All @@ -80,6 +80,6 @@ describe("Handler for generating signed URL", () => {
it("should throw an error if required environment variables are missing", () => {
delete process.env.attachmentsBucketName;

expect(() => handler({} as APIGatewayEvent)).toThrowError;
expect(() => handler({} as APIGatewayEvent)).toThrowError();
});
});
12 changes: 0 additions & 12 deletions lib/lambda/getUploadUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,3 @@ export const handler = async (event: APIGatewayEvent) => {
});
}
};

function checkEnvVariables(requiredEnvVariables: string[]) {
const missingVariables = requiredEnvVariables.filter(
(envVar) => !process.env[envVar],
);

if (missingVariables.length > 0) {
throw new Error(
`Missing required environment variables: ${missingVariables.join(", ")}`,
);
}
}
6 changes: 1 addition & 5 deletions lib/lambda/sinkMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,8 @@ const changed_date = async (
) => {
const docs: any[] = [];
for (const kafkaRecord of kafkaRecords) {
const { key, value } = kafkaRecord;
const { value } = kafkaRecord;
try {
// Set id
const id: string = JSON.parse(decodeBase64WithUtf8(key)).payload
.ID_Number;

// Handle delete events and continue
if (value === undefined) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion lib/libs/api/kafka.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ describe("Kafka producer functions", () => {

it("should throw an error if brokerString is not defined", () => {
delete process.env.brokerString;
expect(() => getProducer()).toThrowError;
expect(() => getProducer()).toThrowError();
});
});
2 changes: 1 addition & 1 deletion lib/libs/opensearch-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function createAwsConnector(credentials: any) {
export async function updateData(host: string, indexObject: any) {
client = client || (await getClient(host));
// Add a document to the index.
const response = await client.update(indexObject);
await client.update(indexObject);
}

function sleep(ms: number): Promise<void> {
Expand Down
23 changes: 12 additions & 11 deletions lib/libs/topics-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface TopicConfig {

export async function createTopics(
brokerString: string,
topicsConfig: TopicConfig[]
topicsConfig: TopicConfig[],
) {
const topics = topicsConfig;
const brokers = brokerString.split(",");
Expand All @@ -27,23 +27,23 @@ export async function createTopics(
// Fetch topics from MSK and filter out __ internal management topic
const existingTopicList = _.filter(
await admin.listTopics(),
(n) => !n.startsWith("_")
(n) => !n.startsWith("_"),
);

console.log("Existing topics:", JSON.stringify(existingTopicList, null, 2));

// Fetch the metadata for the topics in MSK
const topicsMetadata = _.get(
await admin.fetchTopicMetadata({ topics: existingTopicList }),
"topics"
"topics",
);
console.log("Topics Metadata:", JSON.stringify(topicsMetadata, null, 2));

// Diff the existing topics array with the topic configuration collection
const topicsToCreate = _.differenceWith(
topics,
existingTopicList,
(topicConfig, topic) => _.get(topicConfig, "topic") === topic
(topicConfig, topic) => _.get(topicConfig, "topic") === topic,
);

// Find intersection of topics metadata collection with topic configuration collection
Expand All @@ -55,7 +55,7 @@ export async function createTopics(
(topicConfig, topicMetadata) =>
_.get(topicConfig, "topic") === _.get(topicMetadata, "name") &&
_.get(topicConfig, "numPartitions") >
_.get(topicMetadata, "partitions", []).length
_.get(topicMetadata, "partitions", []).length,
);

// Create a collection to update topic partitioning
Expand Down Expand Up @@ -83,19 +83,20 @@ export async function createTopics(
console.log("Topics to Update:", JSON.stringify(topicsToUpdate, null, 2));
console.log(
"Partitions to Update:",
JSON.stringify(partitionConfig, null, 2)
JSON.stringify(partitionConfig, null, 2),
);
console.log(
"Topic configuration options:",
JSON.stringify(configs, null, 2)
JSON.stringify(configs, null, 2),
);

// Create topics that don't exist in MSK
await admin.createTopics({ topics: topicsToCreate });

// If any topics have fewer partitions in MSK than in the configuration, add those partitions
partitionConfig.length > 0 &&
(await admin.createPartitions({ topicPartitions: partitionConfig }));
if (partitionConfig.length > 0) {
await admin.createPartitions({ topicPartitions: partitionConfig });
}

await admin.disconnect();
};
Expand All @@ -108,7 +109,7 @@ export async function deleteTopics(brokerString: string, topicList: string[]) {
for (const topic of topicList) {
if (!topic.match(/.*--.*--.*--.*/g)) {
throw new Error(
"ERROR: The deleteTopics function only operates against topics that match /.*--.*--.*--.*/g"
"ERROR: The deleteTopics function only operates against topics that match /.*--.*--.*--.*/g",
);
}
}
Expand All @@ -130,7 +131,7 @@ export async function deleteTopics(brokerString: string, topicList: string[]) {
const currentTopics = await admin.listTopics();

const topicsToDelete = _.filter(currentTopics, (currentTopic) =>
topicList.some((pattern) => !!currentTopic.match(pattern))
topicList.some((pattern) => !!currentTopic.match(pattern)),
);

console.log(`Deleting topics: ${topicsToDelete}`);
Expand Down
29 changes: 17 additions & 12 deletions lib/local-constructs/clamav-scanning/src/lib/clamav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const downloadAVDefinitions = async (): Promise<void[]> => {
// Download each file in the bucket
const downloadPromises: Promise<void>[] = definitionFileKeys.map(
(filenameToDownload) => {
return new Promise<void>(async (resolve, reject) => {
return new Promise<void>((resolve, reject) => {
const destinationFile: string = path.join(
constants.FRESHCLAM_WORK_DIR,
filenameToDownload,
Expand All @@ -79,13 +79,17 @@ export const downloadAVDefinitions = async (): Promise<void[]> => {
};

try {
const { Body } = await s3Client.send(new GetObjectCommand(options));
if (!Body || !(Body instanceof Readable)) {
throw new Error("Invalid Body type received from S3");
}
await asyncfs.writeFile(destinationFile, Body);
logger.info(`Finished download ${filenameToDownload}`);
resolve();
s3Client
.send(new GetObjectCommand(options))
.then(async ({ Body }) => {
if (!Body || !(Body instanceof Readable)) {
throw new Error("Invalid Body type received from S3");
}

await asyncfs.writeFile(destinationFile, Body);
resolve();
logger.info(`Finished download ${filenameToDownload}`);
});
} catch (err) {
logger.info(
`Error downloading definition file ${filenameToDownload}`,
Expand Down Expand Up @@ -145,7 +149,7 @@ export const uploadAVDefinitions = async (): Promise<void[]> => {

const uploadPromises: Promise<void>[] = definitionFiles.map(
(filenameToUpload) => {
return new Promise<void>(async (resolve, reject) => {
return new Promise<void>((resolve, reject) => {
logger.info(
`Uploading updated definitions for file ${filenameToUpload} ---`,
);
Expand All @@ -159,9 +163,10 @@ export const uploadAVDefinitions = async (): Promise<void[]> => {
};

try {
await s3Client.send(new PutObjectCommand(options));
resolve();
logger.info(`--- Finished uploading ${filenameToUpload} ---`);
s3Client.send(new PutObjectCommand(options)).then(() => {
logger.info(`--- Finished uploading ${filenameToUpload} ---`);
resolve();
});
} catch (err) {
logger.info(`--- Error uploading ${filenameToUpload} ---`);
logger.info(err);
Expand Down
5 changes: 2 additions & 3 deletions lib/local-constructs/clamav-scanning/src/lib/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
GetObjectCommand,
PutObjectTaggingCommand,
HeadObjectCommandOutput,
PutObjectTaggingCommandOutput,
ListObjectsV2Command,
} from "@aws-sdk/client-s3";
import { randomUUID } from "crypto";
Expand Down Expand Up @@ -55,7 +54,7 @@ export async function downloadFileFromS3(
const localPath: string = `${
constants.TMP_DOWNLOAD_PATH
}${randomUUID()}--${s3ObjectKey}`;
const writeStream: fs.WriteStream = fs.createWriteStream(localPath);
fs.createWriteStream(localPath);

logger.info(`Downloading file s3://${s3ObjectBucket}/${s3ObjectKey}`);

Expand Down Expand Up @@ -84,7 +83,7 @@ export async function tagWithScanStatus(
virusScanStatus: string,
): Promise<void> {
try {
const res: PutObjectTaggingCommandOutput = await s3Client.send(
await s3Client.send(
new PutObjectTaggingCommand({
Bucket: bucket,
Key: key,
Expand Down
22 changes: 9 additions & 13 deletions lib/local-constructs/cloudwatch-to-s3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,14 @@ export class CloudWatchToS3 extends Construct {
});

// Create a subscription filter to send logs from the CloudWatch Log Group to Firehose
const subscriptionFilter = new CfnSubscriptionFilter(
this,
"SubscriptionFilter",
{
logGroupName: logGroup.logGroupName,
filterPattern: filterPattern,
destinationArn: cdk.Fn.getAtt(
this.deliveryStream.logicalId,
"Arn",
).toString(),
roleArn: subscriptionFilterRole.roleArn,
},
);
new CfnSubscriptionFilter(this, "SubscriptionFilter", {
logGroupName: logGroup.logGroupName,
filterPattern: filterPattern,
destinationArn: cdk.Fn.getAtt(
this.deliveryStream.logicalId,
"Arn",
).toString(),
roleArn: subscriptionFilterRole.roleArn,
});
}
}
8 changes: 4 additions & 4 deletions lib/packages/shared-utils/s3-url-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export function s3ParseUrl(url: string) {

// http://s3.amazonaws.com/bucket/key1/key2
const _match_1 = _decodedUrl.match(
/^https?:\/\/s3.amazonaws.com\/([^\/]+)\/?(.*?)$/
/^https?:\/\/s3.amazonaws.com\/([^/]+)\/?(.*?)$/,
);
if (_match_1) {
return {
Expand All @@ -15,7 +15,7 @@ export function s3ParseUrl(url: string) {

// http://s3-aws-region.amazonaws.com/bucket/key1/key2
const _match_2 = _decodedUrl.match(
/^https?:\/\/s3-([^.]+).amazonaws.com\/([^\/]+)\/?(.*?)$/
/^https?:\/\/s3-([^.]+).amazonaws.com\/([^/]+)\/?(.*?)$/,
);
if (_match_2) {
return {
Expand All @@ -27,7 +27,7 @@ export function s3ParseUrl(url: string) {

// http://bucket.s3.amazonaws.com/key1/key2
const _match_3 = _decodedUrl.match(
/^https?:\/\/([^.]+).s3.amazonaws.com\/?(.*?)$/
/^https?:\/\/([^.]+).s3.amazonaws.com\/?(.*?)$/,
);
if (_match_3) {
return {
Expand All @@ -40,7 +40,7 @@ export function s3ParseUrl(url: string) {
// http://bucket.s3-aws-region.amazonaws.com/key1/key2 or,
// http://bucket.s3.aws-region.amazonaws.com/key1/key2
const _match_4 = _decodedUrl.match(
/^https?:\/\/([^.]+).(?:s3-|s3\.)([^.]+).amazonaws.com\/?(.*?)$/
/^https?:\/\/([^.]+).(?:s3-|s3\.)([^.]+).amazonaws.com\/?(.*?)$/,
);
if (_match_4) {
return {
Expand Down
3 changes: 1 addition & 2 deletions lib/packages/shared-utils/user-helper.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, vi, expect } from "vitest";
import { describe, it, expect } from "vitest";
import {
isCmsReadonlyUser,
isCmsUser,
Expand Down Expand Up @@ -95,7 +95,6 @@ describe("isCmsSuperUser", () => {
});

describe("isIDM", () => {
const consoleErrorSpy = vi.spyOn(console, "error");
it("returns false if a user has no Cognito identities", () => {
expect(isIDM(testStateCognitoUser.user)).toBe(false);
expect(isIDM(testCMSCognitoUser.user)).toBe(false);
Expand Down
2 changes: 1 addition & 1 deletion lib/stacks/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class Auth extends cdk.NestedStack {
},
);

const manageUsers = new ManageUsers(
new ManageUsers(
this,
"ManageUsers",
userPool,
Expand Down
28 changes: 10 additions & 18 deletions lib/stacks/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,12 @@ export class Data extends cdk.NestedStack {
standardAttributes: { email: { required: true, mutable: true } },
});

const userPoolDomain = new cdk.aws_cognito.UserPoolDomain(
this,
"UserPoolDomain",
{
userPool,
cognitoDomain: {
domainPrefix: `${project}-${stage}-search`,
},
new cdk.aws_cognito.UserPoolDomain(this, "UserPoolDomain", {
userPool,
cognitoDomain: {
domainPrefix: `${project}-${stage}-search`,
},
);
});

const userPoolClient = new cdk.aws_cognito.UserPoolClient(
this,
Expand Down Expand Up @@ -898,16 +894,12 @@ export class Data extends cdk.NestedStack {
},
);

const runReindexCustomResource = new cdk.CustomResource(
this,
"RunReindex",
{
serviceToken: runReindexProviderProvider.serviceToken,
properties: {
stateMachine: reindexStateMachine.stateMachineArn,
},
new cdk.CustomResource(this, "RunReindex", {
serviceToken: runReindexProviderProvider.serviceToken,
properties: {
stateMachine: reindexStateMachine.stateMachineArn,
},
);
});

if (!usingSharedOpenSearch) {
reindexStateMachine.node.addDependency(this.mapRoleCustomResource);
Expand Down
2 changes: 1 addition & 1 deletion lib/stacks/parent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class ParentStack extends cdk.Stack {
devPasswordArn: props.devPasswordArn,
});

const emailStack = new Stacks.Email(this, "email", {
new Stacks.Email(this, "email", {
...commonProps,
stack: "email",
vpc,
Expand Down
Loading

0 comments on commit 9575802

Please sign in to comment.