mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 05:14:33 +00:00
refactor(core): dedupe shared config and runtime helpers
This commit is contained in:
@@ -373,6 +373,18 @@ class RedactionError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
function restoreOriginalValueOrThrow(params: {
|
||||
key: string;
|
||||
path: string;
|
||||
original: Record<string, unknown>;
|
||||
}): unknown {
|
||||
if (params.key in params.original) {
|
||||
return params.original[params.key];
|
||||
}
|
||||
log.warn(`Cannot un-redact config key ${params.path} as it doesn't have any value`);
|
||||
throw new RedactionError(params.path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Worker for restoreRedactedValues().
|
||||
* Used when there are ConfigUiHints available.
|
||||
@@ -427,12 +439,7 @@ function restoreRedactedValuesWithLookup(
|
||||
if (lookup.has(candidate)) {
|
||||
matched = true;
|
||||
if (value === REDACTED_SENTINEL) {
|
||||
if (key in orig) {
|
||||
result[key] = orig[key];
|
||||
} else {
|
||||
log.warn(`Cannot un-redact config key ${candidate} as it doesn't have any value`);
|
||||
throw new RedactionError(candidate);
|
||||
}
|
||||
result[key] = restoreOriginalValueOrThrow({ key, path: candidate, original: orig });
|
||||
} else if (typeof value === "object" && value !== null) {
|
||||
result[key] = restoreRedactedValuesWithLookup(value, orig[key], lookup, candidate, hints);
|
||||
}
|
||||
@@ -442,12 +449,7 @@ function restoreRedactedValuesWithLookup(
|
||||
if (!matched && isExtensionPath(path)) {
|
||||
const markedNonSensitive = isExplicitlyNonSensitivePath(hints, [path, wildcardPath]);
|
||||
if (!markedNonSensitive && isSensitivePath(path) && value === REDACTED_SENTINEL) {
|
||||
if (key in orig) {
|
||||
result[key] = orig[key];
|
||||
} else {
|
||||
log.warn(`Cannot un-redact config key ${path} as it doesn't have any value`);
|
||||
throw new RedactionError(path);
|
||||
}
|
||||
result[key] = restoreOriginalValueOrThrow({ key, path, original: orig });
|
||||
} else if (typeof value === "object" && value !== null) {
|
||||
result[key] = restoreRedactedValuesGuessing(value, orig[key], path, hints);
|
||||
}
|
||||
@@ -506,12 +508,7 @@ function restoreRedactedValuesGuessing(
|
||||
isSensitivePath(path) &&
|
||||
value === REDACTED_SENTINEL
|
||||
) {
|
||||
if (key in orig) {
|
||||
result[key] = orig[key];
|
||||
} else {
|
||||
log.warn(`Cannot un-redact config key ${path} as it doesn't have any value`);
|
||||
throw new RedactionError(path);
|
||||
}
|
||||
result[key] = restoreOriginalValueOrThrow({ key, path, original: orig });
|
||||
} else if (typeof value === "object" && value !== null) {
|
||||
result[key] = restoreRedactedValuesGuessing(value, orig[key], path, hints);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user