Skip to content

Commit

Permalink
feature flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Emanuele De Cupis authored and Emanuele De Cupis committed Jul 24, 2020
1 parent fd190d5 commit d9377f4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
7 changes: 5 additions & 2 deletions UserDataProcessingTrigger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
trackUserDataDeleteEvent,
trackUserDataDownloadEvent
} from "../utils/appinsightsEvents";
import { flags } from "../utils/featureFlags";

const logPrefix = "UserDataProcessingTrigger";

Expand Down Expand Up @@ -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}`
Expand All @@ -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}`
Expand Down
24 changes: 24 additions & 0 deletions utils/featureFlags.ts
Original file line number Diff line number Diff line change
@@ -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);

This comment has been minimized.

Copy link
@gunzip

gunzip Jul 24, 2020

Contributor

what's the expected string value to obtain 'false' ?


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
)
};

0 comments on commit d9377f4

Please sign in to comment.