mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 05:40:44 +00:00
fix(discord): avoid resolving tokens for read-only accessors
This commit is contained in:
@@ -128,4 +128,32 @@ describe("discordConfigAdapter", () => {
|
||||
"123456789",
|
||||
]);
|
||||
});
|
||||
|
||||
it("keeps read-only accessors from resolving token SecretRefs", () => {
|
||||
const cfg = {
|
||||
secrets: {
|
||||
providers: {
|
||||
discord_token: {
|
||||
source: "file",
|
||||
path: "/tmp/openclaw-missing-discord-token",
|
||||
mode: "singleValue",
|
||||
},
|
||||
},
|
||||
},
|
||||
channels: {
|
||||
discord: {
|
||||
token: { source: "file", provider: "discord_token", id: "value" },
|
||||
allowFrom: ["1128540374256849009"],
|
||||
defaultTo: "1498959610751750304",
|
||||
},
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
|
||||
expect(discordConfigAdapter.resolveAllowFrom?.({ cfg, accountId: "default" })).toEqual([
|
||||
"1128540374256849009",
|
||||
]);
|
||||
expect(discordConfigAdapter.resolveDefaultTo?.({ cfg, accountId: "default" })).toBe(
|
||||
"1498959610751750304",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { describeAccountSnapshot } from "openclaw/plugin-sdk/account-helpers";
|
||||
import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
||||
import { formatAllowFromLowercase } from "openclaw/plugin-sdk/allow-from";
|
||||
import { adaptScopedAccountAccessor } from "openclaw/plugin-sdk/channel-config-helpers";
|
||||
import { createScopedChannelConfigAdapter } from "openclaw/plugin-sdk/channel-config-helpers";
|
||||
@@ -7,6 +8,7 @@ import { inspectDiscordAccount } from "./account-inspect.js";
|
||||
import {
|
||||
isDiscordAccountEnabledForRuntime,
|
||||
listDiscordAccountIds,
|
||||
mergeDiscordAccountConfig,
|
||||
resolveDefaultDiscordAccountId,
|
||||
resolveDiscordAccount,
|
||||
resolveDiscordAccountAllowFrom,
|
||||
@@ -66,10 +68,13 @@ function resolveDiscordConfigAccessorAccount(params: {
|
||||
cfg: OpenClawConfig;
|
||||
accountId?: string | null;
|
||||
}): DiscordConfigAccessorAccount {
|
||||
const account = resolveDiscordAccount(params);
|
||||
const accountId = normalizeAccountId(
|
||||
params.accountId ?? resolveDefaultDiscordAccountId(params.cfg),
|
||||
);
|
||||
const config = mergeDiscordAccountConfig(params.cfg, accountId);
|
||||
return {
|
||||
allowFrom: resolveDiscordAccountAllowFrom({ cfg: params.cfg, accountId: account.accountId }),
|
||||
defaultTo: account.config.defaultTo,
|
||||
allowFrom: resolveDiscordAccountAllowFrom({ cfg: params.cfg, accountId }),
|
||||
defaultTo: config.defaultTo,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user