diff --git a/UserDataProcessingTrigger/index.ts b/UserDataProcessingTrigger/index.ts index 8530350d..42c69bbe 100644 --- a/UserDataProcessingTrigger/index.ts +++ b/UserDataProcessingTrigger/index.ts @@ -16,6 +16,7 @@ import { trackUserDataDeleteEvent, trackUserDataDownloadEvent } from "../utils/appinsightsEvents"; +import { flags } from "../utils/featureFlags"; const logPrefix = "UserDataProcessingTrigger"; @@ -84,7 +85,8 @@ export function index( .decode(processableOrNot) .chain(processable => fromNullable(undefined)( - ProcessableUserDataDownload.is(processable) + flags.ENABLE_USER_DATA_DOWNLOAD && + ProcessableUserDataDownload.is(processable) ? () => { context.log.info( `${logPrefix}: starting UserDataDownloadOrchestrator with ${processable.fiscalCode}` @@ -96,7 +98,8 @@ export function index( processable ); } - : ProcessableUserDataDelete.is(processable) + : flags.ENABLE_USER_DATA_DELETE && + ProcessableUserDataDelete.is(processable) ? () => { context.log.info( `${logPrefix}: starting UserDataDeleteOrchestrator with ${processable.fiscalCode}` diff --git a/utils/featureFlags.ts b/utils/featureFlags.ts new file mode 100644 index 00000000..009f6db6 --- /dev/null +++ b/utils/featureFlags.ts @@ -0,0 +1,24 @@ +/** + * + */ + +import { fromNullable } from "fp-ts/lib/Option"; +import * as t from "io-ts"; + +const getEnvVariable = (decoder: t.Mixed) => ( + name: string, + defaultValue: typeof decoder["_A"] +) => + fromNullable(process.env[name]) + .map(decoder.decode) + .getOrElse(defaultValue); + +const getFlagFromEnv = getEnvVariable(t.boolean); + +export const flags = { + ENABLE_USER_DATA_DELETE: getFlagFromEnv("FF_ENABLE_USER_DATA_DELETE", true), + ENABLE_USER_DATA_DOWNLOAD: getFlagFromEnv( + "FF_ENABLE_USER_DATA_DOWNLOAD", + true + ) +};