|
4 | 4 | Note that the same class can also be imported from the ``ldclient.client`` submodule. |
5 | 5 | """ |
6 | 6 |
|
| 7 | +from dataclasses import dataclass |
7 | 8 | from threading import Event |
8 | | -from typing import Callable, List, Optional, Set |
| 9 | +from typing import Callable, List, Optional, Set, TypeVar |
9 | 10 |
|
10 | 11 | from ldclient.feature_store import InMemoryFeatureStore |
11 | 12 | from ldclient.hook import Hook |
| 13 | +from ldclient.impl.datasystem import Initializer, Synchronizer |
12 | 14 | from ldclient.impl.util import ( |
13 | 15 | log, |
14 | 16 | validate_application_info, |
@@ -152,6 +154,32 @@ def disable_ssl_verification(self) -> bool: |
152 | 154 | return self.__disable_ssl_verification |
153 | 155 |
|
154 | 156 |
|
| 157 | +T = TypeVar("T") |
| 158 | + |
| 159 | +Builder = Callable[[], T] |
| 160 | + |
| 161 | + |
| 162 | +@dataclass(frozen=True) |
| 163 | +class DataSystemConfig: |
| 164 | + """ |
| 165 | + Configuration for LaunchDarkly's data acquisition strategy. |
| 166 | + """ |
| 167 | + |
| 168 | + initializers: Optional[List[Builder[Initializer]]] |
| 169 | + """The initializers for the data system.""" |
| 170 | + |
| 171 | + primary_synchronizer: Builder[Synchronizer] |
| 172 | + """The primary synchronizer for the data system.""" |
| 173 | + |
| 174 | + secondary_synchronizer: Optional[Builder[Synchronizer]] = None |
| 175 | + """The secondary synchronizers for the data system.""" |
| 176 | + |
| 177 | + # TODO(fdv2): Implement this synchronizer up and hook it up everywhere. |
| 178 | + # TODO(fdv2): Remove this when FDv2 is fully launched |
| 179 | + fdv1_fallback_synchronizer: Optional[Builder[Synchronizer]] = None |
| 180 | + """An optional fallback synchronizer that will read from FDv1""" |
| 181 | + |
| 182 | + |
155 | 183 | class Config: |
156 | 184 | """Advanced configuration options for the SDK client. |
157 | 185 |
|
@@ -194,6 +222,7 @@ def __init__( |
194 | 222 | enable_event_compression: bool = False, |
195 | 223 | omit_anonymous_contexts: bool = False, |
196 | 224 | payload_filter_key: Optional[str] = None, |
| 225 | + datasystem_config: Optional[DataSystemConfig] = None, |
197 | 226 | ): |
198 | 227 | """ |
199 | 228 | :param sdk_key: The SDK key for your LaunchDarkly account. This is always required. |
@@ -264,6 +293,7 @@ def __init__( |
264 | 293 | :param enable_event_compression: Whether or not to enable GZIP compression for outgoing events. |
265 | 294 | :param omit_anonymous_contexts: Sets whether anonymous contexts should be omitted from index and identify events. |
266 | 295 | :param payload_filter_key: The payload filter is used to selectively limited the flags and segments delivered in the data source payload. |
| 296 | + :param datasystem_config: Configuration for the upcoming enhanced data system design. This is experimental and should not be set without direction from LaunchDarkly support. |
267 | 297 | """ |
268 | 298 | self.__sdk_key = validate_sdk_key_format(sdk_key, log) |
269 | 299 |
|
@@ -303,6 +333,7 @@ def __init__( |
303 | 333 | self.__payload_filter_key = payload_filter_key |
304 | 334 | self._data_source_update_sink: Optional[DataSourceUpdateSink] = None |
305 | 335 | self._instance_id: Optional[str] = None |
| 336 | + self._datasystem_config = datasystem_config |
306 | 337 |
|
307 | 338 | def copy_with_new_sdk_key(self, new_sdk_key: str) -> 'Config': |
308 | 339 | """Returns a new ``Config`` instance that is the same as this one, except for having a different SDK key. |
@@ -546,6 +577,15 @@ def data_source_update_sink(self) -> Optional[DataSourceUpdateSink]: |
546 | 577 | """ |
547 | 578 | return self._data_source_update_sink |
548 | 579 |
|
| 580 | + @property |
| 581 | + def datasystem_config(self) -> Optional[DataSystemConfig]: |
| 582 | + """ |
| 583 | + Configuration for the upcoming enhanced data system design. This is |
| 584 | + experimental and should not be set without direction from LaunchDarkly |
| 585 | + support. |
| 586 | + """ |
| 587 | + return self._datasystem_config |
| 588 | + |
549 | 589 | def _validate(self): |
550 | 590 | if self.offline is False and self.sdk_key == '': |
551 | 591 | log.warning("Missing or blank SDK key") |
|
0 commit comments