Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app-manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ info:
name: package-with-quilt
description: Uses Quilt Package Engine
version: 0.2.0
features:
- name: Quilt Integration
id: quilt_integration
type: CANVAS
subscriptions:
deliveryMethod: WEBHOOK
messages:
- type: v2-beta.app.configuration.updated
- type: v2.app.activateRequested
- type: v2.app.deactivated
- type: v2.app.installed
- type: v2-beta.canvas.created
- type: v2-beta.app.configuration.updated
- type: v2.canvas.initialized
- type: v2.canvas.userInteracted
- type: v2-beta.canvas.created
- type: v2.entity.registered
- type: v2.entry.created
- type: v2.entry.updated.fields
Expand Down
1 change: 0 additions & 1 deletion bin/benchling-webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ new BenchlingWebhookStack(app, "BenchlingWebhookStack", {
prefix: process.env.PREFIX || "benchling",
benchlingClientId: process.env.BENCHLING_CLIENT_ID || "",
benchlingClientSecret: process.env.BENCHLING_CLIENT_SECRET || "",
benchlingTenant: process.env.BENCHLING_TENANT || "",
});
5 changes: 1 addition & 4 deletions lib/benchling-webhook-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ interface BenchlingWebhookStackProps extends cdk.StackProps {
readonly queueName: string;
readonly benchlingClientId: string;
readonly benchlingClientSecret: string;
readonly benchlingTenant: string;
}

export class BenchlingWebhookStack extends cdk.Stack {
Expand Down Expand Up @@ -73,7 +72,6 @@ export class BenchlingWebhookStack extends cdk.Stack {
region: this.region,
account: this.account,
benchlingConnection,
benchlingTenant: props.benchlingTenant,
exportProcessor: this.exportProcessor,
});

Expand All @@ -93,8 +91,7 @@ export class BenchlingWebhookStack extends cdk.Stack {
authorizationType: "OAUTH_CLIENT_CREDENTIALS",
authParameters: {
oAuthParameters: {
authorizationEndpoint:
`https://${props.benchlingTenant}.benchling.com/api/v2/token`,
authorizationEndpoint: "https://benchling.com/api/v2/token",
clientParameters: {
clientId: props.benchlingClientId,
clientSecret: props.benchlingClientSecret,
Expand Down
44 changes: 38 additions & 6 deletions lib/state-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,51 @@ export class WebhookStateMachine extends Construct {
private createDefinition(
props: StateMachineProps,
): stepfunctions.IChainable {
const setupVariablesTask = new stepfunctions.Pass(
const initialSetupTask = new stepfunctions.Pass(
this,
"SetupVariables",
"InitialSetup",
{
parameters: {
"baseURL": `https://${props.benchlingTenant}.benchling.com`,
"baseURL.$": "$.message.baseURL",
"typeFields.$": "States.StringSplit($.message.type, '.')",
"channel.$": "$.channel",
},
resultPath: "$.var",
},
);

const echoTask = new stepfunctions.Pass(this, "Echo", {
parameters: {
"input.$": "$",
"message": "Channel is not 'events', echoing input",
},
});

const channelChoice = new stepfunctions.Choice(this, "CheckChannel")
.when(
stepfunctions.Condition.stringEquals("$.var.channel", "events"),
this.createEventProcessingChain(props)
)
.otherwise(echoTask);

// Main workflow
return initialSetupTask.next(channelChoice);
}

private createEventProcessingChain(props: StateMachineProps): stepfunctions.IChainable {
const setupEventVariablesTask = new stepfunctions.Pass(
this,
"SetupEventVariables",
{
parameters: {
"baseURL.$": "$.var.baseURL",
"entity.$": "$.message.resourceId",
"packageName.$":
`States.Format('${props.prefix}/{}', $.message.resourceId)`,
"readme": README_TEMPLATE,
"registry": props.bucket.bucketName,
"typeFields.$": "States.StringSplit($.message.type, '.')",
"typeFields.$": "$.var.typeFields",
"channel.$": "$.var.channel",
},
resultPath: "$.var",
},
Expand Down Expand Up @@ -153,8 +186,7 @@ export class WebhookStateMachine extends Construct {
}),
);

// Main workflow
return setupVariablesTask
return setupEventVariablesTask
.next(fetchEntryTask)
.next(exportTask)
.next(pollExportTask)
Expand Down
1 change: 0 additions & 1 deletion lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export interface StateMachineProps {
region: string;
account: string;
benchlingConnection: events.CfnConnection;
benchlingTenant: string;
exportProcessor: lambda.IFunction;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"clean": "rm -rf cdk.out */{*.js,*.d.ts}",
"test": "NODE_ENV=test node --max-old-space-size=4096 ./node_modules/.bin/jest",
"cdk": "cdk",
"cdk": "npm run test && npx cdk deploy --require-approval never",
"lint": "eslint . --ext .ts --fix"
},
"devDependencies": {
Expand Down
17 changes: 17 additions & 0 deletions test/app-installed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"app": {
"id": "app_qdSsffBWrLoTVId4"
},
"appDefinition": {
"id": "appdef_mI4jtZESUi",
"versionNumber": "0.2.0"
},
"baseURL": "https://quilt-dtt.benchling.com",
"channel": "app_signals",
"message": {
"deprecated": false,
"type": "v2.app.installed"
},
"tenantId": "ten_dsrealahhb",
"version": "0"
}
4 changes: 1 addition & 3 deletions test/benchling-webhook-stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ describe("BenchlingWebhookStack", () => {
queueName: "test-queue",
benchlingClientId: "test-client-id",
benchlingClientSecret: "test-client-secret",
benchlingTenant: "test-tenant",
});
template = Template.fromStack(stack);
});
Expand All @@ -24,7 +23,7 @@ describe("BenchlingWebhookStack", () => {
AuthorizationType: "OAUTH_CLIENT_CREDENTIALS",
AuthParameters: {
OAuthParameters: {
AuthorizationEndpoint: "https://test-tenant.benchling.com/api/v2/token",
AuthorizationEndpoint: "https://benchling.com/api/v2/token",
HttpMethod: "POST",
},
},
Expand Down Expand Up @@ -109,7 +108,6 @@ describe("BenchlingWebhookStack", () => {
queueName: "test-queue",
benchlingClientId: "test-client-id",
benchlingClientSecret: "test-client-secret",
benchlingTenant: "test-tenant",
});
}).toThrow("Prefix should not contain a '/' character.");
});
Expand Down
19 changes: 19 additions & 0 deletions test/canvas-created.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"app": {
"id": "app_qdSsffBWrLoTVId4"
},
"appDefinition": {
"id": "appdef_mI4jtZESUi",
"versionNumber": "0.2.0"
},
"baseURL": "https://quilt-dtt.benchling.com",
"channel": "app_signals",
"message": {
"canvasId": "cnvs_fDbhxhuD",
"deprecated": false,
"featureId": "quilt_integration",
"type": "v2-beta.canvas.created"
},
"tenantId": "ten_dsrealahhb",
"version": "0"
}
1 change: 0 additions & 1 deletion test/state-machine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ describe("WebhookStateMachine", () => {
region: "us-west-2",
account: "123456789012",
benchlingConnection,
benchlingTenant: "test-tenant",
exportProcessor: new lambda.Function(stack, "TestExportProcessor", {
runtime: lambda.Runtime.NODEJS_16_X,
handler: "index.handler",
Expand Down