Skip to content

Commit d79c7d6

Browse files
authored
Merge pull request #14 from pteich/support_caddyfile_syntax
Support for Caddyfile configuration
2 parents 9b3eabb + 9e9ac15 commit d79c7d6

File tree

7 files changed

+187
-312
lines changed

7 files changed

+187
-312
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.14 AS builder
1+
FROM golang:1.15 AS builder
22

33
WORKDIR /workspace
44
RUN echo 'package main\n\
@@ -11,7 +11,7 @@ func main() {\n\
1111
caddycmd.Main()\n\
1212
}' > main.go && \
1313
go env -w GOPROXY="https://goproxy.io,direct" && \
14-
go mod init caddy && go get github.com/caddyserver/caddy/v2@master && go get && \
14+
go mod init caddy && go get github.com/caddyserver/caddy/v2@v2.2.0 && go get && \
1515
CGO_ENABLED=0 go build -trimpath -tags netgo -ldflags '-extldflags "-static" -s -w' -o /usr/bin/caddy
1616

1717

config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const (
1515
DefaultValuePrefix = "caddy-storage-consul"
1616

1717
// DefaultTimeout is the default timeout for Consul connections
18-
DefaultTimeout = 10 * time.Second
18+
DefaultTimeout = 10
1919

2020
// EnvNameAESKey defines the env variable name to override AES key
2121
EnvNameAESKey = "CADDY_CLUSTERING_CONSUL_AESKEY"

crypto.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111

1212
func (s *Storage) encrypt(bytes []byte) ([]byte, error) {
1313
// No key? No encrypt
14-
if len(s.config.AESKey) == 0 {
14+
if len(s.AESKey) == 0 {
1515
return bytes, nil
1616
}
1717

18-
c, err := aes.NewCipher(s.config.AESKey)
18+
c, err := aes.NewCipher(s.AESKey)
1919
if err != nil {
2020
return nil, fmt.Errorf("unable to create AES cipher: %w", err)
2121
}
@@ -42,20 +42,20 @@ func (s *Storage) EncryptStorageData(data *StorageData) ([]byte, error) {
4242
}
4343

4444
// Prefix with simple prefix and then encrypt
45-
bytes = append([]byte(s.config.ValuePrefix), bytes...)
45+
bytes = append([]byte(s.ValuePrefix), bytes...)
4646
return s.encrypt(bytes)
4747
}
4848

4949
func (s *Storage) decrypt(bytes []byte) ([]byte, error) {
5050
// No key? No decrypt
51-
if len(s.config.AESKey) == 0 {
51+
if len(s.AESKey) == 0 {
5252
return bytes, nil
5353
}
5454
if len(bytes) < aes.BlockSize {
5555
return nil, fmt.Errorf("invalid contents")
5656
}
5757

58-
block, err := aes.NewCipher(s.config.AESKey)
58+
block, err := aes.NewCipher(s.AESKey)
5959
if err != nil {
6060
return nil, fmt.Errorf("unable to create AES cipher: %w", err)
6161
}
@@ -81,13 +81,13 @@ func (s *Storage) DecryptStorageData(bytes []byte) (*StorageData, error) {
8181
}
8282

8383
// Simple sanity check of the beginning of the byte array just to check
84-
if len(bytes) < len(s.config.ValuePrefix) || string(bytes[:len(s.config.ValuePrefix)]) != s.config.ValuePrefix {
84+
if len(bytes) < len(s.ValuePrefix) || string(bytes[:len(s.ValuePrefix)]) != s.ValuePrefix {
8585
return nil, fmt.Errorf("invalid data format")
8686
}
8787

8888
// Now just json unmarshal
8989
data := &StorageData{}
90-
if err := json.Unmarshal(bytes[len(s.config.ValuePrefix):], data); err != nil {
90+
if err := json.Unmarshal(bytes[len(s.ValuePrefix):], data); err != nil {
9191
return nil, fmt.Errorf("unable to unmarshal result: %w", err)
9292
}
9393
return data, nil

go.mod

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@ module github.com/pteich/caddy-tlsconsul
33
go 1.14
44

55
require (
6-
github.com/armon/go-metrics v0.3.3 // indirect
7-
github.com/caddyserver/caddy/v2 v2.0.1-0.20200605181936-1dfb11486eac
8-
github.com/caddyserver/certmagic v0.11.1
9-
github.com/cenkalti/backoff/v4 v4.0.2 // indirect
10-
github.com/hashicorp/consul/api v1.4.0
6+
github.com/armon/go-metrics v0.3.4 // indirect
7+
github.com/caddyserver/caddy/v2 v2.2.0
8+
github.com/caddyserver/certmagic v0.12.0
9+
github.com/hashicorp/consul/api v1.7.0
1110
github.com/hashicorp/go-hclog v0.14.1 // indirect
12-
github.com/hashicorp/go-immutable-radix v1.2.0 // indirect
11+
github.com/hashicorp/go-immutable-radix v1.3.0 // indirect
12+
github.com/hashicorp/go.net v0.0.1 // indirect
1313
github.com/hashicorp/golang-lru v0.5.4 // indirect
14-
github.com/hashicorp/serf v0.9.2 // indirect
15-
github.com/miekg/dns v1.1.29 // indirect
16-
github.com/mitchellh/mapstructure v1.3.1 // indirect
14+
github.com/hashicorp/serf v0.9.5 // indirect
15+
github.com/mattn/go-colorable v0.1.8 // indirect
16+
github.com/mitchellh/gox v0.4.0 // indirect
17+
github.com/mitchellh/iochan v1.0.0 // indirect
18+
github.com/mitchellh/mapstructure v1.3.3 // indirect
1719
github.com/stretchr/testify v1.5.1
1820
go.uber.org/zap v1.15.0
19-
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 // indirect
20-
golang.org/x/net v0.0.0-20200602114024-627f9648deb9 // indirect
21-
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980 // indirect
22-
gopkg.in/square/go-jose.v2 v2.5.1 // indirect
21+
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
22+
golang.org/x/sys v0.0.0-20201008064518-c1f3e3309c71 // indirect
23+
golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb // indirect
24+
honnef.co/go/tools v0.0.1-2020.1.3 // indirect
2325
)

0 commit comments

Comments
 (0)