Skip to content

Commit

Permalink
refactor!: Switch to loading configuation files as YAML (#484)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: All configruation file must now be in YAML format. The default file name has changed to be configuration.yaml

closes #424

Signed-off-by: Leonard Goodell <[email protected]>
  • Loading branch information
Lenny Goodell authored Mar 16, 2023
1 parent 7a040af commit 9d98d1e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions bootstrap/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"math"
"os"
"reflect"
"strconv"
"strings"
Expand All @@ -29,6 +30,7 @@ import (

"github.com/edgexfoundry/go-mod-core-contracts/v3/common"
"github.com/mitchellh/copystructure"
"gopkg.in/yaml.v3"

"github.com/edgexfoundry/go-mod-bootstrap/v3/config"

Expand Down Expand Up @@ -507,16 +509,26 @@ func CreateProviderClient(
return configuration.NewConfigurationClient(providerConfig)
}

// loadPrivateFromFile attempts to read the configuration toml file
// loadPrivateFromFile attempts to read the local configuration file
func (cp *Processor) loadPrivateFromFile() (*toml.Tree, error) {
// pull the private config and convert it to a map[string]any
filePath := GetConfigLocation(cp.lc, cp.flags)
contents, err := toml.LoadFile(filePath)
contents, err := os.ReadFile(filePath)
if err != nil {
return nil, fmt.Errorf("could not load private configuration file (%s): %s", filePath, err.Error())
}

config := make(map[string]any)
if err := yaml.Unmarshal(contents, &config); err != nil {
return nil, fmt.Errorf("could not un-marshal configuration file as YAML (%s): %s", filePath, err.Error())
}

tomlTree, err := toml.TreeFromMap(config)
if err != nil {
return nil, fmt.Errorf("could not convert to TOML Tree: %s", err.Error())
}

cp.lc.Info(fmt.Sprintf("Loaded private configuration from %s", filePath))
return contents, nil
return tomlTree, nil
}

func (cp *Processor) mergeTomlWithConfig(config interface{}, tomlTree *toml.Tree) error {
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

const (
DefaultConfigProvider = "consul.http://localhost:8500"
DefaultConfigFile = "configuration.toml"
DefaultConfigFile = "configuration.yaml"
)

// Common is an interface that defines AP for the common command-line flags used by most EdgeX services
Expand Down

0 comments on commit 9d98d1e

Please sign in to comment.