@quiltdata/benchling-webhook 0.8.8 → 0.9.0-20251126T040420Z

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,211 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.AlbApiGateway = void 0;
37
- const cdk = __importStar(require("aws-cdk-lib"));
38
- const apigateway = __importStar(require("aws-cdk-lib/aws-apigateway"));
39
- const iam = __importStar(require("aws-cdk-lib/aws-iam"));
40
- const logs = __importStar(require("aws-cdk-lib/aws-logs"));
41
- class AlbApiGateway {
42
- constructor(scope, id, props) {
43
- const { config } = props;
44
- this.logGroup = new logs.LogGroup(scope, "ApiGatewayAccessLogs", {
45
- logGroupName: "/aws/apigateway/benchling-webhook",
46
- retention: logs.RetentionDays.ONE_WEEK,
47
- removalPolicy: cdk.RemovalPolicy.DESTROY,
48
- });
49
- this.createCloudWatchRole(scope);
50
- // Get webhook allow list from config
51
- const webhookAllowList = config.security?.webhookAllowList || "";
52
- // Parse IP allowlist for resource policy
53
- let allowedIps = undefined;
54
- if (webhookAllowList) {
55
- if (cdk.Token.isUnresolved(webhookAllowList)) {
56
- // For CDK tokens (parameters), we can't evaluate at synth time
57
- // Split and let CloudFormation handle it
58
- allowedIps = cdk.Fn.split(",", webhookAllowList);
59
- }
60
- else if (webhookAllowList.trim() !== "") {
61
- // For concrete values, parse and filter
62
- const parsed = webhookAllowList
63
- .split(",")
64
- .map(ip => ip.trim())
65
- .filter(ip => ip.length > 0);
66
- if (parsed.length > 0) {
67
- allowedIps = parsed;
68
- }
69
- }
70
- }
71
- // Create resource policy for IP filtering at the edge
72
- // Only create policy if we have IPs and they're not from an empty parameter
73
- const policyDocument = this.createResourcePolicy(allowedIps, webhookAllowList);
74
- this.api = new apigateway.RestApi(scope, "BenchlingWebhookAPI", {
75
- restApiName: "BenchlingWebhookAPI",
76
- policy: policyDocument,
77
- deployOptions: {
78
- stageName: "prod",
79
- accessLogDestination: new apigateway.LogGroupLogDestination(this.logGroup),
80
- methodOptions: {
81
- "/*/*": {
82
- loggingLevel: apigateway.MethodLoggingLevel.INFO,
83
- dataTraceEnabled: true,
84
- },
85
- },
86
- },
87
- });
88
- this.addWebhookEndpoints(props.loadBalancer);
89
- // Output API Gateway ID for execution logs
90
- new cdk.CfnOutput(scope, "ApiGatewayId", {
91
- value: this.api.restApiId,
92
- description: "API Gateway REST API ID",
93
- });
94
- // Output execution log group name
95
- new cdk.CfnOutput(scope, "ApiGatewayExecutionLogGroup", {
96
- value: `API-Gateway-Execution-Logs_${this.api.restApiId}/prod`,
97
- description: "API Gateway execution log group for detailed request/response logs",
98
- });
99
- // Output ALB DNS for direct testing
100
- new cdk.CfnOutput(scope, "LoadBalancerDNS", {
101
- value: props.loadBalancer.loadBalancerDnsName,
102
- description: "Application Load Balancer DNS name for direct testing",
103
- });
104
- }
105
- createResourcePolicy(allowedIps, rawParameter) {
106
- // Don't create policy if no IPs provided
107
- if (!allowedIps) {
108
- return undefined;
109
- }
110
- // Don't create policy for empty arrays
111
- if (Array.isArray(allowedIps) && allowedIps.length === 0) {
112
- return undefined;
113
- }
114
- // For CDK tokens (CloudFormation parameters), we can't evaluate at synth time
115
- // Don't create policy for parameters since we can't conditionally apply them
116
- // API Gateway doesn't support conditional policies, so we skip the policy entirely
117
- // when using parameters. This means WebhookAllowList parameter won't work for
118
- // runtime IP filtering - IPs must be set at deployment time.
119
- if (rawParameter && cdk.Token.isUnresolved(rawParameter)) {
120
- return undefined;
121
- }
122
- return new iam.PolicyDocument({
123
- statements: [
124
- new iam.PolicyStatement({
125
- effect: iam.Effect.ALLOW,
126
- principals: [new iam.AnyPrincipal()],
127
- actions: ["execute-api:Invoke"],
128
- resources: ["execute-api:/*"],
129
- conditions: {
130
- IpAddress: {
131
- "aws:SourceIp": allowedIps,
132
- },
133
- },
134
- }),
135
- ],
136
- });
137
- }
138
- createCloudWatchRole(scope) {
139
- const cloudWatchRole = new iam.Role(scope, "ApiGatewayCloudWatchRole", {
140
- assumedBy: new iam.ServicePrincipal("apigateway.amazonaws.com"),
141
- managedPolicies: [
142
- iam.ManagedPolicy.fromAwsManagedPolicyName("service-role/AmazonAPIGatewayPushToCloudWatchLogs"),
143
- ],
144
- });
145
- new apigateway.CfnAccount(scope, "ApiGatewayAccount", {
146
- cloudWatchRoleArn: cloudWatchRole.roleArn,
147
- });
148
- return cloudWatchRole;
149
- }
150
- addWebhookEndpoints(loadBalancer) {
151
- // Create HTTP integration to ALB
152
- const albIntegration = new apigateway.HttpIntegration(`http://${loadBalancer.loadBalancerDnsName}/{proxy}`, {
153
- httpMethod: "ANY",
154
- options: {
155
- requestParameters: {
156
- "integration.request.path.proxy": "method.request.path.proxy",
157
- },
158
- integrationResponses: [
159
- {
160
- statusCode: "200",
161
- },
162
- {
163
- statusCode: "400",
164
- selectionPattern: "4\\d{2}",
165
- },
166
- {
167
- statusCode: "500",
168
- selectionPattern: "5\\d{2}",
169
- },
170
- ],
171
- },
172
- });
173
- // Create proxy resource to forward all requests to ALB
174
- const proxyResource = this.api.root.addResource("{proxy+}");
175
- proxyResource.addMethod("ANY", albIntegration, {
176
- requestParameters: {
177
- "method.request.path.proxy": true,
178
- },
179
- methodResponses: [
180
- { statusCode: "200" },
181
- { statusCode: "400" },
182
- { statusCode: "500" },
183
- ],
184
- });
185
- // Also handle root path
186
- this.api.root.addMethod("ANY", new apigateway.HttpIntegration(`http://${loadBalancer.loadBalancerDnsName}/`, {
187
- httpMethod: "ANY",
188
- options: {
189
- integrationResponses: [
190
- { statusCode: "200" },
191
- {
192
- statusCode: "400",
193
- selectionPattern: "4\\d{2}",
194
- },
195
- {
196
- statusCode: "500",
197
- selectionPattern: "5\\d{2}",
198
- },
199
- ],
200
- },
201
- }), {
202
- methodResponses: [
203
- { statusCode: "200" },
204
- { statusCode: "400" },
205
- { statusCode: "500" },
206
- ],
207
- });
208
- }
209
- }
210
- exports.AlbApiGateway = AlbApiGateway;
211
- //# sourceMappingURL=alb-api-gateway.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"alb-api-gateway.js","sourceRoot":"","sources":["../../lib/alb-api-gateway.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAmC;AACnC,uEAAyD;AACzD,yDAA2C;AAC3C,2DAA6C;AAe7C,MAAa,aAAa;IAItB,YACI,KAAgB,EAChB,EAAU,EACV,KAAyB;QAEzB,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;QAEzB,IAAI,CAAC,QAAQ,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,sBAAsB,EAAE;YAC7D,YAAY,EAAE,mCAAm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