Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix: extensionsless key upload problems (#2159)

gbirman72924be33913
diff --git a/infra/bun.lock b/infra/bun.lock
index b5dd234254..553722ee89 100644
--- a/infra/bun.lock
+++ b/infra/bun.lock
@@ -16,7 +16,7 @@
"minimist": "^1.2.8",
},
"devDependencies": {
- "@biomejs/biome": "2.2.2",
+ "@biomejs/biome": "2.2.6",
"@types/node": "^20.8.10",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
@@ -246,23 +246,23 @@
"@aws-sdk/util-user-agent-node": ["@aws-sdk/[email protected]", "", { "dependencies": { "@aws-sdk/middleware-user-agent": "3.734.0", "@aws-sdk/types": "3.734.0", "@smithy/node-config-provider": "^4.0.1", "@smithy/types": "^4.1.0", "tslib": "^2.6.2" }, "peerDependencies": { "aws-crt": ">=1.0.0" }, "optionalPeers": ["aws-crt"] }, "sha512-c6Iinh+RVQKs6jYUFQ64htOU2HUXFQ3TVx+8Tu3EDF19+9vzWi9UukhIMH9rqyyEXIAkk9XL7avt8y2Uyw2dGA=="],
- "@biomejs/biome": ["@biomejs/[email protected]", "", { "optionalDependencies": { "@biomejs/cli-darwin-arm64": "2.2.2", "@biomejs/cli-darwin-x64": "2.2.2", "@biomejs/cli-linux-arm64": "2.2.2", "@biomejs/cli-linux-arm64-musl": "2.2.2", "@biomejs/cli-linux-x64": "2.2.2", "@biomejs/cli-linux-x64-musl": "2.2.2", "@biomejs/cli-win32-arm64": "2.2.2", "@biomejs/cli-win32-x64": "2.2.2" }, "bin": { "biome": "bin/biome" } }, "sha512-j1omAiQWCkhuLgwpMKisNKnsM6W8Xtt1l0WZmqY/dFj8QPNkIoTvk4tSsi40FaAAkBE1PU0AFG2RWFBWenAn+w=="],
+ "@biomejs/biome": ["@biomejs/[email protected]", "", { "optionalDependencies": { "@biomejs/cli-darwin-arm64": "2.2.6", "@biomejs/cli-darwin-x64": "2.2.6", "@biomejs/cli-linux-arm64": "2.2.6", "@biomejs/cli-linux-arm64-musl": "2.2.6", "@biomejs/cli-linux-x64": "2.2.6", "@biomejs/cli-linux-x64-musl": "2.2.6", "@biomejs/cli-win32-arm64": "2.2.6", "@biomejs/cli-win32-x64": "2.2.6" }, "bin": { "biome": "bin/biome" } }, "sha512-yKTCNGhek0rL5OEW1jbLeZX8LHaM8yk7+3JRGv08my+gkpmtb5dDE+54r2ZjZx0ediFEn1pYBOJSmOdDP9xtFw=="],
- "@biomejs/cli-darwin-arm64": ["@biomejs/[email protected]", "", { "os": "darwin", "cpu": "arm64" }, "sha512-6ePfbCeCPryWu0CXlzsWNZgVz/kBEvHiPyNpmViSt6A2eoDf4kXs3YnwQPzGjy8oBgQulrHcLnJL0nkCh80mlQ=="],
+ "@biomejs/cli-darwin-arm64": ["@biomejs/[email protected]", "", { "os": "darwin", "cpu": "arm64" }, "sha512-UZPmn3M45CjTYulgcrFJFZv7YmK3pTxTJDrFYlNElT2FNnkkX4fsxjExTSMeWKQYoZjvekpH5cvrYZZlWu3yfA=="],
- "@biomejs/cli-darwin-x64": ["@biomejs/[email protected]", "", { "os": "darwin", "cpu": "x64" }, "sha512-Tn4JmVO+rXsbRslml7FvKaNrlgUeJot++FkvYIhl1OkslVCofAtS35MPlBMhXgKWF9RNr9cwHanrPTUUXcYGag=="],
+ "@biomejs/cli-darwin-x64": ["@biomejs/[email protected]", "", { "os": "darwin", "cpu": "x64" }, "sha512-HOUIquhHVgh/jvxyClpwlpl/oeMqntlteL89YqjuFDiZ091P0vhHccwz+8muu3nTyHWM5FQslt+4Jdcd67+xWQ=="],
- "@biomejs/cli-linux-arm64": ["@biomejs/[email protected]", "", { "os": "linux", "cpu": "arm64" }, "sha512-JfrK3gdmWWTh2J5tq/rcWCOsImVyzUnOS2fkjhiYKCQ+v8PqM+du5cfB7G1kXas+7KQeKSWALv18iQqdtIMvzw=="],
+ "@biomejs/cli-linux-arm64": ["@biomejs/[email protected]", "", { "os": "linux", "cpu": "arm64" }, "sha512-BpGtuMJGN+o8pQjvYsUKZ+4JEErxdSmcRD/JG3mXoWc6zrcA7OkuyGFN1mDggO0Q1n7qXxo/PcupHk8gzijt5g=="],
- "@biomejs/cli-linux-arm64-musl": ["@biomejs/[email protected]", "", { "os": "linux", "cpu": "arm64" }, "sha512-/MhYg+Bd6renn6i1ylGFL5snYUn/Ct7zoGVKhxnro3bwekiZYE8Kl39BSb0MeuqM+72sThkQv4TnNubU9njQRw=="],
+ "@biomejs/cli-linux-arm64-musl": ["@biomejs/[email protected]", "", { "os": "linux", "cpu": "arm64" }, "sha512-TjCenQq3N6g1C+5UT3jE1bIiJb5MWQvulpUngTIpFsL4StVAUXucWD0SL9MCW89Tm6awWfeXBbZBAhJwjyFbRQ=="],
- "@biomejs/cli-linux-x64": ["@biomejs/[email protected]", "", { "os": "linux", "cpu": "x64" }, "sha512-Ogb+77edO5LEP/xbNicACOWVLt8mgC+E1wmpUakr+O4nKwLt9vXe74YNuT3T1dUBxC/SnrVmlzZFC7kQJEfquQ=="],
+ "@biomejs/cli-linux-x64": ["@biomejs/[email protected]", "", { "os": "linux", "cpu": "x64" }, "sha512-1HaM/dpI/1Z68zp8ZdT6EiBq+/O/z97a2AiHMl+VAdv5/ELckFt9EvRb8hDHpk8hUMoz03gXkC7VPXOVtU7faA=="],
- "@biomejs/cli-linux-x64-musl": ["@biomejs/[email protected]", "", { "os": "linux", "cpu": "x64" }, "sha512-ZCLXcZvjZKSiRY/cFANKg+z6Fhsf9MHOzj+NrDQcM+LbqYRT97LyCLWy2AS+W2vP+i89RyRM+kbGpUzbRTYWig=="],
+ "@biomejs/cli-linux-x64-musl": ["@biomejs/[email protected]", "", { "os": "linux", "cpu": "x64" }, "sha512-1ZcBux8zVM3JhWN2ZCPaYf0+ogxXG316uaoXJdgoPZcdK/rmRcRY7PqHdAos2ExzvjIdvhQp72UcveI98hgOog=="],
- "@biomejs/cli-win32-arm64": ["@biomejs/[email protected]", "", { "os": "win32", "cpu": "arm64" }, "sha512-wBe2wItayw1zvtXysmHJQoQqXlTzHSpQRyPpJKiNIR21HzH/CrZRDFic1C1jDdp+zAPtqhNExa0owKMbNwW9cQ=="],
+ "@biomejs/cli-win32-arm64": ["@biomejs/[email protected]", "", { "os": "win32", "cpu": "arm64" }, "sha512-h3A88G8PGM1ryTeZyLlSdfC/gz3e95EJw9BZmA6Po412DRqwqPBa2Y9U+4ZSGUAXCsnSQE00jLV8Pyrh0d+jQw=="],
- "@biomejs/cli-win32-x64": ["@biomejs/[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-DAuHhHekGfiGb6lCcsT4UyxQmVwQiBCBUMwVra/dcOSs9q8OhfaZgey51MlekT3p8UwRqtXQfFuEJBhJNdLZwg=="],
+ "@biomejs/cli-win32-x64": ["@biomejs/[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-yx0CqeOhPjYQ5ZXgPfu8QYkgBhVJyvWe36as7jRuPrKPO5ylVDfwVtPQ+K/mooNTADW0IhxOZm3aPu16dP8yNQ=="],
"@cspotcode/source-map-support": ["@cspotcode/[email protected]", "", { "dependencies": { "@jridgewell/trace-mapping": "0.3.9" } }, "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw=="],
diff --git a/infra/package.json b/infra/package.json
index cbac60c429..cbb27801bc 100644
--- a/infra/package.json
+++ b/infra/package.json
@@ -12,7 +12,7 @@
"check": "tsc --noEmit"
},
"devDependencies": {
- "@biomejs/biome": "2.2.2",
+ "@biomejs/biome": "2.2.6",
"@types/node": "^20.8.10",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
diff --git a/infra/stacks/document-storage-bucket-integrations/index.ts b/infra/stacks/document-storage-bucket-integrations/index.ts
index 9e92f6e311..9f001b3e53 100644
--- a/infra/stacks/document-storage-bucket-integrations/index.ts
+++ b/infra/stacks/document-storage-bucket-integrations/index.ts
@@ -2,6 +2,9 @@
import * as aws from '@pulumi/aws';
import * as pulumi from '@pulumi/pulumi';
+const getEventRuleArn = (ruleName: string) =>
+ pulumi.interpolate`arn:aws:events:${aws.config.region}:569036502058:rule/${ruleName}`;
+
// Main configuration setup
export const setupS3EventBridgeTriggers = () => {
const stack = pulumi.getStack();
@@ -40,16 +43,63 @@ export const setupS3EventBridgeTriggers = () => {
eventbridge: true,
});
+ const searchUploadDlq = new aws.sqs.Queue(`search-upload-dlq-${stack}`, {
+ name: `search-upload-dlq-${stack}`,
+ messageRetentionSeconds: 14 * 24 * 60 * 60, // 14 days
+ });
+
+ const searchUploadRuleName = `search-upload-rule-${stack}`;
+ const textExtractorRuleName = `text-extractor-rule-${stack}`;
+
+ const searchUploadRuleArn = getEventRuleArn(searchUploadRuleName);
+ const textExtractorRuleArn = getEventRuleArn(textExtractorRuleName);
+
+ const createDlqPolicy = (
+ name: string,
+ dlq: aws.sqs.Queue,
+ ruleArn: pulumi.Output<string>
+ ) => {
+ new aws.sqs.QueuePolicy(`${name}-dlq-policy-${stack}`, {
+ queueUrl: dlq.url,
+ policy: pulumi.all([dlq.arn, ruleArn]).apply(([queueArn, ruleArn]) =>
+ JSON.stringify({
+ Version: '2012-10-17',
+ Statement: [
+ {
+ Effect: 'Allow',
+ Principal: { Service: 'events.amazonaws.com' },
+ Action: 'sqs:SendMessage',
+ Resource: queueArn,
+ Condition: {
+ ArnEquals: {
+ 'aws:SourceArn': ruleArn,
+ },
+ },
+ },
+ ],
+ })
+ ),
+ });
+ };
+
+ createDlqPolicy('search-upload', searchUploadDlq, searchUploadRuleArn);
+
+ const textExtractorDlq = new aws.sqs.Queue(`text-extractor-dlq-${stack}`, {
+ name: `text-extractor-dlq-${stack}`,
+ messageRetentionSeconds: 14 * 24 * 60 * 60, // 14 days
+ });
+
+ createDlqPolicy('text-extractor', textExtractorDlq, textExtractorRuleArn);
+
// Configure EventBridge rules for each Lambda
- // Corrected code for EventBridge rules and Lambda integration
pulumi
- .all([bucketId, searchUploadHandlerLambdaArn])
- .apply(([bucketId, lambdaArn]) => {
+ .all([bucketId, searchUploadHandlerLambdaArn, searchUploadDlq.arn])
+ .apply(([bucketId, lambdaArn, dlqArn]) => {
// Rule for upload notification Lambda (handles all files)
const uploadNotificationRule = new aws.cloudwatch.EventRule(
`search-upload-rule-${stack}`,
{
- name: `search-upload-rule-${stack}`,
+ name: searchUploadRuleName,
description: 'Triggers search upload Lambda for all files',
eventPattern: JSON.stringify({
source: ['aws.s3'],
@@ -63,22 +113,25 @@ export const setupS3EventBridgeTriggers = () => {
}
);
- // Add the Lambda as a target
+ // Add the Lambda as a target with DLQ
new aws.cloudwatch.EventTarget('search-upload-target', {
rule: uploadNotificationRule.name,
arn: lambdaArn,
+ deadLetterConfig: {
+ arn: dlqArn,
+ },
});
});
pulumi
- .all([bucketId, documentTextExtractorLambdaArn])
- .apply(([bucketId, extractorArn]) => {
- // Rule for document text extractor Lambda (PDF files only)
+ .all([bucketId, documentTextExtractorLambdaArn, textExtractorDlq.arn])
+ .apply(([bucketId, extractorArn, dlqArn]) => {
+ // Rule for document text extractor Lambda (the lambda will read the db file type to check if it's a PDF)
const textExtractorRule = new aws.cloudwatch.EventRule(
`text-extractor-rule-${stack}`,
{
- name: `text-extractor-rule-${stack}`,
- description: 'Triggers text extractor Lambda for PDF files',
+ name: textExtractorRuleName,
+ description: 'Triggers text extractor Lambda for all files',
eventPattern: JSON.stringify({
source: ['aws.s3'],
'detail-type': ['Object Created'],
@@ -86,32 +139,28 @@ export const setupS3EventBridgeTriggers = () => {
bucket: {
name: [bucketId],
},
- object: {
- key: [
- {
- suffix: '.pdf',
- },
- ],
- },
},
}),
}
);
- // Add the Lambda as a target
+ // Add the Lambda as a target with DLQ
new aws.cloudwatch.EventTarget('text-extractor-target', {
rule: textExtractorRule.name,
arn: extractorArn,
+ deadLetterConfig: {
+ arn: dlqArn,
+ },
});
});
// Add necessary permissions for EventBridge to invoke Lambda functions
- const createLambdaPermission = (functionArn: string, ruleId: string) => {
- return new aws.lambda.Permission(`eventbridge-permission-${ruleId}`, {
+ const createLambdaPermission = (functionArn: string, ruleName: string) => {
+ return new aws.lambda.Permission(`eventbridge-permission-${ruleName}`, {
action: 'lambda:InvokeFunction',
function: functionArn,
principal: 'events.amazonaws.com',
- sourceArn: pulumi.interpolate`arn:aws:events:${aws.config.region}:569036502058:rule/${ruleId}`,
+ sourceArn: getEventRuleArn(ruleName),
});
};
@@ -121,9 +170,9 @@ export const setupS3EventBridgeTriggers = () => {
.apply(([searchUploadHandlerLambdaArn, extractorArn]) => {
createLambdaPermission(
searchUploadHandlerLambdaArn,
- `search-upload-rule-${stack}`
+ searchUploadRuleName
);
- createLambdaPermission(extractorArn, `text-extractor-rule-${stack}`);
+ createLambdaPermission(extractorArn, textExtractorRuleName);
});
};
diff --git a/infra/stacks/search-upload/Pulumi.dev.yaml b/infra/stacks/search-upload/Pulumi.dev.yaml
index 1a38cefb17..c67d71a70b 100644
--- a/infra/stacks/search-upload/Pulumi.dev.yaml
+++ b/infra/stacks/search-upload/Pulumi.dev.yaml
@@ -1,2 +1,3 @@
config:
aws:region: us-east-1
+ search-upload:document_storage_service_auth_key: document-storage-service-auth-key-dev
diff --git a/infra/stacks/search-upload/Pulumi.prod.yaml b/infra/stacks/search-upload/Pulumi.prod.yaml
index 1a38cefb17..cda74ab61e 100644
--- a/infra/stacks/search-upload/Pulumi.prod.yaml
+++ b/infra/stacks/search-upload/Pulumi.prod.yaml
@@ -1,2 +1,3 @@
config:
aws:region: us-east-1
+ search-upload:document_storage_service_auth_key: document-storage-service-auth-key-prod
diff --git a/infra/stacks/search-upload/index.ts b/infra/stacks/search-upload/index.ts
index c90d412aa6..8c8e43a385 100644
--- a/infra/stacks/search-upload/index.ts
+++ b/infra/stacks/search-upload/index.ts
@@ -1,5 +1,6 @@
+import * as aws from '@pulumi/aws';
import * as pulumi from '@pulumi/pulumi';
-import { getSearchEventQueue, stack } from '../../packages/shared';
+import { config, getSearchEventQueue, stack } from '../../packages/shared';
import { SearchUploadHandler } from './search-upload-lambda';
const tags = {
@@ -10,6 +11,12 @@ const tags = {
const { searchEventQueueName, searchEventQueueArn } = getSearchEventQueue();
+const DOCUMENT_STORAGE_SERVICE_AUTH_KEY = aws.secretsmanager
+ .getSecretVersionOutput({
+ secretId: config.require('document_storage_service_auth_key'),
+ })
+ .apply((secret) => secret.secretString);
+
const BASE_NAME = 'search-upload';
const searchUploadHandler = new SearchUploadHandler(
@@ -20,6 +27,7 @@ const searchUploadHandler = new SearchUploadHandler(
RUST_LOG: 'search_upload_handler=info',
SEARCH_EVENT_QUEUE: pulumi.interpolate`${searchEventQueueName}`,
DOCUMENT_STORAGE_SERVICE_URL: `https://cloud-storage${stack === 'prod' ? '' : `-${stack}`}.macro.com`,
+ DOCUMENT_STORAGE_SERVICE_AUTH_KEY: pulumi.interpolate`${DOCUMENT_STORAGE_SERVICE_AUTH_KEY}`,
},
searchEventQueueArn,
tags,
diff --git a/infra/stacks/search-upload/search-upload-lambda.ts b/infra/stacks/search-upload/search-upload-lambda.ts
index f921c1fc93..e6e4569acd 100644
--- a/infra/stacks/search-upload/search-upload-lambda.ts
+++ b/infra/stacks/search-upload/search-upload-lambda.ts
@@ -12,6 +12,7 @@ type EnvVars = {
RUST_LOG: pulumi.Output<string> | string;
SEARCH_EVENT_QUEUE: pulumi.Output<string> | string;
DOCUMENT_STORAGE_SERVICE_URL: pulumi.Output<string> | string;
+ DOCUMENT_STORAGE_SERVICE_AUTH_KEY: pulumi.Output<string> | string;
};
type Args = {