Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into add-dep
Browse files Browse the repository at this point in the history
  • Loading branch information
okushchenko committed Oct 9, 2017
2 parents 3c2a38a + f288e72 commit d3e0869
Show file tree
Hide file tree
Showing 69 changed files with 10,806 additions and 464 deletions.
414 changes: 0 additions & 414 deletions Godeps/Godeps.json

This file was deleted.

5 changes: 0 additions & 5 deletions Godeps/Readme

This file was deleted.

10 changes: 8 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
build:
@echo "Building confd..."
@mkdir -p bin
@go build -o bin/confd .
@go build -ldflags "-X main.GitSHA=`git rev-parse --short HEAD`" -o bin/confd .

install:
@echo "Installing confd..."
Expand Down
3 changes: 2 additions & 1 deletion confd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/signal"
"runtime"
"syscall"

"github.com/kelseyhightower/confd/backends"
Expand All @@ -15,7 +16,7 @@ import (
func main() {
flag.Parse()
if printVersion {
fmt.Printf("confd %s\n", Version)
fmt.Printf("confd %s (Git SHA: %s, Go Version: %s)\n", Version, GitSHA, runtime.Version())
os.Exit(0)
}
if err := initConfig(); err != nil {
Expand Down
66 changes: 42 additions & 24 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
onetime bool
prefix string
printVersion bool
secretKeyring string
scheme string
srvDomain string
srvRecord string
Expand All @@ -54,30 +55,31 @@ var (

// A Config structure is used to configure confd.
type Config struct {
AuthToken string `toml:"auth_token"`
AuthType string `toml:"auth_type"`
Backend string `toml:"backend"`
BasicAuth bool `toml:"basic_auth"`
BackendNodes []string `toml:"nodes"`
ClientCaKeys string `toml:"client_cakeys"`
ClientCert string `toml:"client_cert"`
ClientKey string `toml:"client_key"`
ConfDir string `toml:"confdir"`
Interval int `toml:"interval"`
Noop bool `toml:"noop"`
Password string `toml:"password"`
Prefix string `toml:"prefix"`
SRVDomain string `toml:"srv_domain"`
SRVRecord string `toml:"srv_record"`
Scheme string `toml:"scheme"`
SyncOnly bool `toml:"sync-only"`
Table string `toml:"table"`
Username string `toml:"username"`
LogLevel string `toml:"log-level"`
Watch bool `toml:"watch"`
AppID string `toml:"app_id"`
UserID string `toml:"user_id"`
YAMLFile string `toml:"file"`
AuthToken string `toml:"auth_token"`
AuthType string `toml:"auth_type"`
Backend string `toml:"backend"`
BasicAuth bool `toml:"basic_auth"`
BackendNodes []string `toml:"nodes"`
ClientCaKeys string `toml:"client_cakeys"`
ClientCert string `toml:"client_cert"`
ClientKey string `toml:"client_key"`
ConfDir string `toml:"confdir"`
Interval int `toml:"interval"`
SecretKeyring string `toml:"secret_keyring"`
Noop bool `toml:"noop"`
Password string `toml:"password"`
Prefix string `toml:"prefix"`
SRVDomain string `toml:"srv_domain"`
SRVRecord string `toml:"srv_record"`
Scheme string `toml:"scheme"`
SyncOnly bool `toml:"sync-only"`
Table string `toml:"table"`
Username string `toml:"username"`
LogLevel string `toml:"log-level"`
Watch bool `toml:"watch"`
AppID string `toml:"app_id"`
UserID string `toml:"user_id"`
YAMLFile string `toml:"file"`
}

func init() {
Expand All @@ -99,6 +101,7 @@ func init() {
flag.StringVar(&prefix, "prefix", "", "key path prefix")
flag.BoolVar(&printVersion, "version", false, "print version and exit")
flag.StringVar(&scheme, "scheme", "http", "the backend URI scheme for nodes retrieved from DNS SRV records (http or https)")
flag.StringVar(&secretKeyring, "secret-keyring", "", "path to armored PGP secret keyring (for use with crypt functions)")
flag.StringVar(&srvDomain, "srv-domain", "", "the name of the resource record")
flag.StringVar(&srvRecord, "srv-record", "", "the SRV record to search for backends nodes. Example: _etcd-client._tcp.example.com")
flag.BoolVar(&syncOnly, "sync-only", false, "sync without check_cmd and reload_cmd")
Expand Down Expand Up @@ -150,6 +153,18 @@ func initConfig() error {

// Update config from commandline flags.
processFlags()
var pgpPrivateKey []byte
if config.SecretKeyring != "" {
kr, err := os.Open(config.SecretKeyring)
if err != nil {
log.Fatal(err.Error())
}
defer kr.Close()
pgpPrivateKey, err = ioutil.ReadAll(kr)
if err != nil {
log.Fatal(err.Error())
}
}

if config.LogLevel != "" {
log.SetLevel(config.LogLevel)
Expand Down Expand Up @@ -235,6 +250,7 @@ func initConfig() error {
Prefix: config.Prefix,
SyncOnly: config.SyncOnly,
TemplateDir: filepath.Join(config.ConfDir, "templates"),
PGPPrivateKey: pgpPrivateKey,
}
return nil
}
Expand Down Expand Up @@ -308,6 +324,8 @@ func setConfigFromFlag(f *flag.Flag) {
config.Prefix = prefix
case "scheme":
config.Scheme = scheme
case "secret-keyring":
config.SecretKeyring = secretKeyring
case "srv-domain":
config.SRVDomain = srvDomain
case "srv-record":
Expand Down
25 changes: 13 additions & 12 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ import (
func TestInitConfigDefaultConfig(t *testing.T) {
log.SetLevel("warn")
want := Config{
Backend: "etcd",
BackendNodes: []string{"http://127.0.0.1:4001"},
ClientCaKeys: "",
ClientCert: "",
ClientKey: "",
ConfDir: "/etc/confd",
Interval: 600,
Noop: false,
Prefix: "",
SRVDomain: "",
Scheme: "http",
Table: "",
Backend: "etcd",
BackendNodes: []string{"http://127.0.0.1:4001"},
ClientCaKeys: "",
ClientCert: "",
ClientKey: "",
ConfDir: "/etc/confd",
Interval: 600,
Noop: false,
Prefix: "",
SRVDomain: "",
Scheme: "http",
SecretKeyring: "",
Table: "",
}
if err := initConfig(); err != nil {
t.Errorf(err.Error())
Expand Down
9 changes: 6 additions & 3 deletions docs/command-line-flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,28 @@ Usage of confd:
confd conf directory (default "/etc/confd")
-config-file string
the confd config file
-file string
the YAML/JSON file to watch for changes
-interval int
backend polling interval (default 600)
-keep-stage-file
keep staged files
-log-level string
level which confd should log messages
-node value
list of backend nodes (default [])
list of backend nodes
-noop
only show pending changes
-onetime
run once and exit
-password string
the password to authenticate with (only used with vault and etcd backends)
-prefix string
key path prefix (default "/")
key path prefix
-scheme string
the backend URI scheme for nodes retrieved from DNS SRV records (http or https) (default "http")
-secret-keyring string
path to armored PGP secret keyring (for use with crypt functions)
-srv-domain string
the name of the resource record
-srv-record string
Expand All @@ -62,7 +66,6 @@ Usage of confd:
print version and exit
-watch
enable watch support
```

> The -scheme flag is only used to set the URL scheme for nodes retrieved from DNS SRV records.
Loading

0 comments on commit d3e0869

Please sign in to comment.