Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapshot Webhook Update #9589

Merged
merged 2 commits into from
Oct 18, 2024
Merged
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
4 changes: 1 addition & 3 deletions libs/adapters/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,7 @@ export const config = configure(
})
.refine(
(data) => {
if (
!['local', 'CI', 'discobot', 'snapshot'].includes(target.APP_ENV)
) {
if (!['local', 'CI'].includes(target.APP_ENV)) {
return (
!!LOAD_TESTING_AUTH_TOKEN &&
data.AUTH_TOKEN !== DEFAULTS.LOAD_TESTING_AUTH_TOKEN
Expand Down
2 changes: 0 additions & 2 deletions libs/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ const AppEnvironments = [
'beta',
'demo',
'production',
'discobot',
'snapshot',
] as const;
type Environment = (typeof Environments)[number];
type AppEnvironment = (typeof AppEnvironments)[number];
Expand Down
12 changes: 12 additions & 0 deletions packages/commonwealth/server/api/integration-router.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { express } from '@hicommonwealth/adapters';
import { AppError } from '@hicommonwealth/core';
import { ChainEvents, Snapshot } from '@hicommonwealth/model';
import { Router, raw } from 'express';
import { config } from '../config';

const PATH = '/api/integration';

Expand All @@ -26,6 +28,16 @@ function build() {

router.post(
'/snapshot/webhook',
(req, _, next) => {
const headerSecret = req.headers['authentication'];
if (
config.SNAPSHOT_WEBHOOK_SECRET &&
headerSecret !== config.SNAPSHOT_WEBHOOK_SECRET
) {
throw new AppError('Unauthorized', 401);
}
return next();
},
express.command(Snapshot.CreateSnapshotProposal()),
);

Expand Down
7 changes: 7 additions & 0 deletions packages/commonwealth/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,12 @@ export const config = configure(
EVM_CE_POLL_INTERVAL_MS: z.number().int().positive(),
}),
PEER_ID: z.string().optional(),
SNAPSHOT_WEBHOOK_SECRET: z
.string()
.optional()
.refine(
(data) => !(!['local', 'CI'].includes(model_config.APP_ENV) && !data),
'SNAPSHOT_WEBHOOK_SECRET is required in public environments',
),
}),
);
Loading