mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-26 16:41:49 +00:00
refactor: share normalized account lookups
This commit is contained in:
@@ -6,6 +6,29 @@ import { resolveNextcloudTalkAccount } from "./accounts.js";
|
||||
import type { CoreConfig } from "./types.js";
|
||||
|
||||
describe("resolveNextcloudTalkAccount", () => {
|
||||
it("matches normalized configured account ids", () => {
|
||||
const account = resolveNextcloudTalkAccount({
|
||||
cfg: {
|
||||
channels: {
|
||||
"nextcloud-talk": {
|
||||
accounts: {
|
||||
"Ops Team": {
|
||||
baseUrl: "https://cloud.example.com",
|
||||
botSecret: "bot-secret",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as CoreConfig,
|
||||
accountId: "ops-team",
|
||||
});
|
||||
|
||||
expect(account.accountId).toBe("ops-team");
|
||||
expect(account.baseUrl).toBe("https://cloud.example.com");
|
||||
expect(account.secret).toBe("bot-secret");
|
||||
expect(account.secretSource).toBe("config");
|
||||
});
|
||||
|
||||
it.runIf(process.platform !== "win32")("rejects symlinked botSecretFile paths", () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-nextcloud-talk-"));
|
||||
const secretFile = path.join(dir, "secret.txt");
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { mergeAccountConfig } from "openclaw/plugin-sdk/account-resolution";
|
||||
import {
|
||||
mergeAccountConfig,
|
||||
resolveNormalizedAccountEntry,
|
||||
} from "openclaw/plugin-sdk/account-resolution";
|
||||
import { tryReadSecretFileSync } from "openclaw/plugin-sdk/infra-runtime";
|
||||
import {
|
||||
createAccountListHelpers,
|
||||
@@ -48,17 +51,13 @@ function resolveAccountConfig(
|
||||
cfg: CoreConfig,
|
||||
accountId: string,
|
||||
): NextcloudTalkAccountConfig | undefined {
|
||||
const accounts = cfg.channels?.["nextcloud-talk"]?.accounts;
|
||||
if (!accounts || typeof accounts !== "object") {
|
||||
return undefined;
|
||||
}
|
||||
const direct = accounts[accountId] as NextcloudTalkAccountConfig | undefined;
|
||||
if (direct) {
|
||||
return direct;
|
||||
}
|
||||
const normalized = normalizeAccountId(accountId);
|
||||
const matchKey = Object.keys(accounts).find((key) => normalizeAccountId(key) === normalized);
|
||||
return matchKey ? (accounts[matchKey] as NextcloudTalkAccountConfig | undefined) : undefined;
|
||||
return resolveNormalizedAccountEntry(
|
||||
cfg.channels?.["nextcloud-talk"]?.accounts as
|
||||
| Record<string, NextcloudTalkAccountConfig>
|
||||
| undefined,
|
||||
accountId,
|
||||
normalizeAccountId,
|
||||
);
|
||||
}
|
||||
|
||||
function mergeNextcloudTalkAccountConfig(
|
||||
|
||||
Reference in New Issue
Block a user