|
2 | 2 | This submodule contains the client class that provides most of the SDK functionality. |
3 | 3 | """ |
4 | 4 |
|
5 | | -import hashlib |
6 | | -import hmac |
7 | 5 | import threading |
8 | 6 | import traceback |
9 | 7 | from typing import Any, Callable, Dict, List, Mapping, Optional, Tuple |
|
19 | 17 | _EvaluationWithHookResult |
20 | 18 | ) |
21 | 19 | from ldclient.impl.big_segments import BigSegmentStoreManager |
| 20 | +from ldclient.impl.client_core import ( |
| 21 | + get_environment_metadata, |
| 22 | + get_plugin_hooks |
| 23 | +) |
| 24 | +from ldclient.impl.client_core import secure_mode_hash as _secure_mode_hash |
22 | 25 | from ldclient.impl.datasource.feature_requester import FeatureRequesterImpl |
23 | 26 | from ldclient.impl.datasource.polling import PollingUpdateProcessor |
24 | 27 | from ldclient.impl.datasource.status import ( |
|
57 | 60 | ReadOnlyStore |
58 | 61 | ) |
59 | 62 | from ldclient.migrations import OpTracker, Stage |
60 | | -from ldclient.plugin import ( |
61 | | - ApplicationMetadata, |
62 | | - EnvironmentMetadata, |
63 | | - SdkMetadata |
64 | | -) |
65 | | -from ldclient.version import VERSION |
| 63 | +from ldclient.plugin import EnvironmentMetadata |
66 | 64 | from ldclient.versioned_data_kind import FEATURES, SEGMENTS, VersionedDataKind |
67 | 65 |
|
68 | 66 | from .impl import AnyNum |
@@ -239,8 +237,8 @@ def postfork(self, start_wait: float = 5): |
239 | 237 | self.__start_up(start_wait) |
240 | 238 |
|
241 | 239 | def __start_up(self, start_wait: float): |
242 | | - environment_metadata = self.__get_environment_metadata() |
243 | | - plugin_hooks = self.__get_plugin_hooks(environment_metadata) |
| 240 | + environment_metadata = get_environment_metadata(self._config) |
| 241 | + plugin_hooks = get_plugin_hooks(self._config, environment_metadata) |
244 | 242 |
|
245 | 243 | self.__hooks_lock = ReadWriteLock() |
246 | 244 | self.__hooks = self._config.hooks + plugin_hooks # type: List[Hook] |
@@ -305,36 +303,6 @@ def __start_up(self, start_wait: float): |
305 | 303 | else: |
306 | 304 | log.warning("Initialization timeout exceeded for LaunchDarkly Client or an error occurred. " "Feature Flags may not yet be available.") |
307 | 305 |
|
308 | | - def __get_environment_metadata(self) -> EnvironmentMetadata: |
309 | | - sdk_metadata = SdkMetadata( |
310 | | - name="python-server-sdk", |
311 | | - version=VERSION, |
312 | | - wrapper_name=self._config.wrapper_name, |
313 | | - wrapper_version=self._config.wrapper_version |
314 | | - ) |
315 | | - |
316 | | - application_metadata = None |
317 | | - if self._config.application: |
318 | | - application_metadata = ApplicationMetadata( |
319 | | - id=self._config.application.get('id'), |
320 | | - version=self._config.application.get('version'), |
321 | | - ) |
322 | | - |
323 | | - return EnvironmentMetadata( |
324 | | - sdk=sdk_metadata, |
325 | | - application=application_metadata, |
326 | | - sdk_key=self._config.sdk_key |
327 | | - ) |
328 | | - |
329 | | - def __get_plugin_hooks(self, environment_metadata: EnvironmentMetadata) -> List[Hook]: |
330 | | - hooks = [] |
331 | | - for plugin in self._config.plugins: |
332 | | - try: |
333 | | - hooks.extend(plugin.get_hooks(environment_metadata)) |
334 | | - except Exception as e: |
335 | | - log.error("Error getting hooks from plugin %s: %s", plugin.metadata.name, e) |
336 | | - return hooks |
337 | | - |
338 | 306 | def __register_plugins(self, environment_metadata: EnvironmentMetadata): |
339 | 307 | for plugin in self._config.plugins: |
340 | 308 | try: |
@@ -693,10 +661,7 @@ def secure_mode_hash(self, context: Context) -> str: |
693 | 661 | :param context: the evaluation context |
694 | 662 | :return: the hash string |
695 | 663 | """ |
696 | | - if not context.valid: |
697 | | - log.warning("Context was invalid for secure_mode_hash (%s); returning empty hash" % context.error) |
698 | | - return "" |
699 | | - return hmac.new(str(self._config.sdk_key).encode(), context.fully_qualified_key.encode(), hashlib.sha256).hexdigest() |
| 664 | + return _secure_mode_hash(self._config, context) |
700 | 665 |
|
701 | 666 | def add_hook(self, hook: Hook): |
702 | 667 | """ |
|
0 commit comments