Skip to content

Commit

Permalink
Improve docs, Implement error wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
pteich committed Oct 9, 2020
1 parent bdbf09e commit bb28076
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 140 deletions.
51 changes: 26 additions & 25 deletions crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,90 +5,91 @@ import (
"crypto/cipher"
"crypto/rand"
"encoding/json"
"fmt"
"io"

"github.com/pteich/errors"
)

func (s *Storage) encrypt(bytes []byte) ([]byte, error) {
func (cs *ConsulStorage) encrypt(bytes []byte) ([]byte, error) {
// No key? No encrypt
if len(s.AESKey) == 0 {
if len(cs.AESKey) == 0 {
return bytes, nil
}

c, err := aes.NewCipher(s.AESKey)
c, err := aes.NewCipher(cs.AESKey)
if err != nil {
return nil, fmt.Errorf("unable to create AES cipher: %w", err)
return nil, errors.Wrap(err, "unable to create AES cipher")
}

gcm, err := cipher.NewGCM(c)
if err != nil {
return nil, fmt.Errorf("unable to create GCM cipher: %w", err)
return nil, errors.Wrap(err, "unable to create GCM cipher")
}

nonce := make([]byte, gcm.NonceSize())
_, err = io.ReadFull(rand.Reader, nonce)
if err != nil {
return nil, fmt.Errorf("unable to generate nonce: %w", err)
return nil, errors.Wrap(err, "unable to generate nonce")
}

return gcm.Seal(nonce, nonce, bytes, nil), nil
}

func (s *Storage) EncryptStorageData(data *StorageData) ([]byte, error) {
func (cs *ConsulStorage) EncryptStorageData(data *StorageData) ([]byte, error) {
// JSON marshal, then encrypt if key is there
bytes, err := json.Marshal(data)
if err != nil {
return nil, fmt.Errorf("unable to marshal: %w", err)
return nil, errors.Wrap(err, "unable to marshal")
}

// Prefix with simple prefix and then encrypt
bytes = append([]byte(s.ValuePrefix), bytes...)
return s.encrypt(bytes)
bytes = append([]byte(cs.ValuePrefix), bytes...)
return cs.encrypt(bytes)
}

func (s *Storage) decrypt(bytes []byte) ([]byte, error) {
func (cs *ConsulStorage) decrypt(bytes []byte) ([]byte, error) {
// No key? No decrypt
if len(s.AESKey) == 0 {
if len(cs.AESKey) == 0 {
return bytes, nil
}
if len(bytes) < aes.BlockSize {
return nil, fmt.Errorf("invalid contents")
return nil, errors.New("invalid contents")
}

block, err := aes.NewCipher(s.AESKey)
block, err := aes.NewCipher(cs.AESKey)
if err != nil {
return nil, fmt.Errorf("unable to create AES cipher: %w", err)
return nil, errors.Wrap(err, "unable to create AES cipher")
}

gcm, err := cipher.NewGCM(block)
if err != nil {
return nil, fmt.Errorf("unable to create GCM cipher: %w", err)
return nil, errors.Wrap(err, "unable to create GCM cipher")
}

out, err := gcm.Open(nil, bytes[:gcm.NonceSize()], bytes[gcm.NonceSize():], nil)
if err != nil {
return nil, fmt.Errorf("decryption failure: %w", err)
return nil, errors.Wrap(err, "decryption failure")
}

return out, nil
}

func (s *Storage) DecryptStorageData(bytes []byte) (*StorageData, error) {
func (cs *ConsulStorage) DecryptStorageData(bytes []byte) (*StorageData, error) {
// We have to decrypt if there is an AES key and then JSON unmarshal
bytes, err := s.decrypt(bytes)
bytes, err := cs.decrypt(bytes)
if err != nil {
return nil, fmt.Errorf("unable to decrypt data: %w", err)
return nil, errors.Wrap(err, "unable to decrypt data")
}

// Simple sanity check of the beginning of the byte array just to check
if len(bytes) < len(s.ValuePrefix) || string(bytes[:len(s.ValuePrefix)]) != s.ValuePrefix {
return nil, fmt.Errorf("invalid data format")
if len(bytes) < len(cs.ValuePrefix) || string(bytes[:len(cs.ValuePrefix)]) != cs.ValuePrefix {
return nil, errors.New("invalid data format")
}

// Now just json unmarshal
data := &StorageData{}
if err := json.Unmarshal(bytes[len(s.ValuePrefix):], data); err != nil {
return nil, fmt.Errorf("unable to unmarshal result: %w", err)
if err := json.Unmarshal(bytes[len(cs.ValuePrefix):], data); err != nil {
return nil, errors.Wrap(err, "unable to unmarshal result")
}
return data, nil
}
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ require (
github.com/hashicorp/consul/api v1.7.0
github.com/hashicorp/go-hclog v0.14.1 // indirect
github.com/hashicorp/go-immutable-radix v1.3.0 // indirect
github.com/hashicorp/go.net v0.0.1 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/serf v0.9.5 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mitchellh/gox v0.4.0 // indirect
github.com/mitchellh/iochan v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.3.3 // indirect
github.com/pteich/errors v1.0.1
github.com/stretchr/testify v1.5.1
go.uber.org/zap v1.15.0
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
Expand Down
25 changes: 3 additions & 22 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hC
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da h1:8GUt8eRujhVEGZFFEjBj46YV4rDjvGrNxb0KMWYkL2I=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-metrics v0.3.3 h1:a9F4rlj7EWWrbj7BYw8J8+x+ZZkJeqzNyRk8hdPF+ro=
github.com/armon/go-metrics v0.3.3/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc=
github.com/armon/go-metrics v0.3.4 h1:Xqf+7f2Vhl9tsqDYmXhnXInUdcrtgpRNpIA15/uldSc=
github.com/armon/go-metrics v0.3.4/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
Expand Down Expand Up @@ -285,12 +283,9 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf
github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.12.1/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c=
github.com/hashicorp/consul/api v1.4.0 h1:jfESivXnO5uLdH650JU/6AnjRoHrLhULq0FnC3Kp9EY=
github.com/hashicorp/consul/api v1.4.0/go.mod h1:xc8u05kyMa3Wjr9eEAsIAo3dg8+LywT5E/Cl7cNS5nU=
github.com/hashicorp/consul/api v1.7.0 h1:tGs8Oep67r8CcA2Ycmb/8BLBcJ70St44mF2X10a/qPg=
github.com/hashicorp/consul/api v1.7.0/go.mod h1:1NSuaUUkFaJzMasbfq/11wKYWSR67Xn6r2DXKhuDNFg=
github.com/hashicorp/consul/sdk v0.4.0 h1:zBtCfKJZcJDBvSCkQJch4ulp59m1rATFLKwNo/LYY30=
github.com/hashicorp/consul/sdk v0.4.0/go.mod h1:fY08Y9z5SvJqevyZNy6WWPXiG3KwBPAvlcdx16zZ0fM=
github.com/hashicorp/consul/sdk v0.6.0 h1:FfhMEkwvQl57CildXJyGHnwGGM4HMODGyfjGwNM1Vdw=
github.com/hashicorp/consul/sdk v0.6.0/go.mod h1:fY08Y9z5SvJqevyZNy6WWPXiG3KwBPAvlcdx16zZ0fM=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand All @@ -303,8 +298,6 @@ github.com/hashicorp/go-hclog v0.14.1 h1:nQcJDQwIAGnmoUWp8ubocEX40cCml/17YkF6csQ
github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0=
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-immutable-radix v1.2.0 h1:l6UW37iCXwZkZoAbEYnptSHVE/cQ5bOTPYG5W3vf9+8=
github.com/hashicorp/go-immutable-radix v1.2.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-immutable-radix v1.3.0 h1:8exGP7ego3OmkfksihtSouGMZ+hQrhxx+FVELeXpVPE=
github.com/hashicorp/go-immutable-radix v1.3.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-msgpack v0.5.3 h1:zKjpN5BK/P5lMYrLmBHdBULWbJ0XpYR+7NGzqkZzoD4=
Expand All @@ -322,24 +315,16 @@ github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdv
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce/go.mod h1:oZtUIOe8dh44I2q6ScRibXws4Ajl+d+nod3AaR9vL5w=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
github.com/hashicorp/mdns v1.0.1/go.mod h1:4gW7WsVCke5TE7EPeYliwHlRUyBtfCwuFwuMg2DmyNY=
github.com/hashicorp/memberlist v0.1.3 h1:EmmoJme1matNzb+hMpDuR/0sbJSUisxyqBGG676r31M=
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
github.com/hashicorp/memberlist v0.2.2 h1:5+RffWKwqJ71YPu9mWsF7ZOscZmwfasdA8kbdC7AO2g=
github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE=
github.com/hashicorp/serf v0.8.2 h1:YZ7UKsJv+hKjqGVUUbtE3HNj79Eln2oQ75tniF6iPt0=
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/hashicorp/serf v0.9.2 h1:yJoyfZXo4Pk2p/M/viW+YLibBFiIbKoP79gu7kDAFP0=
github.com/hashicorp/serf v0.9.2/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk=
github.com/hashicorp/serf v0.9.3 h1:AVF6JDQQens6nMHT9OGERBvK0f8rPrAGILnsKLr6lzM=
github.com/hashicorp/serf v0.9.3/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk=
github.com/hashicorp/serf v0.9.5 h1:EBWvyu9tcRszt3Bxp3KNssBMP1KuHWyO51lz9+786iM=
Expand Down Expand Up @@ -438,7 +423,6 @@ github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKju
github.com/miekg/dns v1.1.30 h1:Qww6FseFn8PRfw07jueqIXqodm0JKiiKuK0DeXSqfyo=
github.com/miekg/dns v1.1.30/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
github.com/miekg/pkcs11 v1.0.2/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI=
github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ=
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
Expand All @@ -449,14 +433,10 @@ github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936/go.mod h1:r1VsdOzO
github.com/mitchellh/go-ps v0.0.0-20190716172923-621e5597135b/go.mod h1:r1VsdOzOPt1ZSrGZWFoNhsAedKnEd6r9Np1+5blZCWk=
github.com/mitchellh/go-testing-interface v1.0.0 h1:fzU/JVNcaqHQEcVFAKeR41fkiLdIPrefOvVG1VZ96U0=
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg=
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v0.0.0-20180220230111-00c29f56e238/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.3.1 h1:cCBH2gTD2K0OtLlv/Y5H01VQCqmlDxz30kS5Y5bqfLA=
github.com/mitchellh/mapstructure v1.3.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/mapstructure v1.3.3 h1:SzB1nHZ2Xi+17FP0zVQBHIZqvwRN9408fJO8h+eeNA8=
github.com/mitchellh/mapstructure v1.3.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY=
Expand Down Expand Up @@ -548,6 +528,8 @@ github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+Gx
github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFBS8=
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/pteich/errors v1.0.1 h1:ZQqdQcK079iH6YKb1/1hKSJ67+BuYBlSX3S07wNtEHE=
github.com/pteich/errors v1.0.1/go.mod h1:WgkErUbbxLTRULUtio3fSZfqAmeomF2958UjBIJlA4g=
github.com/quasilyte/go-consistent v0.0.0-20190521200055-c6f3937de18c/go.mod h1:5STLWrekHfjyYwxBRVRXNOSewLJ3PWfDJd1VyTS21fI=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
Expand Down Expand Up @@ -769,7 +751,6 @@ golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/net v0.0.0-20181029044818-c44066c5c816/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181106065722-10aee1819953/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down
40 changes: 20 additions & 20 deletions module.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
)

func init() {
caddy.RegisterModule(Storage{})
caddy.RegisterModule(ConsulStorage{})
}

func (Storage) CaddyModule() caddy.ModuleInfo {
func (ConsulStorage) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{
ID: "caddy.storage.consul",
New: func() caddy.Module {
Expand All @@ -23,28 +23,28 @@ func (Storage) CaddyModule() caddy.ModuleInfo {
}

// Provision is called by Caddy to prepare the module
func (s *Storage) Provision(ctx caddy.Context) error {
s.logger = ctx.Logger(s).Sugar()
s.logger.Infof("TLS storage is using Consul at %s", s.Address)
func (cs *ConsulStorage) Provision(ctx caddy.Context) error {
cs.logger = ctx.Logger(cs).Sugar()
cs.logger.Infof("TLS storage is using Consul at %cs", cs.Address)

// override default values from ENV
if aesKey := os.Getenv(EnvNameAESKey); aesKey != "" {
s.AESKey = []byte(aesKey)
cs.AESKey = []byte(aesKey)
}

if prefix := os.Getenv(EnvNamePrefix); prefix != "" {
s.Prefix = prefix
cs.Prefix = prefix
}

if valueprefix := os.Getenv(EnvValuePrefix); valueprefix != "" {
s.ValuePrefix = valueprefix
cs.ValuePrefix = valueprefix
}

return s.createConsulClient()
return cs.createConsulClient()
}

func (s *Storage) CertMagicStorage() (certmagic.Storage, error) {
return s, nil
func (cs *ConsulStorage) CertMagicStorage() (certmagic.Storage, error) {
return cs, nil
}

// UnmarshalCaddyfile parses plugin settings from Caddyfile
Expand All @@ -58,7 +58,7 @@ func (s *Storage) CertMagicStorage() (certmagic.Storage, error) {
// tls_enabled "false"
// tls_insecure "true"
// }
func (s *Storage) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
func (cs *ConsulStorage) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
for d.Next() {
key := d.Val()
var value string
Expand All @@ -72,44 +72,44 @@ func (s *Storage) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
if value != "" {
parsedAddress, err := caddy.ParseNetworkAddress(value)
if err == nil {
s.Address = parsedAddress.JoinHostPort(0)
cs.Address = parsedAddress.JoinHostPort(0)
}
}
case "token":
if value != "" {
s.Token = value
cs.Token = value
}
case "timeout":
if value != "" {
timeParse, err := strconv.Atoi(value)
if err == nil {
s.Timeout = timeParse
cs.Timeout = timeParse
}
}
case "prefix":
if value != "" {
s.Prefix = value
cs.Prefix = value
}
case "value_prefix":
if value != "" {
s.ValuePrefix = value
cs.ValuePrefix = value
}
case "aes_key":
if value != "" {
s.AESKey = []byte(value)
cs.AESKey = []byte(value)
}
case "tls_enabled":
if value != "" {
tlsParse, err := strconv.ParseBool(value)
if err == nil {
s.TlsEnabled = tlsParse
cs.TlsEnabled = tlsParse
}
}
case "tls_insecure":
if value != "" {
tlsInsecureParse, err := strconv.ParseBool(value)
if err == nil {
s.TlsInsecure = tlsInsecureParse
cs.TlsInsecure = tlsInsecureParse
}
}
}
Expand Down
Loading

0 comments on commit bb28076

Please sign in to comment.