Skip to content

Commit

Permalink
Updated dependencies + refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
gherynos committed Dec 18, 2023
1 parent f343fb7 commit d34fff4
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 80 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exclude: (CMakeFiles|cmake_modules|docs|target)\/
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-json
- id: check-merge-conflict
Expand All @@ -17,7 +17,7 @@ repos:
- --autofix
- id: detect-private-key
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.4.2
rev: v1.5.4
hooks:
- id: forbid-tabs
exclude_types:
Expand All @@ -31,11 +31,11 @@ repos:
- go
exclude: binary|\.bin|go.mod$
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.33.0
rev: v0.37.0
hooks:
- id: markdownlint
- repo: https://github.com/adrienverge/yamllint
rev: v1.29.0
rev: v1.33.0
hooks:
- id: yamllint
- repo: https://github.com/dnephin/pre-commit-golang
Expand Down
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ require (
require (
github.com/cenkalti/backoff/v3 v3.2.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.4 // indirect
github.com/hashicorp/go-retryablehttp v0.7.5 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.8 // indirect
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect
github.com/hashicorp/go-sockaddr v1.0.5 // indirect
github.com/hashicorp/go-sockaddr v1.0.6 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
32 changes: 16 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
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/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/go-jose/go-jose/v3 v3.0.0 h1:s6rrhirfEP/CGIoc6p+PZAeogN2SxKav6Wp7+dyMWVo=
github.com/go-jose/go-jose/v3 v3.0.0/go.mod h1:RNkWWRld676jZEYoV3+XK8L2ZnNSvIsxFMht0mSX+u8=
github.com/go-jose/go-jose/v3 v3.0.1 h1:pWmKFVtt+Jl0vBZTIpz/eAKwsm6LkIxDVVbFHKkchhA=
github.com/go-jose/go-jose/v3 v3.0.1/go.mod h1:RNkWWRld676jZEYoV3+XK8L2ZnNSvIsxFMht0mSX+u8=
github.com/go-test/deep v1.0.2 h1:onZX1rnHT3Wv6cqNgYyFOOlgVKJrksuCMCRvJStbMYw=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
Expand All @@ -18,16 +18,16 @@ github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrj
github.com/hashicorp/go-hclog v0.16.2 h1:K4ev2ib4LdQETX5cSZBG0DVLk1jwGqSPXBjdah3veNs=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-retryablehttp v0.7.4 h1:ZQgVdpTdAL7WpMIwLzCfbalOcSUdkDZnpUv3/+BxzFA=
github.com/hashicorp/go-retryablehttp v0.7.4/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
github.com/hashicorp/go-retryablehttp v0.7.5 h1:bJj+Pj19UZMIweq/iie+1u5YCdGrnxCT9yvm0e+Nd5M=
github.com/hashicorp/go-retryablehttp v0.7.5/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
github.com/hashicorp/go-rootcerts v1.0.2 h1:jzhAVGtqPKbwpyCPELlgNWhE1znq+qwJtW5Oi2viEzc=
github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8=
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.8 h1:iBt4Ew4XEGLfh6/bPk4rSYmuZJGizr6/x/AEizP0CQc=
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.8/go.mod h1:aiJI+PIApBRQG7FZTEBx5GiiX+HbOHilUdNxUZi4eV0=
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 h1:kes8mmyCpxJsI7FTwtzRqEy9CdjCtrXrXGuOpxEA7Ts=
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2/go.mod h1:Gou2R9+il93BqX25LAKCLuM+y9U2T4hlwvT1yprcna4=
github.com/hashicorp/go-sockaddr v1.0.5 h1:dvk7TIXCZpmfOlM+9mlcrWmWjw/wlKT+VDq2wMvfPJU=
github.com/hashicorp/go-sockaddr v1.0.5/go.mod h1:uoUUmtwU7n9Dv3O4SNLeFvg0SxQ3lyjsj6+CCykpaxI=
github.com/hashicorp/go-sockaddr v1.0.6 h1:RSG8rKU28VTUTvEKghe5gIhIQpv8evvNpnDEyqO4u9I=
github.com/hashicorp/go-sockaddr v1.0.6/go.mod h1:uoUUmtwU7n9Dv3O4SNLeFvg0SxQ3lyjsj6+CCykpaxI=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/vault/api v1.10.0 h1:/US7sIjWN6Imp4o/Rj1Ce2Nr5bki/AXi9vAW3p2tOJQ=
Expand All @@ -52,21 +52,21 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
91 changes: 42 additions & 49 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package server
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"

Expand All @@ -15,7 +15,7 @@ import (
)

// Version defines the version of the server
const Version = "0.4.2"
const Version = "0.4.3"

func checkLockID(store s.Store, state, id string) (proceed bool, data string, err error) {

Expand Down Expand Up @@ -44,17 +44,16 @@ func stateHandlerGet(logger *log.Entry, store s.Store, state string, w http.Resp
data, err := store.GetBin(state)
if err != nil {

switch err.(type) {
var itemNotFoundError *s.ItemNotFoundError
var responseError *api.ResponseError
switch {

case *s.ItemNotFoundError:
case errors.As(err, &itemNotFoundError):
return http.StatusNotFound, http.StatusText(http.StatusNotFound)

case *api.ResponseError:
case errors.As(err, &responseError):
{
re := err.(*api.ResponseError)
return re.StatusCode, re.Error()
return responseError.StatusCode, responseError.Error()
}

default:
{
logger.WithError(err).Error("unable to get state")
Expand All @@ -79,17 +78,16 @@ func stateHandlerPost(logger *log.Entry, store s.Store, state string, r *http.Re

if proceed, data, err := checkLockID(store, state, r.URL.Query().Get("ID")); err != nil {

switch err.(type) {
var itemNotFoundError *s.ItemNotFoundError
var responseError *api.ResponseError
switch {

case *s.ItemNotFoundError:
case errors.As(err, &itemNotFoundError):
return http.StatusUnprocessableEntity, http.StatusText(http.StatusUnprocessableEntity)

case *api.ResponseError:
case errors.As(err, &responseError):
{
re := err.(*api.ResponseError)
return re.StatusCode, re.Error()
return responseError.StatusCode, responseError.Error()
}

default:
{
logger.WithError(err).Error("unable to check lock")
Expand All @@ -105,21 +103,20 @@ func stateHandlerPost(logger *log.Entry, store s.Store, state string, r *http.Re

var reqBody []byte
var err error
if reqBody, err = ioutil.ReadAll(r.Body); err != nil {
if reqBody, err = io.ReadAll(r.Body); err != nil {

return http.StatusBadRequest, http.StatusText(http.StatusBadRequest)
}

if err := store.SetBin(state, reqBody); err != nil {

switch err.(type) {
var responseError *api.ResponseError
switch {

case *api.ResponseError:
case errors.As(err, &responseError):
{
re := err.(*api.ResponseError)
return re.StatusCode, re.Error()
return responseError.StatusCode, responseError.Error()
}

default:
{
logger.WithError(err).Error("unable to store state")
Expand All @@ -139,13 +136,15 @@ func stateHandlerLock(logger *log.Entry, store s.Store, state string, r *http.Re
data, err := store.GetBin(name)
if err != nil {

switch err.(type) {
var itemNotFoundError *s.ItemNotFoundError
var responseError *api.ResponseError
switch {

case *s.ItemNotFoundError:
case errors.As(err, &itemNotFoundError):
{
var reqBody []byte
var err error
if reqBody, err = ioutil.ReadAll(r.Body); err != nil {
if reqBody, err = io.ReadAll(r.Body); err != nil {

return http.StatusBadRequest, http.StatusText(http.StatusBadRequest)
}
Expand All @@ -158,13 +157,10 @@ func stateHandlerLock(logger *log.Entry, store s.Store, state string, r *http.Re

return 200, ""
}

case *api.ResponseError:
case errors.As(err, &responseError):
{
re := err.(*api.ResponseError)
return re.StatusCode, re.Error()
return responseError.StatusCode, responseError.Error()
}

default:
{
logger.WithError(err).Error("unable to retrieve lock")
Expand All @@ -183,7 +179,7 @@ func stateHandlerUnlock(logger *log.Entry, store s.Store, state string, pool s.P

var reqBody []byte
var err error
if reqBody, err = ioutil.ReadAll(r.Body); err != nil {
if reqBody, err = io.ReadAll(r.Body); err != nil {

return http.StatusBadRequest, http.StatusText(http.StatusBadRequest)
}
Expand All @@ -196,17 +192,16 @@ func stateHandlerUnlock(logger *log.Entry, store s.Store, state string, pool s.P

if proceed, data, err := checkLockID(store, state, body["ID"].(string)); err != nil {

switch err.(type) {
var itemNotFoundError *s.ItemNotFoundError
var responseError *api.ResponseError
switch {

case *s.ItemNotFoundError:
case errors.As(err, &itemNotFoundError):
return http.StatusUnprocessableEntity, http.StatusText(http.StatusUnprocessableEntity)

case *api.ResponseError:
case errors.As(err, &responseError):
{
re := err.(*api.ResponseError)
return re.StatusCode, re.Error()
return responseError.StatusCode, responseError.Error()
}

default:
{
logger.WithError(err).Error("unable to check lock")
Expand All @@ -222,14 +217,13 @@ func stateHandlerUnlock(logger *log.Entry, store s.Store, state string, pool s.P

if err := store.Delete(fmt.Sprintf("%s-lock", state)); err != nil {

switch err.(type) {
var responseError *api.ResponseError
switch {

case *api.ResponseError:
case errors.As(err, &responseError):
{
re := err.(*api.ResponseError)
return re.StatusCode, re.Error()
return responseError.StatusCode, responseError.Error()
}

default:
{
logger.WithError(err).Error("unable to remove lock")
Expand Down Expand Up @@ -261,15 +255,14 @@ func stateHandler(pool s.Pool, w http.ResponseWriter, r *http.Request) (int, str
store, err = pool.Get(userPassEnc)
if err != nil {

switch err.(type) {
var responseError *api.ResponseError
switch {

case *api.ResponseError:
case errors.As(err, &responseError):
{
re := err.(*api.ResponseError)
logger.Debugf("error connecting to Vault: %d - %s", re.StatusCode, re.Error())
return re.StatusCode, re.Error()
logger.Debugf("error connecting to Vault: %d - %s", responseError.StatusCode, responseError.Error())
return responseError.StatusCode, responseError.Error()
}

default:
{
logger.WithError(err).Error("error connecting to Vault")
Expand Down
5 changes: 2 additions & 3 deletions vault/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/base64"
"errors"
"io"
"io/ioutil"
"strings"
)

Expand Down Expand Up @@ -48,8 +47,8 @@ func Decode(data string) (bt []byte, err error) {
}

defer decoder.Close()
bt, err = ioutil.ReadAll(decoder)
if err != nil && err != io.ErrUnexpectedEOF {
bt, err = io.ReadAll(decoder)
if err != nil && !errors.Is(err, io.ErrUnexpectedEOF) {

return
}
Expand Down

0 comments on commit d34fff4

Please sign in to comment.