|
| 1 | +import { |
| 2 | + collectNestedChannelFieldAssignments, |
| 3 | + collectSimpleChannelFieldAssignments, |
| 4 | + getChannelSurface, |
| 5 | + isBaseFieldActiveForChannelSurface, |
| 6 | + isEnabledFlag, |
| 7 | + isRecord, |
| 8 | + type ResolverContext, |
| 9 | + type SecretDefaults, |
| 10 | + type SecretTargetRegistryEntry, |
| 11 | +} from "openclaw/plugin-sdk/security-runtime"; |
| 12 | + |
| 13 | +export const secretTargetRegistryEntries = [ |
| 14 | + { |
| 15 | + id: "channels.irc.accounts.*.nickserv.password", |
| 16 | + targetType: "channels.irc.accounts.*.nickserv.password", |
| 17 | + configFile: "openclaw.json", |
| 18 | + pathPattern: "channels.irc.accounts.*.nickserv.password", |
| 19 | + secretShape: "secret_input", |
| 20 | + expectedResolvedValue: "string", |
| 21 | + includeInPlan: true, |
| 22 | + includeInConfigure: true, |
| 23 | + includeInAudit: true, |
| 24 | + }, |
| 25 | + { |
| 26 | + id: "channels.irc.accounts.*.password", |
| 27 | + targetType: "channels.irc.accounts.*.password", |
| 28 | + configFile: "openclaw.json", |
| 29 | + pathPattern: "channels.irc.accounts.*.password", |
| 30 | + secretShape: "secret_input", |
| 31 | + expectedResolvedValue: "string", |
| 32 | + includeInPlan: true, |
| 33 | + includeInConfigure: true, |
| 34 | + includeInAudit: true, |
| 35 | + }, |
| 36 | + { |
| 37 | + id: "channels.irc.nickserv.password", |
| 38 | + targetType: "channels.irc.nickserv.password", |
| 39 | + configFile: "openclaw.json", |
| 40 | + pathPattern: "channels.irc.nickserv.password", |
| 41 | + secretShape: "secret_input", |
| 42 | + expectedResolvedValue: "string", |
| 43 | + includeInPlan: true, |
| 44 | + includeInConfigure: true, |
| 45 | + includeInAudit: true, |
| 46 | + }, |
| 47 | + { |
| 48 | + id: "channels.irc.password", |
| 49 | + targetType: "channels.irc.password", |
| 50 | + configFile: "openclaw.json", |
| 51 | + pathPattern: "channels.irc.password", |
| 52 | + secretShape: "secret_input", |
| 53 | + expectedResolvedValue: "string", |
| 54 | + includeInPlan: true, |
| 55 | + includeInConfigure: true, |
| 56 | + includeInAudit: true, |
| 57 | + }, |
| 58 | +] satisfies SecretTargetRegistryEntry[]; |
| 59 | + |
| 60 | +export function collectRuntimeConfigAssignments(params: { |
| 61 | + config: { channels?: Record<string, unknown> }; |
| 62 | + defaults: SecretDefaults | undefined; |
| 63 | + context: ResolverContext; |
| 64 | +}): void { |
| 65 | + const resolved = getChannelSurface(params.config, "irc"); |
| 66 | + if (!resolved) { |
| 67 | + return; |
| 68 | + } |
| 69 | + const { channel: irc, surface } = resolved; |
| 70 | + collectSimpleChannelFieldAssignments({ |
| 71 | + channelKey: "irc", |
| 72 | + field: "password", |
| 73 | + channel: irc, |
| 74 | + surface, |
| 75 | + defaults: params.defaults, |
| 76 | + context: params.context, |
| 77 | + topInactiveReason: "no enabled account inherits this top-level IRC password.", |
| 78 | + accountInactiveReason: "IRC account is disabled.", |
| 79 | + }); |
| 80 | + collectNestedChannelFieldAssignments({ |
| 81 | + channelKey: "irc", |
| 82 | + nestedKey: "nickserv", |
| 83 | + field: "password", |
| 84 | + channel: irc, |
| 85 | + surface, |
| 86 | + defaults: params.defaults, |
| 87 | + context: params.context, |
| 88 | + topLevelActive: |
| 89 | + isBaseFieldActiveForChannelSurface(surface, "nickserv") && |
| 90 | + isRecord(irc.nickserv) && |
| 91 | + isEnabledFlag(irc.nickserv), |
| 92 | + topInactiveReason: |
| 93 | + "no enabled account inherits this top-level IRC nickserv config or NickServ is disabled.", |
| 94 | + accountActive: ({ account, enabled }) => |
| 95 | + enabled && isRecord(account.nickserv) && isEnabledFlag(account.nickserv), |
| 96 | + accountInactiveReason: "IRC account is disabled or NickServ is disabled for this account.", |
| 97 | + }); |
| 98 | +} |
0 commit comments