annon_api v0.16.2 Annon.Plugin behaviour

This helper provides abstract interface to define plugin.

Example:

use Annon.Plugin,
  plugin_name: :my_plugin

Link to this section Summary

Functions

Returns list of processing pipeline features that Plugin requires to work properly

Updates Annon.Plugin.Request structure by raising flag on features in features list

Callbacks

Initializes Plugin

Validates JSON Schema that can be used to validate Plugin settings

Validates Plugin settings

Link to this section Functions

Link to this function get_plugin_features(plugin_name)

Returns list of processing pipeline features that Plugin requires to work properly.

Link to this function update_feature_requirements(request, features)

Updates Annon.Plugin.Request structure by raising flag on features in features list.

Link to this section Callbacks

Link to this callback execute(conn, plugin_request, plugin_settings)
execute(
  conn :: Plug.Conn.t(),
  plugin_request :: %Annon.Plugin.Request{
    api: term(),
    feature_requirements: term(),
    plugins: term(),
    start_time: term()
  },
  plugin_settings :: %Annon.Configuration.Schemas.Plugin{
    __meta__: term(),
    api: term(),
    api_id: term(),
    inserted_at: term(),
    is_enabled: term(),
    name: term(),
    settings: term(),
    updated_at: term()
  }
) :: %Annon.Plugin.Request{
  api: term(),
  feature_requirements: term(),
  plugins: term(),
  start_time: term()
}

Executes Plugin.

Receives Annon.Plugin.Request structure, which allows Plugin to:

  • Set properties for upstream request (in conn.assigns.upstream_request).
  • Modify connection if this feature was enabled.
Link to this callback prepare(plugin_request)
prepare(
  plugin_request :: %Annon.Plugin.Request{
    api: term(),
    feature_requirements: term(),
    plugins: term(),
    start_time: term()
  }
) :: %Annon.Plugin.Request{
  api: term(),
  feature_requirements: term(),
  plugins: term(),
  start_time: term()
}

Initializes Plugin.

Receives Annon.Plugin.Request structure and returns it, which allows Plugin to:

  • Remove itself from execution pipeline if it should be disabled. (Eg. plugin that it depends on is not enabled.)
  • Set required execution features. (Eg. if it wants log writes to be consistent.)

Connection MUST NOT be changed in a preparation pipeline.

Link to this callback settings_validation_schema()
settings_validation_schema() :: Map.t()

Validates JSON Schema that can be used to validate Plugin settings.

Link to this callback validate_settings(changeset)
validate_settings(changeset :: Ecto.Changeset.t()) :: Ecto.Changeset.t()

Validates Plugin settings.