Skip to content

Plugin system

Michael Pöhn requested to merge uniqx/fdroidserver:plugin-system into master

This adds a simple but hopefully very useful plugin system to our main script. It allows adding custom sub-commands to our cli.

In this attempt plugins are python modules with need:

  • a module name looking like this fdroid_(?P<plugin-name>.*). eg. fdroid_makebuildserver.py would work and the command for calling this would be fdorid makebuildserver. Alternatively starting out with fdroid_makebuildserver/__init__.py should also work.
  • a function called main which works identical to what we've got in our sub-module scripts. So it's perfectly fine to just use ArgParse in there for example. It's also perfectly fine to support calling this plugin-scripts standalone.
  • a variable called summary. That's what gets displayed in the help listing to describe this plugin (fdroid -h).
  • to be located in on of the sys.path folders or in the same directory where fdroid gets called

Here's a simple example for a plugin:

#!/usr/evn/bin python3

fdroid_summary = "this is a trivial plugin"

def main():
    print("hello world")

Plugin lookup is using pkgutil to iterate over all modules in sys.path and select them by name-matching. This makes it easily possible to get plugins from your distro or pip. Sadly this opens up quite some attack surface for downloading and executing malicious code. It should work as expected inside virtualenv. For making development/testing of plugins easier I've added sys.getcwd() to sys.path. This also makes me unhappy about opening up more potential attack surface, eg. for privilege escalation. So I'd appreciate input on whether this is could be acceptable or how such risks could be minimized. I substantially improved this, see comments below.

Overall I think we need a plugin-system to make contributing easier and give us room for experimental projects and projects which are not part of our core functionality.

NOTE: this change is based on !708 (merged)

Edited by Michael Pöhn

Merge request reports