From 549de4f6e57cb4d548a14d5a056d30f25bb0b016 Mon Sep 17 00:00:00 2001 From: Rohith Date: Thu, 15 Oct 2015 17:28:12 +0100 Subject: [PATCH] - adding some extra debugging - performing a gofmt on the code, should probably place this into the tests --- config.go | 9 ++++----- main.go | 16 +++++++--------- utils.go | 5 ++++- vault_resource.go | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/config.go b/config.go index 3084018..716bf62 100644 --- a/config.go +++ b/config.go @@ -71,10 +71,9 @@ func parseOptions() error { } // validateOptions parses and validates the command line options -func validateOptions(cfg *config) error { +func validateOptions(cfg *config) (err error) { // step: validate the vault url - _, err := url.Parse(cfg.vaultURL) - if err != nil { + if _, err = url.Parse(cfg.vaultURL); err != nil { return fmt.Errorf("invalid vault url: '%s' specified", cfg.vaultURL) } @@ -83,8 +82,8 @@ func validateOptions(cfg *config) error { if exists, _ := fileExists(cfg.vaultAuthFile); !exists { return fmt.Errorf("the token file: %s does not exists, please check", cfg.vaultAuthFile) } - - if options.vaultAuthOptions, err = readConfigFile(options.vaultAuthFile); err != nil { + options.vaultAuthOptions, err = readConfigFile(options.vaultAuthFile) + if err != nil { return fmt.Errorf("unable to read in authentication options from: %s, error: %s", cfg.vaultAuthFile, err) } } diff --git a/main.go b/main.go index 3c0b560..04d1630 100644 --- a/main.go +++ b/main.go @@ -30,29 +30,26 @@ const ( ) func main() { - var err error - var vault *VaultService - // step: parse and validate the command line / environment options - if err = parseOptions(); err != nil { + if err := parseOptions(); err != nil { showUsage("invalid options, %s", err) } glog.Infof("starting the %s, version: %s", Prog, Version) // step: create a client to vault - if vault, err = NewVaultService(options.vaultURL); err != nil { + vault, err := NewVaultService(options.vaultURL) + if err != nil { showUsage("unable to create the vault client: %s", err) } + // step: create a channel to receive events upon and add our resources for renewal + updates := make(chan VaultEvent, 10) + vault.AddListener(updates) // step: setup the termination signals signalChannel := make(chan os.Signal) signal.Notify(signalChannel, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) - // step: create a channel to receive events upon and add our resources for renewal - updates := make(chan VaultEvent, 10) - vault.AddListener(updates) - // step: add each of the resources to the service processor for _, rn := range options.resources.items { if err := rn.IsValid(); err != nil { @@ -65,6 +62,7 @@ func main() { for { select { case evt := <-updates: + glog.V(10).Infof("recieved an update from the resource: %s", evt.Resource) go writeResource(evt.Resource, evt.Secret) case <-signalChannel: diff --git a/utils.go b/utils.go index f0625a7..9c594be 100644 --- a/utils.go +++ b/utils.go @@ -126,7 +126,7 @@ func readYAMLFile(filename string) (map[string]string, error) { // min : the smallest number we can accept // max : the largest number we can accept func getDurationWithin(min, max int) time.Duration { - return time.Duration(rand.Intn(max-min) + min) * time.Second + return time.Duration(rand.Intn(max-min)+min) * time.Second } // getEnv checks to see if an environment variable exists otherwise uses the default @@ -166,6 +166,8 @@ func writeResource(rn *VaultResource, data map[string]interface{}) error { resourcePath = fmt.Sprintf("%s/%s", options.outputDir, resourcePath) } + glog.V(10).Infof("writing the resource: %s, format: %s", resourcePath, rn.format) + if rn.format == "yaml" { // marshall the content to yaml if content, err = yaml.Marshal(data); err != nil { @@ -195,6 +197,7 @@ func writeResource(rn *VaultResource, data map[string]interface{}) error { filename := fmt.Sprintf("%s.%s", resourcePath, suffix) content, found := data[key] if !found { + glog.Errorf("didn't find the certification option: %s in the resource: %s", key, rn.name) continue } diff --git a/vault_resource.go b/vault_resource.go index 2f0abec..9628a4b 100644 --- a/vault_resource.go +++ b/vault_resource.go @@ -37,7 +37,7 @@ const ( // optionRevoke revokes an old lease when retrieving a new one optionRevoke = "revoke" // optionRevokeDelay - optionsRevokeDelay = "delay" + optionsRevokeDelay = "delay" // optionUpdate overrides the lease of the resource optionUpdate = "update" )