Skip to content

Commit

Permalink
Merge pull request #28 from kristoflemmens/fix-issue-with-empty-confi…
Browse files Browse the repository at this point in the history
…g-dir

Only process config-dir when config-dir is not empty
  • Loading branch information
marcial-lopezferrada-hs authored Apr 14, 2022
2 parents dd37d74 + 1971f0f commit f3fe0fa
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CURRENTOS := $(shell go env GOOS)
CURRENTARCH := $(shell go env GOARCH)
COMMIT := $(shell git rev-parse --short HEAD)
VERSION := v1.3.5
VERSION := v1.3.6
LDFLAGS="-X main.buildVersion=$(VERSION) -X main.commitVersion=$(COMMIT)"

.DEFAULT_GOAL := build
Expand Down
68 changes: 34 additions & 34 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,46 +174,46 @@ func ReadConfigFile(configFile string, configDir string, inputPrefix, outputPref
return nil, fmt.Errorf("could not parse config file %q: %w", absConfigFile, err)
}

_, err = os.Stat(util.AbsolutePath(inputPrefix, configDir))
if configDir != "" && os.IsNotExist(err) {
zlog.Error().Err(err).Msg("config directory doesn't exist")

} else {
items, err := ioutil.ReadDir(util.AbsolutePath(inputPrefix, configDir))
if err != nil {
log.Error().Err(err).Msg("Error reading directory")
return nil, fmt.Errorf("could not read config directory %q: %w", configDir, err)
}
for _, item := range items {
fileExtension := filepath.Ext(item.Name())
if (fileExtension == ".yaml" || fileExtension == ".yml") && !item.IsDir() {

currentConfigFile := util.AbsolutePath(inputPrefix, configDir) + "/" + item.Name()
log.Debug().Msg("reading config file " + currentConfigFile)
yamlFile, err := ioutil.ReadFile(currentConfigFile)
if err != nil {
log.Error().Err(err).Msg("could not read config file")
return nil, fmt.Errorf("trouble reading config file %q: %w", currentConfigFile, err)
}
if configDir != "" {
_, err = os.Stat(util.AbsolutePath(inputPrefix, configDir))

currentConfig, err := ReadConfig(log, yamlFile, inputPrefix, outputPrefix)
config.VaultConfig.Secrets = append(config.VaultConfig.Secrets, currentConfig.VaultConfig.Secrets...)
config.VaultConfig.Templates = append(config.VaultConfig.Templates, currentConfig.VaultConfig.Templates...)
config.VaultConfig.SSHCertificates = append(config.VaultConfig.SSHCertificates, currentConfig.VaultConfig.SSHCertificates...)
config.VaultConfig.AWS = append(config.VaultConfig.AWS, currentConfig.VaultConfig.AWS...)
for k, v := range currentConfig.Templates {
config.Templates[k] = v
}
for k, v := range currentConfig.Composites {
config.Composites[k] = v
if os.IsNotExist(err) {
zlog.Error().Err(err).Msg("config directory doesn't exist")
} else {

items, err := ioutil.ReadDir(util.AbsolutePath(inputPrefix, configDir))
if err != nil {
log.Error().Err(err).Msg("Error reading directory")
return nil, fmt.Errorf("could not read config directory %q: %w", configDir, err)
}
for _, item := range items {
fileExtension := filepath.Ext(item.Name())
if (fileExtension == ".yaml" || fileExtension == ".yml") && !item.IsDir() {

currentConfigFile := util.AbsolutePath(inputPrefix, configDir) + "/" + item.Name()
log.Debug().Msg("reading config file " + currentConfigFile)
yamlFile, err := ioutil.ReadFile(currentConfigFile)
if err != nil {
log.Error().Err(err).Msg("could not read config file")
return nil, fmt.Errorf("trouble reading config file %q: %w", currentConfigFile, err)
}

currentConfig, err := ReadConfig(log, yamlFile, inputPrefix, outputPrefix)
config.VaultConfig.Secrets = append(config.VaultConfig.Secrets, currentConfig.VaultConfig.Secrets...)
config.VaultConfig.Templates = append(config.VaultConfig.Templates, currentConfig.VaultConfig.Templates...)
config.VaultConfig.SSHCertificates = append(config.VaultConfig.SSHCertificates, currentConfig.VaultConfig.SSHCertificates...)
config.VaultConfig.AWS = append(config.VaultConfig.AWS, currentConfig.VaultConfig.AWS...)
for k, v := range currentConfig.Templates {
config.Templates[k] = v
}
for k, v := range currentConfig.Composites {
config.Composites[k] = v
}
}

}
}
}

return config, err

}

// createCompositeSecrets brings an obscure feature of v1 where multiple secret stanzas could
Expand Down

0 comments on commit f3fe0fa

Please sign in to comment.