Skip to content

Commit d585db3

Browse files
authored
Merge pull request #32 from pteich/fix-lock-warning
Fix lock warning
2 parents dfa3d9a + 3dc2c5c commit d585db3

File tree

7 files changed

+464
-1729
lines changed

7 files changed

+464
-1729
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.18 AS builder
1+
FROM golang:1.23 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@v2.5.1 && go get && \
14+
go mod init caddy && go get github.com/pteich/caddy-tlsconsul@fix-lock-warning && go get github.com/caddyserver/caddy/v2@v2.8.4 && go get && \
1515
CGO_ENABLED=0 go build -trimpath -tags netgo -ldflags '-extldflags "-static" -s -w' -o /usr/bin/caddy
1616

1717

crypto.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"crypto/cipher"
66
"crypto/rand"
77
"encoding/json"
8+
"errors"
9+
"fmt"
810
"io"
9-
10-
"github.com/pteich/errors"
1111
)
1212

1313
func (cs *ConsulStorage) encrypt(bytes []byte) ([]byte, error) {
@@ -18,18 +18,18 @@ func (cs *ConsulStorage) encrypt(bytes []byte) ([]byte, error) {
1818

1919
c, err := aes.NewCipher(cs.AESKey)
2020
if err != nil {
21-
return nil, errors.Wrap(err, "unable to create AES cipher")
21+
return nil, fmt.Errorf("unable to create AES cipher: %w", err)
2222
}
2323

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

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

3535
return gcm.Seal(nonce, nonce, bytes, nil), nil
@@ -39,7 +39,7 @@ func (cs *ConsulStorage) EncryptStorageData(data *StorageData) ([]byte, error) {
3939
// JSON marshal, then encrypt if key is there
4040
bytes, err := json.Marshal(data)
4141
if err != nil {
42-
return nil, errors.Wrap(err, "unable to marshal")
42+
return nil, fmt.Errorf("unable to marshal: %w", err)
4343
}
4444

4545
// Prefix with simple prefix and then encrypt
@@ -58,17 +58,17 @@ func (cs *ConsulStorage) decrypt(bytes []byte) ([]byte, error) {
5858

5959
block, err := aes.NewCipher(cs.AESKey)
6060
if err != nil {
61-
return nil, errors.Wrap(err, "unable to create AES cipher")
61+
return nil, fmt.Errorf("unable to create AES cipher: %w", err)
6262
}
6363

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

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

7474
return out, nil
@@ -78,7 +78,7 @@ func (cs *ConsulStorage) DecryptStorageData(bytes []byte) (*StorageData, error)
7878
// We have to decrypt if there is an AES key and then JSON unmarshal
7979
bytes, err := cs.decrypt(bytes)
8080
if err != nil {
81-
return nil, errors.Wrap(err, "unable to decrypt data")
81+
return nil, fmt.Errorf("unable to decrypt data: %w", err)
8282
}
8383

8484
// Simple sanity check of the beginning of the byte array just to check
@@ -89,7 +89,7 @@ func (cs *ConsulStorage) DecryptStorageData(bytes []byte) (*StorageData, error)
8989
// Now just json unmarshal
9090
data := &StorageData{}
9191
if err := json.Unmarshal(bytes[len(cs.ValuePrefix):], data); err != nil {
92-
return nil, errors.Wrap(err, "unable to unmarshal result")
92+
return nil, fmt.Errorf("unable to unmarshal result: %w", err)
9393
}
9494
return data, nil
9595
}

go.mod

Lines changed: 102 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,108 @@
11
module github.com/pteich/caddy-tlsconsul
22

3-
go 1.16
3+
go 1.22.0
4+
5+
toolchain go1.22.5
6+
7+
require (
8+
github.com/caddyserver/caddy/v2 v2.8.4
9+
github.com/caddyserver/certmagic v0.21.3
10+
github.com/hashicorp/consul/api v1.29.4
11+
github.com/stretchr/testify v1.9.0
12+
github.com/testcontainers/testcontainers-go/modules/consul v0.33.0
13+
go.uber.org/zap v1.27.0
14+
)
415

516
require (
6-
github.com/armon/go-metrics v0.4.0 // indirect
7-
github.com/caddyserver/caddy/v2 v2.5.1
8-
github.com/caddyserver/certmagic v0.16.1
9-
github.com/fatih/color v1.13.0 // indirect
10-
github.com/hashicorp/consul/api v1.13.0
11-
github.com/hashicorp/go-hclog v1.2.0 // indirect
12-
github.com/hashicorp/serf v0.9.8 // indirect
13-
github.com/klauspost/cpuid/v2 v2.0.12 // indirect
14-
github.com/mattn/go-colorable v0.1.12 // indirect
15-
github.com/miekg/dns v1.1.49 // indirect
17+
dario.cat/mergo v1.0.0 // indirect
18+
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
19+
github.com/Microsoft/go-winio v0.6.2 // indirect
20+
github.com/armon/go-metrics v0.4.1 // indirect
21+
github.com/beorn7/perks v1.0.1 // indirect
22+
github.com/caddyserver/zerossl v0.1.3 // indirect
23+
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
24+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
25+
github.com/containerd/containerd v1.7.18 // indirect
26+
github.com/containerd/log v0.1.0 // indirect
27+
github.com/containerd/platforms v0.2.1 // indirect
28+
github.com/cpuguy83/dockercfg v0.3.1 // indirect
29+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
30+
github.com/distribution/reference v0.6.0 // indirect
31+
github.com/docker/docker v27.1.1+incompatible // indirect
32+
github.com/docker/go-connections v0.5.0 // indirect
33+
github.com/docker/go-units v0.5.0 // indirect
34+
github.com/fatih/color v1.17.0 // indirect
35+
github.com/felixge/httpsnoop v1.0.4 // indirect
36+
github.com/go-logr/logr v1.4.2 // indirect
37+
github.com/go-logr/stdr v1.2.2 // indirect
38+
github.com/go-ole/go-ole v1.2.6 // indirect
39+
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
40+
github.com/gogo/protobuf v1.3.2 // indirect
41+
github.com/google/pprof v0.0.0-20240903155634-a8630aee4ab9 // indirect
42+
github.com/google/uuid v1.6.0 // indirect
43+
github.com/hashicorp/errwrap v1.1.0 // indirect
44+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
45+
github.com/hashicorp/go-hclog v1.6.3 // indirect
46+
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
47+
github.com/hashicorp/go-multierror v1.1.1 // indirect
48+
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
49+
github.com/hashicorp/golang-lru v1.0.2 // indirect
50+
github.com/hashicorp/serf v0.10.1 // indirect
51+
github.com/klauspost/compress v1.17.9 // indirect
52+
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
53+
github.com/libdns/libdns v0.2.2 // indirect
54+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
55+
github.com/magiconair/properties v1.8.7 // indirect
56+
github.com/mattn/go-colorable v0.1.13 // indirect
57+
github.com/mattn/go-isatty v0.0.20 // indirect
58+
github.com/mholt/acmez/v2 v2.0.2 // indirect
59+
github.com/miekg/dns v1.1.62 // indirect
60+
github.com/mitchellh/go-homedir v1.1.0 // indirect
1661
github.com/mitchellh/mapstructure v1.5.0 // indirect
17-
github.com/onsi/ginkgo v1.16.5 // indirect
18-
github.com/pteich/errors v1.0.1
19-
github.com/stretchr/testify v1.7.1
20-
go.uber.org/multierr v1.8.0 // indirect
21-
go.uber.org/zap v1.21.0
22-
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
23-
golang.org/x/net v0.0.0-20220531201128-c960675eff93 // indirect
24-
golang.org/x/tools v0.1.10 // indirect
25-
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
26-
google.golang.org/protobuf v1.28.0 // indirect
62+
github.com/moby/docker-image-spec v1.3.1 // indirect
63+
github.com/moby/patternmatcher v0.6.0 // indirect
64+
github.com/moby/sys/sequential v0.5.0 // indirect
65+
github.com/moby/sys/user v0.1.0 // indirect
66+
github.com/moby/term v0.5.0 // indirect
67+
github.com/morikuni/aec v1.0.0 // indirect
68+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
69+
github.com/onsi/ginkgo/v2 v2.20.2 // indirect
70+
github.com/opencontainers/go-digest v1.0.0 // indirect
71+
github.com/opencontainers/image-spec v1.1.0 // indirect
72+
github.com/pkg/errors v0.9.1 // indirect
73+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
74+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
75+
github.com/prometheus/client_golang v1.20.3 // indirect
76+
github.com/prometheus/client_model v0.6.1 // indirect
77+
github.com/prometheus/common v0.59.1 // indirect
78+
github.com/prometheus/procfs v0.15.1 // indirect
79+
github.com/quic-go/qpack v0.5.1 // indirect
80+
github.com/quic-go/quic-go v0.47.0 // indirect
81+
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
82+
github.com/shoenig/go-m1cpu v0.1.6 // indirect
83+
github.com/sirupsen/logrus v1.9.3 // indirect
84+
github.com/testcontainers/testcontainers-go v0.33.0 // indirect
85+
github.com/tklauser/go-sysconf v0.3.12 // indirect
86+
github.com/tklauser/numcpus v0.6.1 // indirect
87+
github.com/yusufpapurcu/wmi v1.2.3 // indirect
88+
github.com/zeebo/blake3 v0.2.4 // indirect
89+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
90+
go.opentelemetry.io/otel v1.24.0 // indirect
91+
go.opentelemetry.io/otel/metric v1.24.0 // indirect
92+
go.opentelemetry.io/otel/trace v1.24.0 // indirect
93+
go.uber.org/mock v0.4.0 // indirect
94+
go.uber.org/multierr v1.11.0 // indirect
95+
go.uber.org/zap/exp v0.2.0 // indirect
96+
golang.org/x/crypto v0.27.0 // indirect
97+
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e // indirect
98+
golang.org/x/mod v0.21.0 // indirect
99+
golang.org/x/net v0.29.0 // indirect
100+
golang.org/x/sync v0.8.0 // indirect
101+
golang.org/x/sys v0.25.0 // indirect
102+
golang.org/x/term v0.24.0 // indirect
103+
golang.org/x/text v0.18.0 // indirect
104+
golang.org/x/time v0.6.0 // indirect
105+
golang.org/x/tools v0.24.0 // indirect
106+
google.golang.org/protobuf v1.34.2 // indirect
107+
gopkg.in/yaml.v3 v3.0.1 // indirect
27108
)

0 commit comments

Comments
 (0)