Skip to content

Commit

Permalink
feat: add offline mode file path env (#751)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Beemer <[email protected]>
  • Loading branch information
beeme1mr authored Jan 30, 2024
1 parent 35b81e0 commit 4ff73e7
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion libs/providers/flagd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ Options can be defined in the constructor or as environment variables. Construct
| tls | FLAGD_TLS | boolean | false | |
| socketPath | FLAGD_SOCKET_PATH | string | - | |
| resolverType | FLAGD_SOURCE_RESOLVER | string | rpc | rpc, in-process |
| offlineFlagSourcePath | FLAGD_OFFLINE_FLAG_SOURCE_PATH | string | - | |
| selector | FLAGD_SOURCE_SELECTOR | string | - | |
| cache | FLAGD_CACHE | string | lru | lru,disabled |
| cache | FLAGD_CACHE | string | lru | lru, disabled |
| maxCacheSize | FLAGD_MAX_CACHE_SIZE | int | 1000 | |

Below are examples of usage patterns.
Expand Down
2 changes: 1 addition & 1 deletion libs/providers/flagd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"current-version": "echo $npm_package_version"
},
"dependencies": {
"@openfeature/flagd-core": "~0.1.7"
"@openfeature/flagd-core": "~0.1.10"
},
"peerDependencies": {
"@grpc/grpc-js": "~1.8.0 || ~1.9.0",
Expand Down
3 changes: 3 additions & 0 deletions libs/providers/flagd/src/lib/configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('Configuration', () => {
const cache = 'disabled';
const resolverType = 'in-process';
const selector = 'app=weather';
const offlineFlagSourcePath = '/tmp/flags.json';

process.env['FLAGD_HOST'] = host;
process.env['FLAGD_PORT'] = `${port}`;
Expand All @@ -39,6 +40,7 @@ describe('Configuration', () => {
process.env['FLAGD_MAX_CACHE_SIZE'] = `${maxCacheSize}`;
process.env['FLAGD_SOURCE_SELECTOR'] = `${selector}`;
process.env['FLAGD_RESOLVER'] = `${resolverType}`;
process.env['FLAGD_OFFLINE_FLAG_SOURCE_PATH'] = offlineFlagSourcePath;

expect(getConfig()).toStrictEqual({
host,
Expand All @@ -49,6 +51,7 @@ describe('Configuration', () => {
cache,
resolverType,
selector,
offlineFlagSourcePath,
});
});

Expand Down
4 changes: 4 additions & 0 deletions libs/providers/flagd/src/lib/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ enum ENV_VAR {
FLAGD_MAX_CACHE_SIZE = 'FLAGD_MAX_CACHE_SIZE',
FLAGD_SOURCE_SELECTOR = 'FLAGD_SOURCE_SELECTOR',
FLAGD_RESOLVER = 'FLAGD_RESOLVER',
FLAGD_OFFLINE_FLAG_SOURCE_PATH = 'FLAGD_OFFLINE_FLAG_SOURCE_PATH',
}

const getEnvVarConfig = (): Partial<Config> => ({
Expand Down Expand Up @@ -118,6 +119,9 @@ const getEnvVarConfig = (): Partial<Config> => ({
...((process.env[ENV_VAR.FLAGD_RESOLVER] === 'rpc' || process.env[ENV_VAR.FLAGD_RESOLVER] === 'in-process') && {
resolverType: process.env[ENV_VAR.FLAGD_RESOLVER],
}),
...(process.env[ENV_VAR.FLAGD_OFFLINE_FLAG_SOURCE_PATH] && {
offlineFlagSourcePath: process.env[ENV_VAR.FLAGD_OFFLINE_FLAG_SOURCE_PATH],
}),
});

export function getConfig(options: FlagdProviderOptions = {}) {
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@nx/web": "16.9.1",
"@nx/workspace": "16.9.1",
"@openfeature/core": "^0.0.21",
"@openfeature/flagd-core": ">=0.1.7",
"@openfeature/flagd-core": ">=0.1.10",
"@openfeature/server-sdk": "^1.8.0",
"@openfeature/web-sdk": "^0.4.0",
"@opentelemetry/sdk-metrics": "^1.15.0",
Expand Down Expand Up @@ -83,4 +83,4 @@
"ts-node": "10.9.2",
"typescript": "5.1.6"
}
}
}

0 comments on commit 4ff73e7

Please sign in to comment.