Skip to content
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

Extension mechanism #268

Merged

Conversation

symphony-mariacristina
Copy link
Contributor

@symphony-mariacristina symphony-mariacristina commented Mar 17, 2022

Description

The Extension API is available through the module symphony.bdk.core.extension. Extensions are registered programmatically via the ExtensionService. A Service Provider extension is a specific type of extension loaded on demand when calling the ExtensionService#service(MyExtensionType) method.

To make your extension Service Provider, your extension definition must implement the method get_service(self).

# Usage example.
async def run():
    config = BdkConfigLoader.load_from_symphony_dir("config.yaml")
    async with SymphonyBdk(config) as bdk:
        extension_service = bdk.extensions()
        extension_service.register(MyBdkExtensionService)
        service = extension_service.service(MyBdkExtensionService)
        service.say_hello("Symphony")
        
asyncio.run(run())

BDK Aware Extensions

The BDK Extension Model allows extensions to access to some core objects such as the configuration or the api clients.
Developers that wish to use these objects are free to implement a set of abstract base classes all suffixed with the Aware keyword.
List of Aware classes:

  • BdkConfigAware- allows extensions to read the BdkConfig:
  • BdkApiClientFactoryAware - can be used by extensions that need to use the ApiClientFactory
  • BdkAuthenticationAware- can be used by extensions that need to rely on the service account authentication session (AuthSession)

Symphony Groups Extension

As part of this PR we also leveraged this new Extension Mechanism to implement a new custom extension to support the Symphony Groups APIs.

client.configuration._disabled_client_side_validations = ["minLength"]
self._group_api = GroupApi(client)

async def insert_group(self, create_group: CreateGroup) -> ReadGroup:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to say we should name it create group to be consistent with other services but then in the Java BDK it is named like that, I missed it during the Java BDK review :(

:param user_id: The ID of the user to be added into the group
:return: the updated group
"""
member = Member(member_id=user_id, member_tenant=extract_tenant_id(user_id))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm I missed that in the Java BDK we were doing that (guessing the tenant id from the user id) (which the profile manager API should do for us already...)
So I should probably change the WDK implem too (although we only do it partially for this method and not for the creation)

@symphony-elias
Copy link
Contributor

@symphony-mariacristina should we document how to leverage the retry mechanism in extensions? I would say so because it differs much from the Java BDK

Copy link
Contributor

@symphony-elias symphony-elias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@symphony-mariacristina symphony-mariacristina merged commit 2d5b82a into finos:main Mar 23, 2022
@symphony-elias
Copy link
Contributor

Implements #251

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants