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

Allow plugins to be enabled, disabled, and applied via env vars. #12844

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion kolibri/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ def __init__(self):
)
self.save()
logger.info("Initialized plugins.json")
if self.ENV_VAR_APPLIED_PLUGINS:
logger.info(
"Applied plugins from environment variable: {}".format(
self.ENV_VAR_APPLIED_PLUGINS
)
)
if self.ENV_VAR_ENABLED_PLUGINS:
logger.info(
"Enabled plugins from environment variable: {}".format(
self.ENV_VAR_ENABLED_PLUGINS
)
)
if self.ENV_VAR_DISABLED_PLUGINS:
logger.info(
"Disabled plugins from environment variable: {}".format(
self.ENV_VAR_DISABLED_PLUGINS
)
)

def set_defaults(self):
self.update(
Expand All @@ -55,9 +73,40 @@ def set_defaults(self):
}
)

@property
def ENV_VAR_APPLIED_PLUGINS(self):
return [
p.strip()
for p in os.environ.get("KOLIBRI_PLUGIN_APPLY", "").split(",")
if p.strip()
]

@property
def ENV_VAR_ENABLED_PLUGINS(self):
return set(
p.strip()
for p in os.environ.get("KOLIBRI_PLUGIN_ENABLE", "").split(",")
if p.strip()
)

@property
def ENV_VAR_DISABLED_PLUGINS(self):
return set(
p.strip()
for p in os.environ.get("KOLIBRI_PLUGIN_DISABLE", "").split(",")
if p.strip()
)

@property
def ACTIVE_PLUGINS(self):
return list(self["INSTALLED_PLUGINS"] - self["DISABLED_PLUGINS"])
if self.ENV_VAR_APPLIED_PLUGINS:
return self.ENV_VAR_APPLIED_PLUGINS
return list(
(self["INSTALLED_PLUGINS"] - self["DISABLED_PLUGINS"]).union(
self.ENV_VAR_ENABLED_PLUGINS
)
- self.ENV_VAR_DISABLED_PLUGINS
)

def update(self, new_values):
"""
Expand Down
18 changes: 18 additions & 0 deletions kolibri/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ def settings_module():
See the sd_notify(3) man page for more details.
""",
},
"KOLIBRI_PLUGIN_APPLY": {
"description": """
A comma-separated list of plugins to apply. If this variable is set,
only the specified plugins will be applied.
""",
},
"KOLIBRI_PLUGIN_ENABLE": {
"description": """
A comma-separated list of plugins to enable. If this variable is set,
the specified plugins will be enabled, overriding plugins disabled via the CLI.
""",
},
"KOLIBRI_PLUGIN_DISABLE": {
"description": """
A comma-separated list of plugins to disable. If this variable is set,
the specified plugins will be disabled, overriding plugins enabled via the CLI.
""",
},
}


Expand Down