- adding some extra debugging

- performing a gofmt on the code, should probably place this into the tests
This commit is contained in:
Rohith 2015-10-15 17:28:12 +01:00
parent 86d4cd64f2
commit 549de4f6e5
4 changed files with 16 additions and 16 deletions

View file

@ -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)
}
}

16
main.go
View file

@ -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:

View file

@ -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
}

View file

@ -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"
)