Skip to content

Commit 0a014fc

Browse files
authored
Merge pull request #17 from PowerDNS/upgrades-20221027
Upgrades, loggers and GetBackendWithParams
2 parents 28dad2e + d285442 commit 0a014fc

File tree

7 files changed

+152
-103
lines changed

7 files changed

+152
-103
lines changed

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
go: [ '1.18', '1.17' ]
15+
go: [ '1.19', '1.18' ]
1616

1717
name: Go ${{ matrix.go }} tests
1818
steps:

backends/s3/s3.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"time"
1515

1616
"github.com/PowerDNS/go-tlsconfig"
17+
"github.com/go-logr/logr"
1718
minio "github.com/minio/minio-go/v7"
1819
"github.com/minio/minio-go/v7/pkg/credentials"
1920

@@ -77,6 +78,9 @@ type Options struct {
7778
// change in marker, to ensure a full sync even if the marker would for
7879
// some reason get out of sync.
7980
UpdateMarkerForceListInterval time.Duration `yaml:"update_marker_force_list_interval"`
81+
82+
// Not loaded from YAML
83+
Logger logr.Logger `yaml:"-"`
8084
}
8185

8286
func (o Options) Check() error {
@@ -96,6 +100,7 @@ type Backend struct {
96100
opt Options
97101
config *minio.Options
98102
client *minio.Client
103+
log logr.Logger
99104

100105
mu sync.Mutex
101106
lastMarker string
@@ -220,6 +225,9 @@ func (b *Backend) Delete(ctx context.Context, name string) error {
220225
return err
221226
}
222227

228+
// New creates a new backend instance.
229+
// The lifetime of the context passed in must span the lifetime of the whole
230+
// backend instance, not just the init time, so do not set any timeout on it!
223231
func New(ctx context.Context, opt Options) (*Backend, error) {
224232
if opt.Region == "" {
225233
opt.Region = DefaultRegion
@@ -237,15 +245,19 @@ func New(ctx context.Context, opt Options) (*Backend, error) {
237245
return nil, err
238246
}
239247

248+
log := opt.Logger
249+
if log.GetSink() == nil {
250+
log = logr.Discard()
251+
}
252+
log = log.WithName("s3")
253+
240254
// Automatic TLS handling
241255
// This MUST receive a longer running context to be able to automatically
242256
// reload certificates, so we use the original ctx, not one with added
243257
// InitTimeout.
244258
tlsmgr, err := tlsconfig.NewManager(ctx, opt.TLS, tlsconfig.Options{
245259
IsClient: true,
246-
// TODO: logging might be useful here, but we need to figure this
247-
// out for other parts of simpleblob first.
248-
Logr: nil,
260+
Logr: log.WithName("tls-manager"),
249261
})
250262
if err != nil {
251263
return nil, err
@@ -277,7 +289,7 @@ func New(ctx context.Context, opt Options) (*Backend, error) {
277289
case "https":
278290
useSSL = true
279291
default:
280-
return nil, fmt.Errorf("Unsupported scheme for S3: '%s'", u.Scheme)
292+
return nil, fmt.Errorf("unsupported scheme for S3: '%s'", u.Scheme)
281293
}
282294

283295
cfg := &minio.Options{
@@ -290,7 +302,7 @@ func New(ctx context.Context, opt Options) (*Backend, error) {
290302
// Remove scheme from URL.
291303
// Leave remaining validation to Minio client.
292304
endpoint := opt.EndpointURL[len(u.Scheme)+1:] // Remove scheme and colon
293-
endpoint = strings.TrimLeft(endpoint, "/") // Remove slashes if any
305+
endpoint = strings.TrimLeft(endpoint, "/") // Remove slashes if any
294306

295307
client, err := minio.New(endpoint, cfg)
296308
if err != nil {
@@ -318,6 +330,7 @@ func New(ctx context.Context, opt Options) (*Backend, error) {
318330
opt: opt,
319331
config: cfg,
320332
client: client,
333+
log: log,
321334
}
322335

323336
return b, nil
@@ -344,6 +357,7 @@ func init() {
344357
if err := p.OptionsThroughYAML(&opt); err != nil {
345358
return nil, err
346359
}
360+
opt.Logger = p.Logger
347361
return New(ctx, opt)
348362
})
349363
}

backends/s3/s3_test.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package s3
22

33
import (
44
"context"
5-
"io/ioutil"
65
"os"
76
"testing"
87
"time"
@@ -21,18 +20,17 @@ import (
2120
//
2221
// To run a Minio for this :
2322
//
24-
// env MINIO_ROOT_USER=test MINIO_ROOT_PASSWORD=secret minio server /tmp/test-data/
23+
// env MINIO_ROOT_USER=test MINIO_ROOT_PASSWORD=secret minio server /tmp/test-data/
2524
//
2625
// Example test config:
2726
//
28-
// {
29-
// "access_key": "test",
30-
// "secret_key": "verysecret",
31-
// "region": "us-east-1",
32-
// "bucket": "test-bucket",
33-
// "endpoint_url": "http://127.0.0.1:9000"
34-
// }
35-
//
27+
// {
28+
// "access_key": "test",
29+
// "secret_key": "verysecret",
30+
// "region": "us-east-1",
31+
// "bucket": "test-bucket",
32+
// "endpoint_url": "http://127.0.0.1:9000"
33+
// }
3634
const TestConfigPathEnv = "SIMPLEBLOB_TEST_S3_CONFIG"
3735

3836
func getBackend(ctx context.Context, t *testing.T) (b *Backend) {
@@ -42,7 +40,7 @@ func getBackend(ctx context.Context, t *testing.T) (b *Backend) {
4240
return
4341
}
4442

45-
cfgContents, err := ioutil.ReadFile(cfgPath)
43+
cfgContents, err := os.ReadFile(cfgPath)
4644
require.NoError(t, err)
4745

4846
var opt Options
@@ -59,13 +57,13 @@ func getBackend(ctx context.Context, t *testing.T) (b *Backend) {
5957
return
6058
}
6159
for _, blob := range blobs {
62-
err := b.client.RemoveObject(ctx, b.opt.Bucket, blob.Name, minio.RemoveObjectOptions{})
60+
err := b.client.RemoveObject(ctx, b.opt.Bucket, blob.Name, minio.RemoveObjectOptions{})
6361
if err != nil {
6462
t.Logf("Object delete error: %s", err)
6563
}
6664
}
6765
// This one is not returned by the List command
68-
err = b.client.RemoveObject(ctx, b.opt.Bucket, UpdateMarkerFilename, minio.RemoveObjectOptions{})
66+
err = b.client.RemoveObject(ctx, b.opt.Bucket, UpdateMarkerFilename, minio.RemoveObjectOptions{})
6967
require.NoError(t, err)
7068
}
7169
t.Cleanup(cleanup)

go.mod

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
module github.com/PowerDNS/simpleblob
22

3-
go 1.17
3+
go 1.18
44

55
require (
6-
github.com/PowerDNS/go-tlsconfig v0.0.0-20201014142732-fe6ff56e2a95
7-
github.com/minio/minio-go/v7 v7.0.30
8-
github.com/prometheus/client_golang v1.12.0
9-
github.com/stretchr/testify v1.7.0
6+
github.com/PowerDNS/go-tlsconfig v0.0.0-20221101135152-0956853b28df
7+
github.com/go-logr/logr v1.2.3
8+
github.com/minio/minio-go/v7 v7.0.42
9+
github.com/prometheus/client_golang v1.13.0
10+
github.com/stretchr/testify v1.8.1
1011
gopkg.in/yaml.v2 v2.4.0
1112
)
1213

@@ -15,35 +16,30 @@ require (
1516
github.com/cespare/xxhash/v2 v2.1.2 // indirect
1617
github.com/davecgh/go-spew v1.1.1 // indirect
1718
github.com/dustin/go-humanize v1.0.0 // indirect
18-
github.com/go-logr/logr v0.2.1 // indirect
1919
github.com/golang/protobuf v1.5.2 // indirect
20-
github.com/google/go-cmp v0.5.6 // indirect
21-
github.com/google/uuid v1.1.1 // indirect
22-
github.com/gopherjs/gopherjs v1.17.2 // indirect
20+
github.com/google/uuid v1.3.0 // indirect
2321
github.com/json-iterator/go v1.1.12 // indirect
24-
github.com/jtolds/gls v4.20.0+incompatible // indirect
25-
github.com/klauspost/compress v1.13.5 // indirect
26-
github.com/klauspost/cpuid v1.3.1 // indirect
22+
github.com/klauspost/compress v1.15.12 // indirect
23+
github.com/klauspost/cpuid/v2 v2.1.2 // indirect
2724
github.com/kr/text v0.2.0 // indirect
28-
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
29-
github.com/minio/md5-simd v1.1.0 // indirect
30-
github.com/minio/sha256-simd v0.1.1 // indirect
25+
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
26+
github.com/minio/md5-simd v1.1.2 // indirect
27+
github.com/minio/sha256-simd v1.0.0 // indirect
3128
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
3229
github.com/modern-go/reflect2 v1.0.2 // indirect
3330
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
3431
github.com/pmezard/go-difflib v1.0.0 // indirect
35-
github.com/prometheus/client_model v0.2.0 // indirect
36-
github.com/prometheus/common v0.32.1 // indirect
37-
github.com/prometheus/procfs v0.7.3 // indirect
38-
github.com/rs/xid v1.2.1 // indirect
39-
github.com/sirupsen/logrus v1.8.1 // indirect
40-
github.com/smartystreets/assertions v1.13.0 // indirect
41-
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
42-
golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect
43-
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
44-
golang.org/x/text v0.3.6 // indirect
45-
google.golang.org/protobuf v1.27.1 // indirect
32+
github.com/prometheus/client_model v0.3.0 // indirect
33+
github.com/prometheus/common v0.37.0 // indirect
34+
github.com/prometheus/procfs v0.8.0 // indirect
35+
github.com/rs/xid v1.4.0 // indirect
36+
github.com/sirupsen/logrus v1.9.0 // indirect
37+
golang.org/x/crypto v0.1.0 // indirect
38+
golang.org/x/net v0.1.0 // indirect
39+
golang.org/x/sys v0.1.0 // indirect
40+
golang.org/x/text v0.4.0 // indirect
41+
google.golang.org/protobuf v1.28.1 // indirect
4642
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
47-
gopkg.in/ini.v1 v1.57.0 // indirect
48-
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
43+
gopkg.in/ini.v1 v1.67.0 // indirect
44+
gopkg.in/yaml.v3 v3.0.1 // indirect
4945
)

0 commit comments

Comments
 (0)