MCPcopy
hub / github.com/netdata/netdata / LoadFileConfigs

Function LoadFileConfigs

src/go/plugin/agent/secrets/secretstore/fileconfig.go:20–78  ·  view source on GitHub ↗
(roots []string)

Source from the content-addressed store, hash-verified

18}
19
20func LoadFileConfigs(roots []string) ([]Config, []error) {
21 var cfgs []Config
22 var errs []error
23
24 for _, root := range roots {
25 root = strings.TrimSpace(root)
26 if root == "" {
27 continue
28 }
29
30 dir := filepath.Join(root, "ss")
31 entries, err := os.ReadDir(dir)
32 if err != nil {
33 continue
34 }
35
36 for _, entry := range entries {
37 if !entry.Type().IsRegular() {
38 continue
39 }
40
41 ext := strings.ToLower(filepath.Ext(entry.Name()))
42 if ext != ".conf" && ext != ".yaml" && ext != ".yml" {
43 continue
44 }
45
46 path := filepath.Join(dir, entry.Name())
47 stem := strings.TrimSpace(strings.TrimSuffix(entry.Name(), filepath.Ext(entry.Name())))
48
49 jobs, jobErrs := loadFileConfigJobs(path)
50 errs = append(errs, jobErrs...)
51 if len(jobs) == 0 {
52 continue
53 }
54
55 sourceType := fileConfigSourceType(path)
56 source := "file=" + path
57 for i, job := range jobs {
58 cfg := Config(job)
59 if strings.TrimSpace(cfg.Name()) == "" {
60 errs = append(errs, fmt.Errorf("secretstore file config '%s' job %d: store name is required", path, i+1))
61 continue
62 }
63 if cfg.Kind() == "" {
64 cfg.SetKind(StoreKind(stem))
65 }
66 cfg.SetSource(source)
67 cfg.SetSourceType(sourceType)
68 if err := validateFileConfig(cfg); err != nil {
69 errs = append(errs, fmt.Errorf("secretstore file config '%s' job %d: %w", path, i+1, err))
70 continue
71 }
72 cfgs = append(cfgs, cfg)
73 }
74 }
75 }
76
77 return cfgs, errs

Callers

nothing calls this directly

Calls 13

loadFileConfigJobsFunction · 0.85
fileConfigSourceTypeFunction · 0.85
StoreKindTypeAlias · 0.85
validateFileConfigFunction · 0.85
SetKindMethod · 0.80
ConfigTypeAlias · 0.70
ReadDirMethod · 0.65
NameMethod · 0.65
ErrorfMethod · 0.65
KindMethod · 0.65
TypeMethod · 0.45
SetSourceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…