Add safe historical configuration explanations
This commit is contained in:
28
render.go
28
render.go
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user