@quiltdata/benchling-webhook 0.4.13 → 0.5.0
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.
- package/dist/bin/benchling-webhook.d.ts +50 -0
- package/dist/bin/benchling-webhook.d.ts.map +1 -0
- package/dist/bin/benchling-webhook.js +268 -0
- package/dist/bin/benchling-webhook.js.map +1 -0
- package/dist/bin/cli.d.ts +3 -0
- package/dist/bin/cli.d.ts.map +1 -0
- package/dist/bin/cli.js +83 -0
- package/dist/bin/cli.js.map +1 -0
- package/dist/bin/commands/deploy.d.ts +7 -0
- package/dist/bin/commands/deploy.d.ts.map +1 -0
- package/dist/bin/commands/deploy.js +154 -0
- package/dist/bin/commands/deploy.js.map +1 -0
- package/dist/bin/commands/init.d.ts +9 -0
- package/dist/bin/commands/init.d.ts.map +1 -0
- package/dist/bin/commands/init.js +155 -0
- package/dist/bin/commands/init.js.map +1 -0
- package/dist/bin/commands/validate.d.ts +5 -0
- package/dist/bin/commands/validate.d.ts.map +1 -0
- package/dist/bin/commands/validate.js +135 -0
- package/dist/bin/commands/validate.js.map +1 -0
- package/dist/bin/get-env.js +180 -0
- package/dist/bin/publish.js +327 -0
- package/{bin → dist/bin}/version.js +73 -37
- package/dist/lib/alb-api-gateway.d.ts +17 -0
- package/dist/lib/alb-api-gateway.d.ts.map +1 -0
- package/dist/lib/alb-api-gateway.js +191 -0
- package/dist/lib/alb-api-gateway.js.map +1 -0
- package/dist/lib/benchling-webhook-stack.d.ts +25 -0
- package/dist/lib/benchling-webhook-stack.d.ts.map +1 -0
- package/dist/lib/benchling-webhook-stack.js +165 -0
- package/dist/lib/benchling-webhook-stack.js.map +1 -0
- package/dist/lib/constants.d.ts +28 -0
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/lib/constants.js +31 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/ecr-repository.d.ts +16 -0
- package/dist/lib/ecr-repository.d.ts.map +1 -0
- package/dist/lib/ecr-repository.js +90 -0
- package/dist/lib/ecr-repository.js.map +1 -0
- package/dist/lib/fargate-service.d.ts +32 -0
- package/dist/lib/fargate-service.d.ts.map +1 -0
- package/dist/lib/fargate-service.js +294 -0
- package/dist/lib/fargate-service.js.map +1 -0
- package/{lib/index.ts → dist/lib/index.d.ts} +5 -5
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +38 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/templates/base-template.d.ts +14 -0
- package/dist/lib/templates/base-template.d.ts.map +1 -0
- package/dist/lib/templates/base-template.js +68 -0
- package/dist/lib/templates/base-template.js.map +1 -0
- package/dist/lib/templates/readme.d.ts +11 -0
- package/dist/lib/templates/readme.d.ts.map +1 -0
- package/dist/lib/templates/readme.js +105 -0
- package/dist/lib/templates/readme.js.map +1 -0
- package/dist/lib/utils/config.d.ts +68 -0
- package/dist/lib/utils/config.d.ts.map +1 -0
- package/dist/lib/utils/config.js +195 -0
- package/dist/lib/utils/config.js.map +1 -0
- package/dist/lib/utils/stack-inference.d.ts +73 -0
- package/dist/lib/utils/stack-inference.d.ts.map +1 -0
- package/dist/lib/utils/stack-inference.js +410 -0
- package/dist/lib/utils/stack-inference.js.map +1 -0
- package/dist/package.json +90 -0
- package/package.json +32 -21
- package/AGENTS.md +0 -226
- package/CHANGELOG.md +0 -91
- package/bin/benchling-webhook.ts +0 -172
- package/bin/cli-auth.sh +0 -74
- package/bin/get-env.js +0 -564
- package/bin/publish-manual.js +0 -211
- package/bin/release-notes.sh +0 -82
- package/bin/sync-version.js +0 -72
- package/cdk.context.json +0 -58
- package/cdk.json +0 -85
- package/doc/NPM_OIDC_SETUP.md +0 -95
- package/doc/PARAMETERS.md +0 -203
- package/doc/RELEASE.md +0 -297
- package/doc/RELEASE_NOTES.md +0 -64
- package/jest.config.js +0 -14
- package/lib/README.md +0 -50
- package/lib/oauth-tester.json +0 -35
- package/tsconfig.json +0 -34
- /package/{bin → dist/bin}/check-logs.js +0 -0
- /package/{bin → dist/bin}/release.js +0 -0
- /package/{bin → dist/bin}/send-event.js +0 -0
- /package/{bin → dist/bin}/test-invalid-signature.js +0 -0
package/AGENTS.md
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
# Benchling Webhook Integration - Complete Guide
|
|
2
|
-
|
|
3
|
-
Complete deployment and operational guide for the Benchling webhook integration with Quilt.
|
|
4
|
-
|
|
5
|
-
## Architecture Overview
|
|
6
|
-
|
|
7
|
-
This AWS CDK application deploys a highly available, auto-scaling webhook processor using:
|
|
8
|
-
|
|
9
|
-
- **Amazon API Gateway** → Routes HTTPS webhooks with IP-based access control
|
|
10
|
-
- **Application Load Balancer (ALB)** → Distributes traffic across container instances
|
|
11
|
-
- **AWS Fargate on Amazon ECS** → Runs containerized webhook processor (auto-scales 2-10 tasks)
|
|
12
|
-
- **Amazon S3** → Stores webhook payloads and package data
|
|
13
|
-
- **Amazon SQS** → Queues package creation requests for Quilt
|
|
14
|
-
- **AWS Secrets Manager** → Securely stores Benchling OAuth credentials
|
|
15
|
-
- **Amazon CloudWatch** → Provides centralized logging and monitoring
|
|
16
|
-
- **AWS IAM** → Enforces least-privilege access controls
|
|
17
|
-
|
|
18
|
-
**Request Flow:** Benchling → API Gateway → ALB → Fargate (Flask app) → S3 + SQS
|
|
19
|
-
|
|
20
|
-
### Code Organization
|
|
21
|
-
|
|
22
|
-
- **Infrastructure (CDK)**: `bin/` and `lib/` contain TypeScript CDK code for AWS deployment
|
|
23
|
-
- `lib/benchling-webhook-stack.ts` - Main stack orchestrating all components
|
|
24
|
-
- `lib/fargate-service.ts` - ECS Fargate service running Flask in Docker
|
|
25
|
-
- `lib/alb-api-gateway.ts` - API Gateway with HTTP integration to ALB
|
|
26
|
-
- `lib/ecr-repository.ts` - Docker image repository
|
|
27
|
-
- **Application (Python)**: `docker/` contains Flask webhook processor
|
|
28
|
-
- See [docker/README.md](docker/README.md) for application development
|
|
29
|
-
|
|
30
|
-
## Prerequisites
|
|
31
|
-
|
|
32
|
-
- **AWS Account** with appropriate IAM permissions
|
|
33
|
-
- **AWS CLI** v2.x configured with credentials
|
|
34
|
-
- **Node.js** >= 18.0.0
|
|
35
|
-
- **Docker** for container builds
|
|
36
|
-
- **Quilt Stack** deployed with S3 bucket and SQS queue configured
|
|
37
|
-
- **Benchling Account** with app creation permissions
|
|
38
|
-
|
|
39
|
-
## Installation
|
|
40
|
-
|
|
41
|
-
### 1. Clone and Install
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
git clone https://github.com/quiltdata/benchling-webhook.git
|
|
45
|
-
cd benchling-webhook
|
|
46
|
-
npm install
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
### 2. Configure Environment
|
|
50
|
-
|
|
51
|
-
#### Option A: Auto-infer from Quilt Catalog (Recommended)
|
|
52
|
-
|
|
53
|
-
If you have an existing Quilt deployment, you can automatically infer most configuration values:
|
|
54
|
-
|
|
55
|
-
```bash
|
|
56
|
-
# Infer config from your Quilt catalog
|
|
57
|
-
npm run get-env -- https://quilt-catalog.yourcompany.com --write
|
|
58
|
-
|
|
59
|
-
# Review the generated env.inferred file
|
|
60
|
-
cat env.inferred
|
|
61
|
-
|
|
62
|
-
# Copy to .env and fill in Benchling credentials
|
|
63
|
-
cp env.inferred .env
|
|
64
|
-
# Then edit .env to add your Benchling-specific values
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
The script will:
|
|
68
|
-
|
|
69
|
-
- Fetch `config.json` from your Quilt catalog
|
|
70
|
-
- Query AWS CloudFormation to find your Quilt stack
|
|
71
|
-
- Extract bucket names, queue names, region, and account ID
|
|
72
|
-
- Generate a `.env.inferred` file with pre-filled AWS/Quilt configuration
|
|
73
|
-
|
|
74
|
-
**Note:** You'll still need to manually add Benchling credentials (tenant, client ID, client secret, etc.).
|
|
75
|
-
|
|
76
|
-
#### Option B: Manual Configuration
|
|
77
|
-
|
|
78
|
-
```bash
|
|
79
|
-
cp env.template .env
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
Edit `.env` with your configuration:
|
|
83
|
-
|
|
84
|
-
**Required Variables** (you must provide these):
|
|
85
|
-
|
|
86
|
-
| Variable | Description |
|
|
87
|
-
|----------|-------------|
|
|
88
|
-
| `QUILT_CATALOG` | Quilt catalog URL (e.g., `quilt-catalog.yourcompany.com`) |
|
|
89
|
-
| `QUILT_USER_BUCKET` | Your S3 bucket for Benchling exports |
|
|
90
|
-
| `BENCHLING_TENANT` | Benchling subdomain (e.g., `myorg` from `myorg.benchling.com`) |
|
|
91
|
-
| `BENCHLING_CLIENT_ID` | OAuth client ID from Benchling app |
|
|
92
|
-
| `BENCHLING_CLIENT_SECRET` | OAuth client secret from Benchling app |
|
|
93
|
-
| `BENCHLING_APP_DEFINITION_ID` | App definition ID for webhook verification |
|
|
94
|
-
|
|
95
|
-
**Auto-Inferred Variables** (automatically determined from your Quilt catalog):
|
|
96
|
-
|
|
97
|
-
| Variable | How It's Inferred |
|
|
98
|
-
|----------|-------------------|
|
|
99
|
-
| `CDK_DEFAULT_ACCOUNT` | From AWS STS (your current account) |
|
|
100
|
-
| `CDK_DEFAULT_REGION` | From catalog config.json |
|
|
101
|
-
| `QUEUE_NAME` | From Quilt stack outputs |
|
|
102
|
-
| `SQS_QUEUE_URL` | From Quilt stack outputs |
|
|
103
|
-
| `QUILT_DATABASE` | From Quilt stack outputs |
|
|
104
|
-
|
|
105
|
-
**Optional Variables** (have sensible defaults):
|
|
106
|
-
|
|
107
|
-
| Variable | Default | Description |
|
|
108
|
-
|----------|---------|-------------|
|
|
109
|
-
| `PKG_PREFIX` | `benchling` | Quilt package name prefix |
|
|
110
|
-
| `PKG_KEY` | `experiment_id` | Metadata key for linking entries to packages |
|
|
111
|
-
| `LOG_LEVEL` | `INFO` | Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
|
|
112
|
-
| `ENABLE_WEBHOOK_VERIFICATION` | `true` | Verify webhook signatures |
|
|
113
|
-
| `WEBHOOK_ALLOW_LIST` | (empty) | Comma-separated IP allowlist |
|
|
114
|
-
| `ECR_REPOSITORY_NAME` | `quiltdata/benchling` | Custom ECR repo name |
|
|
115
|
-
|
|
116
|
-
See [doc/PARAMETERS.md](doc/PARAMETERS.md) for complete reference.
|
|
117
|
-
|
|
118
|
-
### 3. Deploy Infrastructure
|
|
119
|
-
|
|
120
|
-
```bash
|
|
121
|
-
# Bootstrap CDK (first time only)
|
|
122
|
-
source .env
|
|
123
|
-
npx cdk bootstrap aws://$CDK_DEFAULT_ACCOUNT/$CDK_DEFAULT_REGION
|
|
124
|
-
|
|
125
|
-
# Deploy stack
|
|
126
|
-
npm run deploy
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
The webhook URL will be saved to `.env.deploy`:
|
|
130
|
-
|
|
131
|
-
```bash
|
|
132
|
-
WEBHOOK_ENDPOINT=https://abc123.execute-api.us-east-1.amazonaws.com/prod
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
## Post-Deployment Configuration
|
|
136
|
-
|
|
137
|
-
### Configure Benchling App
|
|
138
|
-
|
|
139
|
-
1. **Create App**: Benchling → Developer Console → Apps → Create app → From manifest
|
|
140
|
-
2. **Upload Manifest**: Use `app-manifest.yaml` from this repository
|
|
141
|
-
3. **Set Credentials**: Create Client Secret → Copy ID and Secret to `.env`
|
|
142
|
-
4. **Configure Webhook**: Overview → Webhook URL → Paste URL from `.env.deploy`
|
|
143
|
-
5. **Install App**: Version History → Install → Activate
|
|
144
|
-
6. **Grant Permissions**: Tenant Admin → Organizations → Apps → Add app → Set role to Admin
|
|
145
|
-
|
|
146
|
-
### Verify Deployment
|
|
147
|
-
|
|
148
|
-
```bash
|
|
149
|
-
# Health check
|
|
150
|
-
source .env.deploy
|
|
151
|
-
curl $WEBHOOK_ENDPOINT/health
|
|
152
|
-
|
|
153
|
-
# Monitor logs
|
|
154
|
-
aws logs tail /ecs/benchling-webhook --follow
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
## Usage
|
|
158
|
-
|
|
159
|
-
1. **Create Entry** in Benchling notebook
|
|
160
|
-
2. **Insert Canvas** → Select "Quilt Integration"
|
|
161
|
-
3. **Create Package** → Generates versioned Quilt package
|
|
162
|
-
4. **Add Files** → Attach experimental data
|
|
163
|
-
5. **Update Package** → Creates new version with attachments
|
|
164
|
-
|
|
165
|
-
## Development
|
|
166
|
-
|
|
167
|
-
### Common Commands
|
|
168
|
-
|
|
169
|
-
**Development:**
|
|
170
|
-
- `npm run build` - Compile TypeScript
|
|
171
|
-
- `npm run test` - Run Jest tests
|
|
172
|
-
- `npm run lint` - Apply ESLint
|
|
173
|
-
|
|
174
|
-
**Deployment:**
|
|
175
|
-
- `npm run deploy` - Test + deploy (outputs to `.env.deploy`)
|
|
176
|
-
- `npm run docker-push` - Build and push Docker images
|
|
177
|
-
- `npm run docker-check` - Validate Docker images
|
|
178
|
-
- `npm run release` - Create production release
|
|
179
|
-
|
|
180
|
-
**Python App:**
|
|
181
|
-
- See [docker/README.md](docker/README.md) or run `make help` in docker/ directory
|
|
182
|
-
|
|
183
|
-
### Coding Style
|
|
184
|
-
|
|
185
|
-
- **TypeScript**: 4-space indent, double quotes, trailing commas, required semicolons
|
|
186
|
-
- **Types**: Avoid `any` in production; explicit return types on exports
|
|
187
|
-
- **Organization**: Separate CDK constructs in `lib/`; application code in `docker/`
|
|
188
|
-
|
|
189
|
-
### Commits & PRs
|
|
190
|
-
|
|
191
|
-
- Use Conventional Commits: `type(scope): summary`
|
|
192
|
-
- Keep commits focused; update `package-lock.json` when needed
|
|
193
|
-
- Include test results and deployment considerations in PRs
|
|
194
|
-
|
|
195
|
-
## Security Best Practices
|
|
196
|
-
|
|
197
|
-
- OAuth credentials stored in AWS Secrets Manager
|
|
198
|
-
- IP-based access control via API Gateway resource policies
|
|
199
|
-
- Container images scanned for vulnerabilities via Amazon ECR
|
|
200
|
-
- IAM roles follow least-privilege principle
|
|
201
|
-
- All traffic encrypted in transit (TLS 1.2+)
|
|
202
|
-
- CloudWatch logs encrypted at rest
|
|
203
|
-
|
|
204
|
-
## Monitoring & Troubleshooting
|
|
205
|
-
|
|
206
|
-
### Monitoring
|
|
207
|
-
|
|
208
|
-
- **CloudWatch Logs**: `/ecs/benchling-webhook`
|
|
209
|
-
- **ECS Task Metrics**: CPU, memory, task count
|
|
210
|
-
- **API Gateway Metrics**: Request count, latency, 4XX/5XX errors
|
|
211
|
-
- **ALB Target Health**: Monitor unhealthy targets
|
|
212
|
-
|
|
213
|
-
### Health Endpoints
|
|
214
|
-
|
|
215
|
-
- `/health` - General health check
|
|
216
|
-
- `/health/ready` - Readiness probe
|
|
217
|
-
|
|
218
|
-
### Debugging
|
|
219
|
-
|
|
220
|
-
- **Deployment**: Check `.env.deploy` for outputs
|
|
221
|
-
- **Logs**: `npm run logs` or `aws logs tail /ecs/benchling-webhook --follow`
|
|
222
|
-
- **Events**: `npm run event` to send test events
|
|
223
|
-
|
|
224
|
-
## License
|
|
225
|
-
|
|
226
|
-
Apache-2.0 - See [LICENSE](LICENSE) file for details
|
package/CHANGELOG.md
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
<!-- markdownlint-disable MD024 -->
|
|
2
|
-
# Changelog
|
|
3
|
-
|
|
4
|
-
All notable changes to this project will be documented in this file.
|
|
5
|
-
|
|
6
|
-
## [Unreleased]
|
|
7
|
-
|
|
8
|
-
## [0.4.13] - 2025-10-28
|
|
9
|
-
|
|
10
|
-
### Changed
|
|
11
|
-
|
|
12
|
-
- **Simplified configuration**: Auto-infer AWS and Quilt config from catalog at deployment time
|
|
13
|
-
- **Reduced required .env variables**: From 20+ to just 6 (catalog URL, user bucket, 4 Benchling credentials)
|
|
14
|
-
- **Renamed `BUCKET_NAME` → `QUILT_USER_BUCKET`**: Clearer distinction between user data bucket and Quilt system buckets
|
|
15
|
-
- **Added CDK bootstrap validation**: Fails fast with helpful error if account/region not bootstrapped
|
|
16
|
-
- **Made LOG_LEVEL configurable**: Override default INFO level for production debugging
|
|
17
|
-
|
|
18
|
-
### Removed
|
|
19
|
-
|
|
20
|
-
- Unused environment variables: `BENCHLING_API_KEY`, `PKG_BUCKET_ONLY`, `PREFIX`, `STAGE`, `FLASK_ENV`
|
|
21
|
-
|
|
22
|
-
### Fixed
|
|
23
|
-
|
|
24
|
-
- Module import issue: CLI argument parsing now only runs when executed directly, not on import
|
|
25
|
-
|
|
26
|
-
## [0.4.12] - 2025-10-27
|
|
27
|
-
|
|
28
|
-
### Added
|
|
29
|
-
|
|
30
|
-
- Dev release workflow with timestamped pre-release tags for testing CI/CD pipeline
|
|
31
|
-
|
|
32
|
-
### Changed
|
|
33
|
-
|
|
34
|
-
- Refactored release script to separate version bumping from tag creation
|
|
35
|
-
- version.js now outputs just the version number when called with no arguments
|
|
36
|
-
|
|
37
|
-
## [0.4.11] - 2025-10-27
|
|
38
|
-
|
|
39
|
-
### Added
|
|
40
|
-
|
|
41
|
-
- Version synchronization test to ensure package.json, docker/pyproject.toml, and docker/app-manifest.yaml remain in sync
|
|
42
|
-
- app-manifest.yaml now published as GitHub release asset for Benchling App installations
|
|
43
|
-
|
|
44
|
-
### Fixed
|
|
45
|
-
|
|
46
|
-
- Version bump script (bin/version.js) now updates all three version files instead of just package.json
|
|
47
|
-
- `docker-validate` target now validates ECR repository is publicly accessible without authentication
|
|
48
|
-
- `docker-validate` reads Docker image URI from `cdk-outputs.json` instead of requiring version parameter
|
|
49
|
-
- `docker-validate` will fail if repository requires authentication, ensuring public access is maintained
|
|
50
|
-
|
|
51
|
-
## [0.4.10] - 2025-10-27
|
|
52
|
-
|
|
53
|
-
### Added
|
|
54
|
-
|
|
55
|
-
- Canvas error notification section to display warnings and errors to users
|
|
56
|
-
- Athena permissions (StartQueryExecution, GetQueryExecution, GetQueryResults) to ECS task role
|
|
57
|
-
- Glue Data Catalog permissions for Athena queries
|
|
58
|
-
- S3 permissions for Athena query results bucket
|
|
59
|
-
- Test event file for Athena access denied scenario
|
|
60
|
-
|
|
61
|
-
### Fixed
|
|
62
|
-
|
|
63
|
-
- Canvas now displays error notifications instead of failing silently when PackageQuery encounters AWS permission issues
|
|
64
|
-
- Improved error messages for Athena AccessDeniedException with actionable guidance
|
|
65
|
-
|
|
66
|
-
## [0.4.9] - 2025-10-27
|
|
67
|
-
|
|
68
|
-
### Added
|
|
69
|
-
|
|
70
|
-
- Integrated release workflow into CI pipeline for automated GitHub releases, Docker image publishing, and NPM package publishing
|
|
71
|
-
- Support for both production and pre-release (dev) versions
|
|
72
|
-
|
|
73
|
-
### Changed
|
|
74
|
-
|
|
75
|
-
- Updated Python to 3.14 in CI workflows
|
|
76
|
-
- Updated aws-actions/configure-aws-credentials to v5
|
|
77
|
-
- Updated actions/setup-python to v6
|
|
78
|
-
- Streamlined release process with automated tagging and publishing
|
|
79
|
-
|
|
80
|
-
## [0.4.8] - 2025-10-27
|
|
81
|
-
|
|
82
|
-
### Changed
|
|
83
|
-
|
|
84
|
-
- **Infrastructure Migration** - Migrated from Lambda to Docker/Fargate for improved scalability and resource management
|
|
85
|
-
- **Improved Deployment** - Streamlined Docker-based deployment workflow with health checks and automated verification
|
|
86
|
-
- **Enhanced Testing** - Added comprehensive test commands for local development and CI/CD workflows
|
|
87
|
-
|
|
88
|
-
### Fixed
|
|
89
|
-
|
|
90
|
-
- Resolved CloudFormation deployment conflicts during stack updates
|
|
91
|
-
- Ensured ECR repository exists before Docker push in CI
|
package/bin/benchling-webhook.ts
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import "dotenv/config";
|
|
3
|
-
import * as cdk from "aws-cdk-lib";
|
|
4
|
-
import { BenchlingWebhookStack } from "../lib/benchling-webhook-stack";
|
|
5
|
-
|
|
6
|
-
// Import get-env to infer configuration from catalog
|
|
7
|
-
const { inferStackConfig } = require("./get-env.js");
|
|
8
|
-
const { execSync } = require("child_process");
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Check if CDK is bootstrapped for the given account/region
|
|
12
|
-
*/
|
|
13
|
-
async function checkCdkBootstrap(account: string, region: string): Promise<void> {
|
|
14
|
-
try {
|
|
15
|
-
console.log(`Checking CDK bootstrap for account ${account} in ${region}...`);
|
|
16
|
-
|
|
17
|
-
// Check if bootstrap stack exists
|
|
18
|
-
const result = execSync(
|
|
19
|
-
`aws cloudformation describe-stacks --region ${region} --stack-name CDKToolkit --query "Stacks[0].StackStatus" --output text 2>&1`,
|
|
20
|
-
{ encoding: "utf-8" }
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
const stackStatus = result.trim();
|
|
24
|
-
|
|
25
|
-
if (stackStatus.includes("does not exist") || stackStatus.includes("ValidationError")) {
|
|
26
|
-
console.error("\n❌ CDK Bootstrap Error");
|
|
27
|
-
console.error("=".repeat(80));
|
|
28
|
-
console.error(`CDK is not bootstrapped for account ${account} in region ${region}`);
|
|
29
|
-
console.error("\nTo bootstrap CDK, run:");
|
|
30
|
-
console.error(` npx cdk bootstrap aws://${account}/${region}`);
|
|
31
|
-
console.error("\nOr source your .env and run:");
|
|
32
|
-
console.error(` source .env`);
|
|
33
|
-
console.error(` npx cdk bootstrap aws://\${CDK_DEFAULT_ACCOUNT}/\${CDK_DEFAULT_REGION}`);
|
|
34
|
-
console.error("=".repeat(80));
|
|
35
|
-
process.exit(1);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Check if the stack is in a good state
|
|
39
|
-
if (!stackStatus.includes("COMPLETE")) {
|
|
40
|
-
console.error("\n⚠️ CDK Bootstrap Warning");
|
|
41
|
-
console.error("=".repeat(80));
|
|
42
|
-
console.error(`CDKToolkit stack is in state: ${stackStatus}`);
|
|
43
|
-
console.error("This may cause deployment issues.");
|
|
44
|
-
console.error("=".repeat(80));
|
|
45
|
-
} else {
|
|
46
|
-
console.log(`✓ CDK is bootstrapped (CDKToolkit stack: ${stackStatus})\n`);
|
|
47
|
-
}
|
|
48
|
-
} catch (error) {
|
|
49
|
-
console.error("\n⚠️ Warning: Could not verify CDK bootstrap status");
|
|
50
|
-
console.error(`Error: ${(error as Error).message}`);
|
|
51
|
-
console.error("\nProceeding anyway, but deployment may fail if CDK is not bootstrapped.\n");
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Get environment configuration with catalog inference
|
|
57
|
-
*
|
|
58
|
-
* This combines user-provided values from .env with inferred values from the Quilt catalog.
|
|
59
|
-
* User values always take precedence over inferred values.
|
|
60
|
-
*/
|
|
61
|
-
async function getConfig() {
|
|
62
|
-
const userEnv = process.env;
|
|
63
|
-
let inferredEnv: Record<string, string> = {};
|
|
64
|
-
|
|
65
|
-
// If QUILT_CATALOG is provided, try to infer additional configuration
|
|
66
|
-
if (userEnv.QUILT_CATALOG) {
|
|
67
|
-
try {
|
|
68
|
-
console.log(`Inferring configuration from catalog: ${userEnv.QUILT_CATALOG}`);
|
|
69
|
-
const result = await inferStackConfig(`https://${userEnv.QUILT_CATALOG.replace(/^https?:\/\//, '')}`);
|
|
70
|
-
inferredEnv = result.inferredVars;
|
|
71
|
-
console.log("✓ Successfully inferred stack configuration\n");
|
|
72
|
-
} catch (error) {
|
|
73
|
-
console.error(`Warning: Could not infer configuration from catalog: ${(error as Error).message}`);
|
|
74
|
-
console.error("Falling back to environment variables only.\n");
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Merge: user env takes precedence over inferred values
|
|
79
|
-
const config = { ...inferredEnv, ...userEnv };
|
|
80
|
-
|
|
81
|
-
// Validate required user-provided values
|
|
82
|
-
const requiredUserVars = [
|
|
83
|
-
"QUILT_CATALOG",
|
|
84
|
-
"QUILT_USER_BUCKET",
|
|
85
|
-
"BENCHLING_CLIENT_ID",
|
|
86
|
-
"BENCHLING_CLIENT_SECRET",
|
|
87
|
-
"BENCHLING_TENANT",
|
|
88
|
-
];
|
|
89
|
-
|
|
90
|
-
const missingVars = requiredUserVars.filter((varName) => !config[varName]);
|
|
91
|
-
|
|
92
|
-
if (missingVars.length > 0) {
|
|
93
|
-
console.error("Error: Missing required environment variables:");
|
|
94
|
-
missingVars.forEach((varName) => {
|
|
95
|
-
console.error(` - ${varName}`);
|
|
96
|
-
});
|
|
97
|
-
console.error("\nPlease set these variables in your .env file.");
|
|
98
|
-
console.error("See env.template for guidance.");
|
|
99
|
-
process.exit(1);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Validate inferred values are present (should be available if catalog lookup succeeded)
|
|
103
|
-
const requiredInferredVars = [
|
|
104
|
-
"CDK_DEFAULT_ACCOUNT",
|
|
105
|
-
"CDK_DEFAULT_REGION",
|
|
106
|
-
"QUEUE_NAME",
|
|
107
|
-
"SQS_QUEUE_URL",
|
|
108
|
-
"QUILT_DATABASE",
|
|
109
|
-
];
|
|
110
|
-
|
|
111
|
-
const missingInferredVars = requiredInferredVars.filter((varName) => !config[varName]);
|
|
112
|
-
|
|
113
|
-
if (missingInferredVars.length > 0) {
|
|
114
|
-
console.error("Error: Could not infer required configuration:");
|
|
115
|
-
missingInferredVars.forEach((varName) => {
|
|
116
|
-
console.error(` - ${varName}`);
|
|
117
|
-
});
|
|
118
|
-
console.error("\nThese values should be automatically inferred from your Quilt catalog.");
|
|
119
|
-
console.error("Please ensure:");
|
|
120
|
-
console.error(" 1. QUILT_CATALOG is set correctly");
|
|
121
|
-
console.error(" 2. Your AWS credentials have CloudFormation read permissions");
|
|
122
|
-
console.error(" 3. The Quilt stack is deployed and accessible");
|
|
123
|
-
console.error("\nAlternatively, you can manually set these values in your .env file.");
|
|
124
|
-
process.exit(1);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// Validate conditional requirements
|
|
128
|
-
if (config.ENABLE_WEBHOOK_VERIFICATION !== "false" && !config.BENCHLING_APP_DEFINITION_ID) {
|
|
129
|
-
console.error("Error: BENCHLING_APP_DEFINITION_ID is required when webhook verification is enabled.");
|
|
130
|
-
console.error("Either set BENCHLING_APP_DEFINITION_ID or set ENABLE_WEBHOOK_VERIFICATION=false");
|
|
131
|
-
process.exit(1);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return config;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Main execution
|
|
139
|
-
*/
|
|
140
|
-
async function main() {
|
|
141
|
-
const config = await getConfig();
|
|
142
|
-
|
|
143
|
-
// Validate CDK bootstrap before proceeding
|
|
144
|
-
await checkCdkBootstrap(config.CDK_DEFAULT_ACCOUNT!, config.CDK_DEFAULT_REGION!);
|
|
145
|
-
|
|
146
|
-
const app = new cdk.App();
|
|
147
|
-
new BenchlingWebhookStack(app, "BenchlingWebhookStack", {
|
|
148
|
-
env: {
|
|
149
|
-
account: config.CDK_DEFAULT_ACCOUNT,
|
|
150
|
-
region: config.CDK_DEFAULT_REGION,
|
|
151
|
-
},
|
|
152
|
-
bucketName: config.QUILT_USER_BUCKET!, // User's data bucket
|
|
153
|
-
queueName: config.QUEUE_NAME!,
|
|
154
|
-
environment: "production",
|
|
155
|
-
prefix: config.PKG_PREFIX || "benchling",
|
|
156
|
-
benchlingClientId: config.BENCHLING_CLIENT_ID!,
|
|
157
|
-
benchlingClientSecret: config.BENCHLING_CLIENT_SECRET!,
|
|
158
|
-
benchlingTenant: config.BENCHLING_TENANT!,
|
|
159
|
-
quiltCatalog: config.QUILT_CATALOG!,
|
|
160
|
-
quiltDatabase: config.QUILT_DATABASE!,
|
|
161
|
-
webhookAllowList: config.WEBHOOK_ALLOW_LIST,
|
|
162
|
-
logLevel: config.LOG_LEVEL || "INFO",
|
|
163
|
-
// ECR repository configuration
|
|
164
|
-
createEcrRepository: config.CREATE_ECR_REPOSITORY === "true",
|
|
165
|
-
ecrRepositoryName: config.ECR_REPOSITORY_NAME || "quiltdata/benchling",
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
main().catch((error) => {
|
|
170
|
-
console.error("Fatal error during CDK synthesis:", error);
|
|
171
|
-
process.exit(1);
|
|
172
|
-
});
|
package/bin/cli-auth.sh
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Ensure environment variables are set
|
|
4
|
-
if [[ -z "$BENCHLING_CLIENT_ID" || -z "$BENCHLING_TENANT" || -z "$BENCHLING_CLIENT_SECRET" ]]; then
|
|
5
|
-
echo "Error: Required environment variables are not set. Please source .env first."
|
|
6
|
-
exit 1
|
|
7
|
-
fi
|
|
8
|
-
|
|
9
|
-
# Debugging: Print the extracted values
|
|
10
|
-
echo "BENCHLING_CLIENT_ID: $BENCHLING_CLIENT_ID"
|
|
11
|
-
echo "BENCHLING_TENANT: $BENCHLING_TENANT"
|
|
12
|
-
|
|
13
|
-
API_ROOT="https://${BENCHLING_TENANT}.benchling.com/api/v2"
|
|
14
|
-
|
|
15
|
-
# Function to get OAuth Token
|
|
16
|
-
get_token() {
|
|
17
|
-
curl -s -X POST "$API_ROOT/token" \
|
|
18
|
-
-H "Content-Type: application/x-www-form-urlencoded" \
|
|
19
|
-
-d "client_id=${BENCHLING_CLIENT_ID}" \
|
|
20
|
-
-d "client_secret=${BENCHLING_CLIENT_SECRET}" \
|
|
21
|
-
-d "grant_type=client_credentials" | jq -r '.access_token'
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
# Generic function to make API requests
|
|
25
|
-
api_request() {
|
|
26
|
-
local method=$1
|
|
27
|
-
local endpoint=$2
|
|
28
|
-
local data=$3
|
|
29
|
-
|
|
30
|
-
curl -v -X "$method" "$API_ROOT/$endpoint" \
|
|
31
|
-
-H "Authorization: Bearer $TOKEN" \
|
|
32
|
-
-H "Content-Type: application/json" \
|
|
33
|
-
${data:+--data "$data"}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
# Get OAuth Token
|
|
37
|
-
TOKEN=$(get_token)
|
|
38
|
-
|
|
39
|
-
# Export TOKEN globally
|
|
40
|
-
export TOKEN
|
|
41
|
-
|
|
42
|
-
# Debugging: Print the token
|
|
43
|
-
if [[ -z "$TOKEN" || "$TOKEN" == "null" ]]; then
|
|
44
|
-
echo "Error: Failed to retrieve access token."
|
|
45
|
-
exit 1
|
|
46
|
-
fi
|
|
47
|
-
echo "TOKEN: $TOKEN"
|
|
48
|
-
|
|
49
|
-
# Check if CANVAS_ID is provided as an argument
|
|
50
|
-
if [[ -n "$1" ]]; then
|
|
51
|
-
CANVAS_ID="$1"
|
|
52
|
-
echo "Fetching canvas with ID: $CANVAS_ID"
|
|
53
|
-
echo "=== $CANVAS_ID ==="
|
|
54
|
-
api_request "GET" "app-canvases/${CANVAS_ID}"
|
|
55
|
-
echo "=== $CANVAS_ID ==="
|
|
56
|
-
|
|
57
|
-
echo "Updating canvas with ID: $CANVAS_ID"
|
|
58
|
-
api_request "PATCH" "app-canvases/${CANVAS_ID}" '{
|
|
59
|
-
"blocks": [
|
|
60
|
-
{
|
|
61
|
-
"enabled": true,
|
|
62
|
-
"id": "user_defined_id",
|
|
63
|
-
"text": "Click me to submit",
|
|
64
|
-
"type": "BUTTON"
|
|
65
|
-
}
|
|
66
|
-
],
|
|
67
|
-
"enabled": true,
|
|
68
|
-
"featureId": "quilt_integration"
|
|
69
|
-
}'
|
|
70
|
-
|
|
71
|
-
else
|
|
72
|
-
echo "No canvas ID provided. Fetching apps instead."
|
|
73
|
-
api_request "GET" "apps"
|
|
74
|
-
fi
|