-
Notifications
You must be signed in to change notification settings - Fork 45
feat: Add support for plugins. #337
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
924cec5
feat: Add support for plugins.
kinyoklion 531bfd9
Refactor metadata to be a property.
kinyoklion 2a3a6bf
Extend testing to ensure correct messages are logged.
kinyoklion 6ddfdd0
Linting
kinyoklion a4737b1
Revert changes to __init__
kinyoklion af2e4a8
Add typing to get_environment_metadata.
kinyoklion 0aef37e
Remove unused credential types.
kinyoklion 81a8224
Make get_hooks abstract.
kinyoklion 32e9fd9
Merge branch 'main' into rlamb/o11y-265/add-plugin-support
keelerm84 f15aa86
Update ldclient/client.py
kinyoklion f4f8ae4
Update log format.
kinyoklion 01801f5
kw_only
kinyoklion 8c2c990
Merge branch 'main' into rlamb/o11y-265/add-plugin-support
kinyoklion 3cb9f99
Update with correct LDClient type.
kinyoklion 1b13184
Remove kw_only
kinyoklion aec6d5f
Order of environment data.
kinyoklion 1e4fadb
SDK Key optional.
kinyoklion ecc14ea
Fix import sorting.
kinyoklion 32433bc
Format plugin.py
kinyoklion 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
Next
Next commit
feat: Add support for plugins.
- Loading branch information
commit 924cec5205bca771633985cb09824ccbbbe411b5
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
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,97 @@ | ||
| from abc import ABCMeta, abstractmethod | ||
| from dataclasses import dataclass | ||
| from typing import Any, List, Optional | ||
|
|
||
| from ldclient.hook import Hook | ||
|
|
||
|
|
||
| @dataclass | ||
| class SdkMetadata: | ||
| """ | ||
| Metadata about the SDK. | ||
| """ | ||
| name: str #: The id of the SDK (e.g., "python-server-sdk") | ||
| version: str #: The version of the SDK | ||
| wrapper_name: Optional[str] = None #: The wrapper name if this SDK is a wrapper | ||
| wrapper_version: Optional[str] = None #: The wrapper version if this SDK is a wrapper | ||
|
|
||
|
|
||
| @dataclass | ||
| class ApplicationMetadata: | ||
| """ | ||
| Metadata about the application using the SDK. | ||
| """ | ||
| id: Optional[str] = None #: The id of the application | ||
| version: Optional[str] = None #: The version of the application | ||
|
|
||
|
|
||
| @dataclass | ||
| class EnvironmentMetadata: | ||
| """ | ||
| Metadata about the environment in which the SDK is running. | ||
| """ | ||
| sdk: SdkMetadata #: Information about the SDK | ||
| application: Optional[ApplicationMetadata] = None #: Information about the application | ||
| sdk_key: Optional[str] = None #: The SDK key used to initialize the SDK | ||
| mobile_key: Optional[str] = None #: The mobile key used to initialize the SDK | ||
| client_side_id: Optional[str] = None #: The client-side ID used to initialize the SDK | ||
|
|
||
|
|
||
| @dataclass | ||
| class PluginMetadata: | ||
| """ | ||
| Metadata about a plugin implementation. | ||
| """ | ||
| name: str #: A name representing the plugin instance | ||
|
|
||
|
|
||
| class Plugin: | ||
| """ | ||
| Abstract base class for extending SDK functionality via plugins. | ||
|
|
||
| All provided plugin implementations **MUST** inherit from this class. | ||
|
|
||
| This class includes default implementations for optional methods. This | ||
| allows LaunchDarkly to expand the list of plugin methods without breaking | ||
| customer integrations. | ||
|
|
||
| Plugins provide an interface which allows for initialization, access to | ||
| credentials, and hook registration in a single interface. | ||
| """ | ||
|
|
||
| __metaclass__ = ABCMeta | ||
|
|
||
| @abstractmethod | ||
| def get_metadata(self) -> PluginMetadata: | ||
| """ | ||
| Get metadata about the plugin implementation. | ||
|
|
||
| :return: Metadata containing information about the plugin | ||
| """ | ||
| return PluginMetadata(name='UNDEFINED') | ||
|
|
||
| @abstractmethod | ||
| def register(self, client: Any, metadata: EnvironmentMetadata) -> None: | ||
| """ | ||
| Register the plugin with the SDK client. | ||
|
|
||
| This method is called during SDK initialization to allow the plugin | ||
| to set up any necessary integrations, register hooks, or perform | ||
| other initialization tasks. | ||
|
|
||
| :param client: The LDClient instance | ||
| :param metadata: Metadata about the environment in which the SDK is running | ||
| """ | ||
| pass | ||
|
|
||
| def get_hooks(self, metadata: EnvironmentMetadata) -> List[Hook]: | ||
| """ | ||
| Get a list of hooks that this plugin provides. | ||
|
|
||
| This method is called before register() to collect all hooks from | ||
| plugins. The hooks returned will be added to the SDK's hook configuration. | ||
|
|
||
| :param metadata: Metadata about the environment in which the SDK is running | ||
| :return: A list of hooks to be registered with the SDK | ||
| """ | ||
| return [] |
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.
This line reads like a joke. Peak python! lol