Skip to content

Commit

Permalink
Merge pull request #97 from gr455/use-viper
Browse files Browse the repository at this point in the history
Move to Viper for config management
  • Loading branch information
Revolyssup committed Jun 4, 2022
2 parents 94ce7bf + 731ed98 commit e7b29a0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
47 changes: 36 additions & 11 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"path"
"strings"

"github.com/layer5io/meshery-adapter-library/adapter"
"github.com/layer5io/meshery-adapter-library/common"
"github.com/layer5io/meshery-adapter-library/config"
configprovider "github.com/layer5io/meshery-adapter-library/config/provider"
configprovider "github.com/layer5io/meshkit/config/provider"
"github.com/layer5io/meshery-adapter-library/status"

// "github.com/layer5io/meshery-adapter-library"
Expand Down Expand Up @@ -34,10 +35,9 @@ var (
configRootPath = path.Join(utils.GetHome(), ".meshery")

Config = configprovider.Options{
ServerConfig: ServerConfig,
MeshSpec: MeshSpec,
ProviderConfig: ProviderConfig,
Operations: Operations,
FilePath: configRootPath,
FileName: "app-mesh",
FileType: "yaml",
}

// ServerConfig is the configuration for the gRPC server
Expand Down Expand Up @@ -75,22 +75,47 @@ var (
)

// New creates a new config instance
func New(provider string) (config.Handler, error) {
func New(provider string) (h config.Handler, err error) {
// Config provider
switch provider {
case configprovider.ViperKey:
return configprovider.NewViper(Config)
h, err = configprovider.NewViper(Config)
if err != nil {
return nil, err
}
case configprovider.InMemKey:
return configprovider.NewInMem(Config)
h, err = configprovider.NewInMem(Config)
if err != nil {
return nil, err
}
default:
return nil, ErrEmptyConfig
}

return nil, ErrEmptyConfig
// Setup server config
if err := h.SetObject(adapter.ServerKey, ServerConfig); err != nil {
return nil, err
}

// Setup mesh config
if err := h.SetObject(adapter.MeshSpecKey, MeshSpec); err != nil {
return nil, err
}

// Setup Operations Config
if err := h.SetObject(adapter.OperationsKey, Operations); err != nil {
return nil, err
}

return h, nil
}

func NewKubeconfigBuilder(provider string) (config.Handler, error) {
opts := configprovider.Options{}
opts.ProviderConfig = KubeConfig
opts := configprovider.Options{
FilePath: configRootPath,
FileType: "yaml",
FileName: "kubeconfig",
}

// Config provider
switch provider {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func main() {

// Initialize application specific configs and dependencies
// App and request config
cfg, err := config.New(configprovider.InMemKey)
cfg, err := config.New(configprovider.ViperKey)
if err != nil {
log.Error(err)
os.Exit(1)
Expand Down

0 comments on commit e7b29a0

Please sign in to comment.