keepluggable.orchestrator module

The Orchestrator coordinates the components you chose in configuration.

class keepluggable.orchestrator.ConfigurationSchema(*args, **kw)[source]

Bases: colander.Schema

Validated configuration of a keepluggable instance.

settings should contain only the relevant section of an INI file.

class keepluggable.orchestrator.Orchestrator(config: Dict[str, Any])[source]

Bases: object

A coordinator that instantiates configured components at startup.

An Orchestrator instance provides:

  • storage_file: the instance of the payload storage strategy class.

  • storage_metadata: the instance of the metadata storage strategy.

  • get_action(namespace): conveniently get an instance of the action class, in order to serve a request.

classmethod from_ini(name: str, *paths: Union[str, os.PathLike], encoding: str = 'utf-8') keepluggable.orchestrator.Orchestrator[source]

Read one or more INI files and return an Orchestrator instance.

get_action(namespace: str) Any[source]

Conveniently instantiate the configured action class.

instances: Dict[str, keepluggable.orchestrator.Orchestrator] = {}
keepluggable.orchestrator.get_middle_path(name: str, namespace: Any) str[source]

Return the path between bucket and file name.

By default this simply returns the namespace. This means the default naming scheme is: bucket / namespace / file_name

BUT you can override this function for each keepluggable instance in your application.

By creating multiple naming schemes, you can have multiple storages living in the same bucket without clashing!

We use the Reg library to accomplish this. It implements dispatch based on function arguments. This particular function will dispatch based on the value of the name argument, which should be the same as the name of a keepluggable instance.

For instance, your keepluggable instance that stores user avatars could register one implementation such as:

return "avatar{}".format(namespace)

…and then a different area of your app could have a keepluggable instance that stores company logos by registering another implementation:

return "logo{}".format(namespace)

…and so these can share a single S3 bucket.