- adding some extra debugging
- performing a gofmt on the code, should probably place this into the tests
This commit is contained in:
parent
86d4cd64f2
commit
549de4f6e5
|
@ -71,10 +71,9 @@ func parseOptions() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// validateOptions parses and validates the command line options
|
// validateOptions parses and validates the command line options
|
||||||
func validateOptions(cfg *config) error {
|
func validateOptions(cfg *config) (err error) {
|
||||||
// step: validate the vault url
|
// step: validate the vault url
|
||||||
_, err := url.Parse(cfg.vaultURL)
|
if _, err = url.Parse(cfg.vaultURL); err != nil {
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("invalid vault url: '%s' specified", cfg.vaultURL)
|
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 {
|
if exists, _ := fileExists(cfg.vaultAuthFile); !exists {
|
||||||
return fmt.Errorf("the token file: %s does not exists, please check", cfg.vaultAuthFile)
|
return fmt.Errorf("the token file: %s does not exists, please check", cfg.vaultAuthFile)
|
||||||
}
|
}
|
||||||
|
options.vaultAuthOptions, err = readConfigFile(options.vaultAuthFile)
|
||||||
if options.vaultAuthOptions, err = readConfigFile(options.vaultAuthFile); err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to read in authentication options from: %s, error: %s", cfg.vaultAuthFile, err)
|
return fmt.Errorf("unable to read in authentication options from: %s, error: %s", cfg.vaultAuthFile, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
main.go
16
main.go
|
@ -30,29 +30,26 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var err error
|
|
||||||
var vault *VaultService
|
|
||||||
|
|
||||||
// step: parse and validate the command line / environment options
|
// step: parse and validate the command line / environment options
|
||||||
if err = parseOptions(); err != nil {
|
if err := parseOptions(); err != nil {
|
||||||
showUsage("invalid options, %s", err)
|
showUsage("invalid options, %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.Infof("starting the %s, version: %s", Prog, Version)
|
glog.Infof("starting the %s, version: %s", Prog, Version)
|
||||||
|
|
||||||
// step: create a client to vault
|
// 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)
|
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
|
// step: setup the termination signals
|
||||||
signalChannel := make(chan os.Signal)
|
signalChannel := make(chan os.Signal)
|
||||||
signal.Notify(signalChannel, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
|
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
|
// step: add each of the resources to the service processor
|
||||||
for _, rn := range options.resources.items {
|
for _, rn := range options.resources.items {
|
||||||
if err := rn.IsValid(); err != nil {
|
if err := rn.IsValid(); err != nil {
|
||||||
|
@ -65,6 +62,7 @@ func main() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case evt := <-updates:
|
case evt := <-updates:
|
||||||
|
glog.V(10).Infof("recieved an update from the resource: %s", evt.Resource)
|
||||||
go writeResource(evt.Resource, evt.Secret)
|
go writeResource(evt.Resource, evt.Secret)
|
||||||
|
|
||||||
case <-signalChannel:
|
case <-signalChannel:
|
||||||
|
|
5
utils.go
5
utils.go
|
@ -126,7 +126,7 @@ func readYAMLFile(filename string) (map[string]string, error) {
|
||||||
// min : the smallest number we can accept
|
// min : the smallest number we can accept
|
||||||
// max : the largest number we can accept
|
// max : the largest number we can accept
|
||||||
func getDurationWithin(min, max int) time.Duration {
|
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
|
// 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)
|
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" {
|
if rn.format == "yaml" {
|
||||||
// marshall the content to yaml
|
// marshall the content to yaml
|
||||||
if content, err = yaml.Marshal(data); err != nil {
|
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)
|
filename := fmt.Sprintf("%s.%s", resourcePath, suffix)
|
||||||
content, found := data[key]
|
content, found := data[key]
|
||||||
if !found {
|
if !found {
|
||||||
|
glog.Errorf("didn't find the certification option: %s in the resource: %s", key, rn.name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ const (
|
||||||
// optionRevoke revokes an old lease when retrieving a new one
|
// optionRevoke revokes an old lease when retrieving a new one
|
||||||
optionRevoke = "revoke"
|
optionRevoke = "revoke"
|
||||||
// optionRevokeDelay
|
// optionRevokeDelay
|
||||||
optionsRevokeDelay = "delay"
|
optionsRevokeDelay = "delay"
|
||||||
// optionUpdate overrides the lease of the resource
|
// optionUpdate overrides the lease of the resource
|
||||||
optionUpdate = "update"
|
optionUpdate = "update"
|
||||||
)
|
)
|
||||||
|
|
Reference in a new issue