Skip to content

Commit

Permalink
Refactor configuration functionality (#687)
Browse files Browse the repository at this point in the history
* reduced config file

* updated tests

* fixed tests after merge

* fixed fmt

* minor fix
  • Loading branch information
AndrewChubatiuk authored and okushchenko committed Mar 24, 2018
1 parent a23aa1c commit 93c8904
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 295 deletions.
42 changes: 23 additions & 19 deletions backends/config.go
@@ -1,24 +1,28 @@
package backends

import (
util "github.com/kelseyhightower/confd/util"
)

type Config struct {
AuthToken string
AuthType string
Backend string
BasicAuth bool
ClientCaKeys string
ClientCert string
ClientKey string
BackendNodes []string
Password string
Scheme string
Table string
Separator string
Username string
AppID string
UserID string
RoleID string
SecretID string
YAMLFile []string
Filter string
AuthToken string `toml:"auth_token"`
AuthType string `toml:"auth_type"`
Backend string `toml:"backend"`
BasicAuth bool `toml:"basic_auth"`
ClientCaKeys string `toml:"client_cakeys"`
ClientCert string `toml:"client_cert"`
ClientKey string `toml:"client_key"`
BackendNodes util.Nodes `toml:"nodes"`
Password string `toml:"password"`
Scheme string `toml:"scheme"`
Table string `toml:"table"`
Separator string `toml:"separator"`
Username string `toml:"username"`
AppID string `toml:"app_id"`
UserID string `toml:"user_id"`
RoleID string `toml:"role_id"`
SecretID string `toml:"secret_id"`
YAMLFile util.Nodes `toml:"file"`
Filter string `toml:"filter"`
Role string
}
14 changes: 7 additions & 7 deletions confd.go
Expand Up @@ -15,7 +15,7 @@ import (

func main() {
flag.Parse()
if printVersion {
if config.PrintVersion {
fmt.Printf("confd %s (Git SHA: %s, Go Version: %s)\n", Version, GitSHA, runtime.Version())
os.Exit(0)
}
Expand All @@ -25,14 +25,14 @@ func main() {

log.Info("Starting confd")

storeClient, err := backends.New(backendsConfig)
storeClient, err := backends.New(config.BackendsConfig)
if err != nil {
log.Fatal(err.Error())
}

templateConfig.StoreClient = storeClient
if onetime {
if err := template.Process(templateConfig); err != nil {
config.TemplateConfig.StoreClient = storeClient
if config.OneTime {
if err := template.Process(config.TemplateConfig); err != nil {
log.Fatal(err.Error())
}
os.Exit(0)
Expand All @@ -45,9 +45,9 @@ func main() {
var processor template.Processor
switch {
case config.Watch:
processor = template.WatchProcessor(templateConfig, stopChan, doneChan, errChan)
processor = template.WatchProcessor(config.TemplateConfig, stopChan, doneChan, errChan)
default:
processor = template.IntervalProcessor(templateConfig, stopChan, doneChan, errChan, config.Interval)
processor = template.IntervalProcessor(config.TemplateConfig, stopChan, doneChan, errChan, config.Interval)
}

go processor.Process()
Expand Down

0 comments on commit 93c8904

Please sign in to comment.