From 6117bcd7bf756a5f166674e6495ad1228204582d Mon Sep 17 00:00:00 2001 From: Simon Marsh Date: Tue, 26 Jul 2022 13:26:33 +0100 Subject: [PATCH] more fixes --- go.mod | 9 ++++++--- go.sum | 4 ++++ mini-vault/mini-vault.go | 2 +- mini-vault/tls.go | 2 +- mini-vault/token.go | 2 +- test/test.go | 43 ---------------------------------------- tls.go | 12 +++++++++-- 7 files changed, 23 insertions(+), 51 deletions(-) delete mode 100644 test/test.go diff --git a/go.mod b/go.mod index bc3f8c9..b17b54c 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,14 @@ -module libvault +module git.burble.dn42/burble.dn42/libvault go 1.18 +require ( + github.com/sirupsen/logrus v1.9.0 + github.com/spf13/cobra v1.5.0 +) + require ( github.com/inconshreveable/mousetrap v1.0.0 // indirect - github.com/sirupsen/logrus v1.9.0 // indirect - github.com/spf13/cobra v1.5.0 // indirect github.com/spf13/pflag v1.0.5 // indirect golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect ) diff --git a/go.sum b/go.sum index f621d46..ea3a43c 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,10 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= @@ -12,9 +14,11 @@ github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/mini-vault/mini-vault.go b/mini-vault/mini-vault.go index a6adc08..a92808f 100644 --- a/mini-vault/mini-vault.go +++ b/mini-vault/mini-vault.go @@ -10,7 +10,7 @@ import ( "os" - vault "libvault" + vault "git.burble.dn42/burble.dn42/libvault" ) ////////////////////////////////////////////////////////////////////////// diff --git a/mini-vault/tls.go b/mini-vault/tls.go index c0f5f1b..a406e05 100644 --- a/mini-vault/tls.go +++ b/mini-vault/tls.go @@ -13,7 +13,7 @@ import ( "fmt" "os" - vault "libvault" + vault "git.burble.dn42/burble.dn42/libvault" ) ////////////////////////////////////////////////////////////////////////// diff --git a/mini-vault/token.go b/mini-vault/token.go index d6f1f06..aea49eb 100644 --- a/mini-vault/token.go +++ b/mini-vault/token.go @@ -12,7 +12,7 @@ import ( "os" "time" - vault "libvault" + vault "git.burble.dn42/burble.dn42/libvault" ) ////////////////////////////////////////////////////////////////////////// diff --git a/test/test.go b/test/test.go deleted file mode 100644 index cf91337..0000000 --- a/test/test.go +++ /dev/null @@ -1,43 +0,0 @@ -////////////////////////////////////////////////////////////////////////// - -package main - -////////////////////////////////////////////////////////////////////////// - -import ( - "crypto/tls" - "fmt" - log "github.com/sirupsen/logrus" - - vault "libvault" -) - -////////////////////////////////////////////////////////////////////////// -// everything starts here - -func main() { - log.SetLevel(log.DebugLevel) - - token, _ := vault.NewTokenFromFile("/home/simon/.vault-token") - - config := &tls.Config{} - tlsreq := &vault.TLSRequest{ - CommonName: "here.burble.dn42", - AltNames: "there.burble.dn42,everywhere.burble.dn42", - } - - { - ok, err := tlsreq.Renew(token, config) - fmt.Printf("ok: %v, err: %v\n", ok, err) - } - - // and again - { - ok, err := tlsreq.Renew(token, config) - fmt.Printf("ok: %v, err: %v\n", ok, err) - } - -} - -////////////////////////////////////////////////////////////////////////// -// end of code diff --git a/tls.go b/tls.go index 86bde53..c7c2698 100644 --- a/tls.go +++ b/tls.go @@ -168,8 +168,16 @@ func (req *TLSRequest) AutoRenew( for { for i := 0; i < 3; i++ { - // attempt to renew - updated, err := req.Renew(t, config) + var err error + var updated bool + + // attempt to renew token first + err = t.Renew(VAULT_TTL) + if err == nil { + updated, err = req.Renew(t, config) + } + + // was there an error in either renewal ? if err != nil { // if renew fails then sleep for a while and try again