feat: add confd folder
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
0239b0cab2
commit
5be3a1d4e2
1 changed files with 33 additions and 0 deletions
33
config.go
33
config.go
|
|
@ -63,6 +63,39 @@ func ReadFromFile(path string) (config, error) {
|
||||||
return config{}, fmt.Errorf(ErrWrapTemplate, ErrCantParseConfigFile, err)
|
return config{}, fmt.Errorf(ErrWrapTemplate, ErrCantParseConfigFile, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfgFolder := "/etc/scron/conf.d/"
|
||||||
|
|
||||||
|
if _, err := os.Stat(cfgFolder); os.IsNotExist(err) {
|
||||||
|
return c, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
entries, err := os.ReadDir("./")
|
||||||
|
if err != nil {
|
||||||
|
return c, fmt.Errorf("cant scan confd folder: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, file := range entries {
|
||||||
|
if !strings.HasSuffix(file.Name(), ".yml") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
fileContent, err := os.ReadFile(cfgFolder + file.Name())
|
||||||
|
if err != nil {
|
||||||
|
return config{}, fmt.Errorf("cant read config file %s: %w", file.Name(), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fileConfig := config{}
|
||||||
|
|
||||||
|
err = yaml.Unmarshal(fileContent, &fileConfig)
|
||||||
|
if err != nil {
|
||||||
|
return config{}, fmt.Errorf("cant unmarshal yml config: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Jobs = append(c.Jobs, fileConfig.Jobs...)
|
||||||
|
c.Notification = append(c.Notification, fileConfig.Notification...)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue