Add safe historical configuration explanations

This commit is contained in:
2026-09-06 22:14:54 +00:00
parent d4ec8607d1
commit 6ef240b1a0
17 changed files with 1032 additions and 141 deletions

View File

@@ -3,7 +3,6 @@ package configkit
import (
"errors"
"io"
"slices"
"strings"
"gitea.maximumdirect.net/eric/ConfigKit/internal/document"
@@ -24,31 +23,8 @@ func (r *Result[T]) WriteEffective(output io.Writer) error {
}
func redactedDocument(node *document.Node, secret map[string]bool, path Path) *document.Node {
if node == nil {
return nil
}
if pathIsSecret(secret, path) {
return &document.Node{Kind: document.String, Text: "[REDACTED]"}
}
result := *node
switch node.Kind {
case document.Mapping:
result.Mapping = make([]document.Entry, len(node.Mapping))
copy(result.Mapping, node.Mapping)
slices.SortFunc(result.Mapping, func(left, right document.Entry) int {
return strings.Compare(left.Key, right.Key)
})
for index := range result.Mapping {
entry := &result.Mapping[index]
entry.Value = redactedDocument(entry.Value, secret, path.Key(entry.Key))
}
case document.Sequence:
result.Sequence = make([]*document.Node, len(node.Sequence))
for index, child := range node.Sequence {
result.Sequence[index] = redactedDocument(child, secret, path.Index(index))
}
}
return &result
result, _ := safeSnapshotDocument(node, secret, path)
return result
}
func pathIsSecret(secret map[string]bool, path Path) bool {