Plugins Overview¶
AMSDAL provides the ability to extend the functionality of AMSDAL by using existing plugin packages or by creating your own one.
A plugin can be used for:
- Custom connection implementations
- Custom locking implementation
- Rest API (
amsdal_server
) functionality such us: authorization mechanism, extending response data
AMSDAL includes a several built-in plugin solutions:
amsdal.contrib.auth
- Rest API: Authorization mechanismamsdal.contrib.frontend_config
- Rest API: Adds ability to define UI configs to control how each model and field will be rendered on the frontend app.
AppConfig¶
AppConfig is the main class of the plugin that defines the plugin package. To define it, you need to inherit from amsdal.contrib.app_config.AppConfig
class and implement the following methods:
- on_ready
To include your plugin in AMSDAL, you need to add the full path to your AppConfig class to AMSDAL_CONTRIBS environment variable, for example amsdal.contrib.auth.app.AuthAppConfig
.
Lifecycles¶
Lifecycles are implementation of Producer-Consumer pattern. They are used to perform some actions on application events, such as ON_SERVER_STARTUP or ON_AUTHENTICATE.
To define a lifecycle consumer, you need to inherit from amsdal_utils.lifecycle.consumer.LifecycleConsumer
class and implement the following methods:
- on_event
After that, subscribe your consumer to the lifecycle by adding the subscription code to the AppConfig.on_ready method. For example:
class AuthAppConfig(AppConfig):
def on_ready(self) -> None:
from amsdal.contrib.auth.lifecycle.consumer import AuthenticateUserConsumer
from amsdal.contrib.auth.lifecycle.consumer import CheckAndCreateSuperUserConsumer
from amsdal.contrib.auth.lifecycle.consumer import CheckPermissionConsumer
LifecycleProducer.add_listener(LifecycleEvent.ON_SERVER_STARTUP, CheckAndCreateSuperUserConsumer)
LifecycleProducer.add_listener(LifecycleEvent.ON_AUTHENTICATE, AuthenticateUserConsumer)
LifecycleProducer.add_listener(LifecycleEvent.ON_PERMISSION_CHECK, CheckPermissionConsumer)
Models¶
You can add custom plugin models to the application. Add models
directory to your plugin package and create your models there the same way you create models in your application.