refactor: centralize plugin allowlist mutation

This commit is contained in:
Peter Steinberger
2026-02-17 00:44:43 +00:00
parent 7147cd9cc0
commit 5195179150
3 changed files with 20 additions and 31 deletions

View File

@@ -1,4 +1,5 @@
import type { OpenClawConfig } from "../config/config.js";
import { ensurePluginAllowlisted } from "../config/plugins-allowlist.js";
export type PluginEnableResult = {
config: OpenClawConfig;
@@ -6,20 +7,6 @@ export type PluginEnableResult = {
reason?: string;
};
function ensureAllowlisted(cfg: OpenClawConfig, pluginId: string): OpenClawConfig {
const allow = cfg.plugins?.allow;
if (!Array.isArray(allow) || allow.includes(pluginId)) {
return cfg;
}
return {
...cfg,
plugins: {
...cfg.plugins,
allow: [...allow, pluginId],
},
};
}
export function enablePluginInConfig(cfg: OpenClawConfig, pluginId: string): PluginEnableResult {
if (cfg.plugins?.enabled === false) {
return { config: cfg, enabled: false, reason: "plugins disabled" };
@@ -42,6 +29,6 @@ export function enablePluginInConfig(cfg: OpenClawConfig, pluginId: string): Plu
entries,
},
};
next = ensureAllowlisted(next, pluginId);
next = ensurePluginAllowlisted(next, pluginId);
return { config: next, enabled: true };
}