- fixed up the formatting
- fixing up the imports
This commit is contained in:
parent
b6e5503615
commit
20baf582fe
|
@ -21,8 +21,9 @@ import (
|
|||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"github.com/golang/glog"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
// config ... the command line configuration
|
||||
|
|
8
utils.go
8
utils.go
|
@ -17,11 +17,11 @@ limitations under the License.
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"math/rand"
|
||||
"time"
|
||||
"flag"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -48,7 +48,7 @@ func randomWait(min, max int ) <-chan time.Time {
|
|||
// getKeys ... retrieve a list of keys from the map
|
||||
func getKeys(data map[string]interface{}) []string {
|
||||
var list []string
|
||||
for key, _ := range data {
|
||||
for key := range data {
|
||||
list = append(list, key)
|
||||
}
|
||||
return list
|
||||
|
|
17
vault.go
17
vault.go
|
@ -17,11 +17,11 @@ limitations under the License.
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/vault/api"
|
||||
"github.com/golang/glog"
|
||||
"fmt"
|
||||
"github.com/hashicorp/vault/api"
|
||||
)
|
||||
|
||||
// a channel to send resource
|
||||
|
@ -122,7 +122,8 @@ func newVaultService(url, token string) (*vaultService, error) {
|
|||
func (r vaultService) vaultServiceProcessor() {
|
||||
go func() {
|
||||
// a list of resource being watched
|
||||
items := make([]*watchedResource, 0)
|
||||
var items []*watchedResource
|
||||
|
||||
// the channel to receive renewal notifications on
|
||||
renewChannel := make(chan *watchedResource, 10)
|
||||
retrieveChannel := make(chan *watchedResource, 10)
|
||||
|
@ -144,10 +145,10 @@ func (r vaultService) vaultServiceProcessor() {
|
|||
|
||||
case x := <-retrieveChannel:
|
||||
// step: save the current lease if we have one
|
||||
leaseId := ""
|
||||
leaseID := ""
|
||||
if x.secret != nil && x.secret.LeaseID != "" {
|
||||
leaseId = x.secret.LeaseID
|
||||
glog.V(10).Infof("resource: %s has a previous lease: %s", x.resource, leaseId)
|
||||
leaseID = x.secret.LeaseID
|
||||
glog.V(10).Infof("resource: %s has a previous lease: %s", x.resource, leaseID)
|
||||
}
|
||||
|
||||
// step: retrieve the resource from vault
|
||||
|
@ -163,8 +164,8 @@ func (r vaultService) vaultServiceProcessor() {
|
|||
glog.Infof("succesfully retrieved resournce: %s, leaseID: %s", x.resource, x.secret.LeaseID)
|
||||
|
||||
// step: if we had a previous lease and the option is to revoke, lets throw into the revoke channel
|
||||
if leaseId != "" && x.resource.revoked {
|
||||
revokeChannel <- leaseId
|
||||
if leaseID != "" && x.resource.revoked {
|
||||
revokeChannel <- leaseID
|
||||
}
|
||||
|
||||
// step: setup a timer for renewal
|
||||
|
|
|
@ -19,28 +19,25 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"time"
|
||||
"strconv"
|
||||
"github.com/golang/glog"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
// OptionFilename ... option to set the filename of the resource
|
||||
OptionFilename = "fn"
|
||||
// OptionsFormat ... option to set the output format (yaml, xml, json)
|
||||
// OptionFormat ... option to set the output format (yaml, xml, json)
|
||||
OptionFormat = "fmt"
|
||||
// OptionsCommonName ... use by the PKI resource
|
||||
// OptionCommonName ... use by the PKI resource
|
||||
OptionCommonName = "cn"
|
||||
// OptionTemplatePath ... the full path to a template
|
||||
OptionsTemplatePath = "tpl"
|
||||
// OptionRenew ... a duration to renew the resource
|
||||
OptionTemplatePath = "tpl"
|
||||
// OptionRenewal ... a duration to renew the resource
|
||||
OptionRenewal = "rn"
|
||||
// OptionRevoke ... revoke an old lease when retrieving a new one
|
||||
OptionRevoke = "rv"
|
||||
// OptionUpdate ... override the lease of the resource
|
||||
OptionUpdate = "up"
|
||||
|
||||
DefaultRenewable = "false"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -53,6 +50,8 @@ var (
|
|||
"secret": true,
|
||||
"mysql": true,
|
||||
"tpl": true,
|
||||
"postgres": true,
|
||||
"cassandra": true,
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -111,7 +110,7 @@ func (r *vaultResource) isValidResource() error {
|
|||
return fmt.Errorf("pki resource requires a common name specified")
|
||||
}
|
||||
case "tpl":
|
||||
if _, found := r.options[OptionsTemplatePath]; !found {
|
||||
if _, found := r.options[OptionTemplatePath]; !found {
|
||||
return fmt.Errorf("template resource requires a template path option")
|
||||
}
|
||||
}
|
||||
|
@ -128,34 +127,30 @@ func (r *vaultResource) isValidOptions() error {
|
|||
if matched := resourceFormatRegex.MatchString(r.options[OptionFormat]); !matched {
|
||||
return fmt.Errorf("unsupported output format: %s", r.options[OptionFormat])
|
||||
}
|
||||
glog.V(20).Infof("setting the format: %s on resource: %s", val, r)
|
||||
r.format = val
|
||||
case OptionUpdate:
|
||||
duration, err := time.ParseDuration(val)
|
||||
if err != nil {
|
||||
return fmt.Errorf("the update option: %s is not value, should be a duration format", val)
|
||||
}
|
||||
glog.V(20).Infof("setting the update time: %s on resource: %s", duration, r)
|
||||
r.update = duration
|
||||
case OptionRevoke:
|
||||
choice, err := strconv.ParseBool(val)
|
||||
if err != nil {
|
||||
return fmt.Errorf("the revoke option: %s is invalid, should be a boolean", val)
|
||||
}
|
||||
glog.V(20).Infof("setting the revoked: %t on resource: %s", choice, r)
|
||||
r.revoked = choice
|
||||
case OptionRenewal:
|
||||
choice, err := strconv.ParseBool(val)
|
||||
if err != nil {
|
||||
return fmt.Errorf("the renewal option: %s is invalid, should be a boolean", val)
|
||||
}
|
||||
glog.V(20).Infof("setting the renewable: %t on resource: %s", choice, r)
|
||||
r.renewable = choice
|
||||
case OptionFilename:
|
||||
// @TODO need to check it's valid filename / path
|
||||
case OptionCommonName:
|
||||
// @TODO need to check it's a valid hostname
|
||||
case OptionsTemplatePath:
|
||||
case OptionTemplatePath:
|
||||
if exists, _ := fileExists(val); !exists {
|
||||
return fmt.Errorf("the template file: %s does not exist", val)
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ func TestResourceFilename(t *testing.T) {
|
|||
assert.Equal(t, "credentials", rn.filename())
|
||||
}
|
||||
|
||||
|
||||
func TestIsValid(t *testing.T) {
|
||||
resource := defaultVaultResource()
|
||||
resource.name = "/test/name"
|
||||
|
|
|
@ -33,10 +33,6 @@ type vaultResources struct {
|
|||
items []*vaultResource
|
||||
}
|
||||
|
||||
func (r vaultResources) size() int {
|
||||
return len(r.items)
|
||||
}
|
||||
|
||||
// Set ... implementation for the parser
|
||||
func (r *vaultResources) Set(value string) error {
|
||||
rn := defaultVaultResource()
|
||||
|
|
|
@ -22,7 +22,6 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
func TestSetResources(t *testing.T) {
|
||||
var items vaultResources
|
||||
|
||||
|
@ -41,13 +40,6 @@ func TestSetResources(t *testing.T) {
|
|||
assert.NotNil(t, items.Set("fn=filename.test,fmt=yaml"))
|
||||
}
|
||||
|
||||
func TestResourceSize(t *testing.T) {
|
||||
var items vaultResources
|
||||
items.Set("secret:test:fn=filename.test,fmt=yaml")
|
||||
items.Set("secret:test:fn=fileame.test")
|
||||
assert.Equal(t, 2, items.size())
|
||||
}
|
||||
|
||||
func TestResources(t *testing.T) {
|
||||
var items vaultResources
|
||||
items.Set("secret:test:fn=filename.test,fmt=yaml")
|
||||
|
|
|
@ -15,4 +15,3 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
package main
|
||||
|
||||
|
|
Reference in a new issue