Skip to content

Commit

Permalink
console: allow URLs with templated environment variable for data even…
Browse files Browse the repository at this point in the history
…ts (close hasura#6239) (hasura#160)

GitOrigin-RevId: fb1041a4d33a7f78db66b8cebcea041dd1d55ef8
  • Loading branch information
Aleksandra Sikora authored and hasura-bot committed Dec 4, 2020
1 parent 8c9ffbe commit a75564c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions console/src/components/Common/utils/jsUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export const isValidURL = (value: string) => {
return true;
};

export const isURLTemplated = (value: string): boolean => {
return /{{(\S+)}}/.test(value);
};

export const isValidTemplateLiteral = (literal_: string) => {
const literal = literal_.trim();
if (!literal) return false;
Expand Down
7 changes: 5 additions & 2 deletions console/src/components/Services/Events/EventTriggers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LocalEventTriggerState } from './state';
import { isValidURL } from '../../../Common/utils/jsUtils';
import { isURLTemplated, isValidURL } from '../../../Common/utils/jsUtils';
import { makeBaseTable } from '../../../Common/utils/pgUtils';

// check 2xx success status codes
Expand Down Expand Up @@ -78,7 +78,10 @@ export const validateETState = (state: LocalEventTriggerState) => {
if (!state.webhook.value) {
return 'Webhook URL cannot be empty';
}
if (state.webhook.type === 'static' && !isValidURL(state.webhook.value)) {
if (
state.webhook.type === 'static' &&
!(isValidURL(state.webhook.value) || isURLTemplated(state.webhook.value))
) {
return 'Invalid webhook URL';
}

Expand Down
19 changes: 15 additions & 4 deletions console/src/components/Services/Events/ServerIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ import {
} from '../../Common/utils/routesUtils';
import { transformHeaders } from '../../Common/Headers/utils';
import { Table } from '../../Common/utils/pgUtils';
import { getConfirmation, isValidURL } from '../../Common/utils/jsUtils';
import {
getConfirmation,
isURLTemplated,
isValidURL,
} from '../../Common/utils/jsUtils';
import { Nullable } from '../../Common/utils/tsUtils';
import Endpoints, { globalCookiePolicy } from '../../../Endpoints';
import dataHeaders from '../Data/Common/Headers';
Expand Down Expand Up @@ -324,6 +328,7 @@ export const createEventTrigger = (
dispatch(
showErrorNotification('Creating event trigger failed', validationError)
);
return;
}

const migrationName = `create_event_trigger_${state.name.trim()}`;
Expand Down Expand Up @@ -389,14 +394,20 @@ export const modifyEventTrigger = (

switch (property) {
case 'webhook': {
if (state.webhook.type === 'static' && !isValidURL(state.webhook.value)) {
if (
state.webhook.type === 'static' &&
!(
isValidURL(state.webhook.value) || isURLTemplated(state.webhook.value)
)
) {
return dispatch(showErrorNotification(errorMsg, 'Invalid URL'));
}
upQuery.args = {
...upQuery.args,
webhook: state.webhook.type === 'static' ? state.webhook.value : null,
webhook:
state.webhook.type === 'static' ? state.webhook.value.trim() : null,
webhook_from_env:
state.webhook.type === 'env' ? state.webhook.value : null,
state.webhook.type === 'env' ? state.webhook.value.trim() : null,
};
break;
}
Expand Down

0 comments on commit a75564c

Please sign in to comment.