mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-23 06:21:24 +00:00
* refactor(deadcode): trim auto-reply and CLI exports * refactor(deadcode): trim cron and task exports * refactor(deadcode): trim fleet and process exports * test(deadcode): exercise live task and process seams * test(fleet): cover stream redaction through owner module * refactor(security): trim dead internal exports * refactor(secrets): trim dead internal exports * refactor(deadcode): trim remaining src exports * refactor(deadcode): remove test-only runtime exports * refactor(deadcode): trim pairing test exports * refactor(deadcode): reconcile refreshed baseline * test(auto-reply): deduplicate queue state imports
100 lines
3.7 KiB
TypeScript
100 lines
3.7 KiB
TypeScript
/** Collects and analyzes command-scoped secret assignments from OpenClaw config. */
|
|
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
|
import { coerceSecretRef, resolveSecretInputRef } from "../config/types.secrets.js";
|
|
import { getPath } from "./path-utils.js";
|
|
import { isExpectedResolvedSecretValue } from "./secret-value.js";
|
|
import { discoverConfigSecretTargetsByIds } from "./target-registry.js";
|
|
|
|
/** One resolved SecretRef value ready to inject into a command-scoped config view. */
|
|
/** One command config path whose value can be resolved from a SecretRef. */
|
|
export type CommandSecretAssignment = {
|
|
path: string;
|
|
pathSegments: string[];
|
|
value: unknown;
|
|
};
|
|
|
|
/** Active or inactive command target that could not be materialized. */
|
|
export type UnresolvedCommandSecretAssignment = {
|
|
path: string;
|
|
pathSegments: string[];
|
|
};
|
|
|
|
/** Full command assignment analysis before unresolved active refs are rejected. */
|
|
type AnalyzeAssignmentsFromSnapshotResult = {
|
|
assignments: CommandSecretAssignment[];
|
|
diagnostics: string[];
|
|
unresolved: UnresolvedCommandSecretAssignment[];
|
|
inactive: UnresolvedCommandSecretAssignment[];
|
|
};
|
|
|
|
/**
|
|
* Compares source SecretRefs with the active resolved snapshot for command-time assignments.
|
|
*/
|
|
/** Analyzes command secret assignments without mutating the source config. */
|
|
export function analyzeCommandSecretAssignmentsFromSnapshot(params: {
|
|
sourceConfig: OpenClawConfig;
|
|
resolvedConfig: OpenClawConfig;
|
|
targetIds: ReadonlySet<string>;
|
|
inactiveRefPaths?: ReadonlySet<string>;
|
|
allowedPaths?: ReadonlySet<string>;
|
|
}): AnalyzeAssignmentsFromSnapshotResult {
|
|
const defaults = params.sourceConfig.secrets?.defaults;
|
|
const assignments: CommandSecretAssignment[] = [];
|
|
const diagnostics: string[] = [];
|
|
const unresolved: UnresolvedCommandSecretAssignment[] = [];
|
|
const inactive: UnresolvedCommandSecretAssignment[] = [];
|
|
|
|
for (const target of discoverConfigSecretTargetsByIds(params.sourceConfig, params.targetIds)) {
|
|
if (params.allowedPaths && !params.allowedPaths.has(target.path)) {
|
|
continue;
|
|
}
|
|
const { explicitRef, ref } = resolveSecretInputRef({
|
|
value: target.value,
|
|
refValue: target.refValue,
|
|
defaults,
|
|
});
|
|
const inlineCandidateRef = explicitRef ? coerceSecretRef(target.value, defaults) : null;
|
|
if (!ref) {
|
|
continue;
|
|
}
|
|
|
|
const resolved = getPath(params.resolvedConfig, target.pathSegments);
|
|
if (!isExpectedResolvedSecretValue(resolved, target.entry.expectedResolvedValue)) {
|
|
// Inactive surfaces are diagnostics, not hard failures; active unresolved refs block the
|
|
// command because the runtime snapshot promised that target was usable.
|
|
if (params.inactiveRefPaths?.has(target.path)) {
|
|
diagnostics.push(
|
|
`${target.path}: secret ref is configured on an inactive surface; skipping command-time assignment.`,
|
|
);
|
|
inactive.push({
|
|
path: target.path,
|
|
pathSegments: [...target.pathSegments],
|
|
});
|
|
continue;
|
|
}
|
|
unresolved.push({
|
|
path: target.path,
|
|
pathSegments: [...target.pathSegments],
|
|
});
|
|
continue;
|
|
}
|
|
|
|
assignments.push({
|
|
path: target.path,
|
|
pathSegments: [...target.pathSegments],
|
|
value: resolved,
|
|
});
|
|
|
|
const hasCompetingSiblingRef =
|
|
target.entry.secretShape === "sibling_ref" && explicitRef && inlineCandidateRef; // pragma: allowlist secret
|
|
if (hasCompetingSiblingRef) {
|
|
// Sibling refs are the canonical target for these surfaces; inline refs are legacy overlap.
|
|
diagnostics.push(
|
|
`${target.path}: both inline and sibling ref were present; sibling ref took precedence.`,
|
|
);
|
|
}
|
|
}
|
|
|
|
return { assignments, diagnostics, unresolved, inactive };
|
|
}
|