-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprovenance.go
More file actions
52 lines (42 loc) · 1.22 KB
/
provenance.go
File metadata and controls
52 lines (42 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package rigging
import "sync"
// Provenance contains source information for configuration fields.
type Provenance struct {
Fields []FieldProvenance
}
// FieldProvenance describes where a field's value came from.
type FieldProvenance struct {
FieldPath string // Dot notation (e.g., "Database.Host")
KeyPath string // Normalized key (e.g., "database.host")
SourceName string // Source identifier (e.g., "env:APP_PORT")
Secret bool // Whether field is secret
}
var provenanceStore sync.Map
// GetProvenance returns provenance metadata for a loaded configuration.
// Thread-safe.
func GetProvenance[T any](cfg *T) (*Provenance, bool) {
if cfg == nil {
return nil, false
}
value, ok := provenanceStore.Load(cfg)
if !ok {
return nil, false
}
prov, ok := value.(*Provenance)
return prov, ok
}
func storeProvenance[T any](cfg *T, prov *Provenance) {
if cfg != nil && prov != nil {
provenanceStore.Store(cfg, prov)
}
}
func deleteProvenance[T any](cfg *T) {
if cfg != nil {
provenanceStore.Delete(cfg)
}
}
// ReleaseProvenance removes stored provenance for a config instance.
// Use this in long-lived processes once provenance is no longer needed.
func ReleaseProvenance[T any](cfg *T) {
deleteProvenance(cfg)
}