-
Notifications
You must be signed in to change notification settings - Fork 19
feat: Internal environment ID support. #217
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
Changes from all commits
27e0793
ace28b8
e885ac4
7865444
ed5eb10
cfa03b4
91984b8
9261669
4c2dc50
0a7a73a
117f9df
3883d52
187e49c
22b6107
b493ec8
693a504
91341e8
8196367
0a45970
4ccc498
38c0db3
635ed95
8cca976
884d177
8ddf361
4c4d2f4
575305e
b867cff
ad86a37
be04094
284f6e7
10b6448
e21f366
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| const _envIdHeader = 'x-ld-envid'; | ||
|
|
||
| final _splitRegex = RegExp(r'\s*,\s*'); | ||
|
|
||
| /// Get the environment ID from headers. | ||
| String? getEnvironmentId(Map<String, String>? headers) { | ||
| // Headers will always be in lower case from the http response. | ||
| // If multiple headers are associated with a single key, then they will be | ||
| // in a comma separated list with potential whitespace. | ||
| final headerValue = headers?[_envIdHeader]; | ||
| if (headerValue == null) { | ||
| return null; | ||
| } | ||
| return headerValue.split(_splitRegex).first; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import 'flag_store.dart'; | |
|
|
||
| const String _globalNamespace = 'LaunchDarkly'; | ||
| const String _indexKey = 'ContextIndex'; | ||
| const String _envIdKey = 'EnvironmentId'; | ||
|
|
||
| String _makeEnvironment(String sdkKey) { | ||
| return '${_globalNamespace}_${encodePersistenceKey(sdkKey)}'; | ||
|
|
@@ -45,9 +46,9 @@ final class FlagPersistence { | |
| _logger = logger.subLogger('FlagPersistence'), | ||
| _stamper = stamper; | ||
|
|
||
| Future<void> init( | ||
| LDContext context, Map<String, ItemDescriptor> newFlags) async { | ||
| _updater.init(context, newFlags); | ||
| Future<void> init(LDContext context, Map<String, ItemDescriptor> newFlags, | ||
| {String? environmentId}) async { | ||
| _updater.init(context, newFlags, environmentId: environmentId); | ||
| return _storeCache(context); | ||
| } | ||
|
|
||
|
|
@@ -70,14 +71,17 @@ final class FlagPersistence { | |
| return false; | ||
| } | ||
|
|
||
| final environmentId = await _persistence?.read(_environmentKey, _envIdKey); | ||
|
|
||
| try { | ||
| final flagConfig = | ||
| LDEvaluationResultsSerialization.fromJson(jsonDecode(json)); | ||
|
|
||
| _updater.initCached( | ||
| context, | ||
| flagConfig.map((key, value) => MapEntry( | ||
| key, ItemDescriptor(version: value.version, flag: value)))); | ||
| key, ItemDescriptor(version: value.version, flag: value))), | ||
| environmentId: environmentId); | ||
| _logger.debug('Loaded a cached flag config from persistence.'); | ||
| return true; | ||
| } catch (e) { | ||
|
|
@@ -135,6 +139,12 @@ final class FlagPersistence { | |
| // is always written. | ||
| if (maxCachedContexts > 0) { | ||
| await _persistence?.set(_environmentKey, contextPersistenceKey, jsonAll); | ||
| // There will be a singular environment ID for a given environment key | ||
| // (credential). | ||
| if (_store.environmentId != null) { | ||
| await _persistence?.set( | ||
| _environmentKey, _envIdKey, _store.environmentId!); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this bang avoidable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is checked before, but the dart compiler still wanted it. I think because maybe it doesn't know the parameter evaluation happens before the async operation. |
||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing temporary changes from the major versioning of the event source client.