-
Notifications
You must be signed in to change notification settings - Fork 47
chore: Extract shared sans-I/O cores from sync data paths #450
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
Open
jsonbailey
wants to merge
1
commit into
main
Choose a base branch
from
jb/sdk-2602/core-extraction
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+621
−494
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| """ | ||
| Genuinely I/O-free, await-free helpers shared by the sync :class:`ldclient.client.LDClient` | ||
| and async :class:`ldclient.async_client.AsyncLDClient`. | ||
|
|
||
| These functions contain no awaits and touch no store/network/event I/O, so they | ||
| can live in a single module imported by both clients. Anything that reads the | ||
| store, sends events, or runs hook stages is I/O-adjacent and is hand-duplicated | ||
| across the two client classes instead (differing only in ``async``/``await``). | ||
| """ | ||
|
|
||
| import hashlib | ||
| import hmac | ||
| from typing import List | ||
|
|
||
| from ldclient.config import Config | ||
| from ldclient.context import Context | ||
| from ldclient.hook import Hook | ||
| from ldclient.impl.util import log | ||
| from ldclient.plugin import ( | ||
| ApplicationMetadata, | ||
| EnvironmentMetadata, | ||
| SdkMetadata | ||
| ) | ||
| from ldclient.version import VERSION | ||
|
|
||
|
|
||
| def get_environment_metadata(config: Config) -> EnvironmentMetadata: | ||
| sdk_metadata = SdkMetadata( | ||
| name="python-server-sdk", | ||
| version=VERSION, | ||
| wrapper_name=config.wrapper_name, | ||
| wrapper_version=config.wrapper_version | ||
| ) | ||
|
|
||
| application_metadata = None | ||
| if config.application: | ||
| application_metadata = ApplicationMetadata( | ||
| id=config.application.get('id'), | ||
| version=config.application.get('version'), | ||
| ) | ||
|
|
||
| return EnvironmentMetadata( | ||
| sdk=sdk_metadata, | ||
| application=application_metadata, | ||
| sdk_key=config.sdk_key | ||
| ) | ||
|
|
||
|
|
||
| def get_plugin_hooks(config: Config, environment_metadata: EnvironmentMetadata) -> List[Hook]: | ||
| hooks = [] | ||
| for plugin in config.plugins: | ||
| try: | ||
| hooks.extend(plugin.get_hooks(environment_metadata)) | ||
| except Exception as e: | ||
| log.error("Error getting hooks from plugin %s: %s", plugin.metadata.name, e) | ||
| return hooks | ||
|
|
||
|
|
||
| def secure_mode_hash(config: Config, context: Context) -> str: | ||
| """Computes the secure-mode HMAC for a context, or an empty string for an | ||
| invalid context. Pure: depends only on the SDK key and the context's | ||
| fully-qualified key.""" | ||
| if not context.valid: | ||
| log.warning("Context was invalid for secure_mode_hash (%s); returning empty hash" % context.error) | ||
| return "" | ||
| return hmac.new(str(config.sdk_key).encode(), context.fully_qualified_key.encode(), hashlib.sha256).hexdigest() | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we need to make a distinction for async here?