mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04:00
refactor: centralize plugin allowlist mutation
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user