Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrades, loggers and GetBackendWithParams #17

Merged
merged 3 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.18', '1.17' ]
go: [ '1.19', '1.18' ]

name: Go ${{ matrix.go }} tests
steps:
Expand Down
24 changes: 19 additions & 5 deletions backends/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/PowerDNS/go-tlsconfig"
"github.com/go-logr/logr"
minio "github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"

Expand Down Expand Up @@ -77,6 +78,9 @@ type Options struct {
// change in marker, to ensure a full sync even if the marker would for
// some reason get out of sync.
UpdateMarkerForceListInterval time.Duration `yaml:"update_marker_force_list_interval"`

// Not loaded from YAML
Logger logr.Logger `yaml:"-"`
}

func (o Options) Check() error {
Expand All @@ -96,6 +100,7 @@ type Backend struct {
opt Options
config *minio.Options
client *minio.Client
log logr.Logger

mu sync.Mutex
lastMarker string
Expand Down Expand Up @@ -220,6 +225,9 @@ func (b *Backend) Delete(ctx context.Context, name string) error {
return err
}

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

log := opt.Logger
if log.GetSink() == nil {
log = logr.Discard()
}
log = log.WithName("s3")

// Automatic TLS handling
// This MUST receive a longer running context to be able to automatically
// reload certificates, so we use the original ctx, not one with added
// InitTimeout.
tlsmgr, err := tlsconfig.NewManager(ctx, opt.TLS, tlsconfig.Options{
IsClient: true,
// TODO: logging might be useful here, but we need to figure this
// out for other parts of simpleblob first.
Logr: nil,
Logr: log.WithName("tls-manager"),
})
if err != nil {
return nil, err
Expand Down Expand Up @@ -277,7 +289,7 @@ func New(ctx context.Context, opt Options) (*Backend, error) {
case "https":
useSSL = true
default:
return nil, fmt.Errorf("Unsupported scheme for S3: '%s'", u.Scheme)
return nil, fmt.Errorf("unsupported scheme for S3: '%s'", u.Scheme)
}

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

client, err := minio.New(endpoint, cfg)
if err != nil {
Expand Down Expand Up @@ -318,6 +330,7 @@ func New(ctx context.Context, opt Options) (*Backend, error) {
opt: opt,
config: cfg,
client: client,
log: log,
}

return b, nil
Expand All @@ -344,6 +357,7 @@ func init() {
if err := p.OptionsThroughYAML(&opt); err != nil {
return nil, err
}
opt.Logger = p.Logger
return New(ctx, opt)
})
}
24 changes: 11 additions & 13 deletions backends/s3/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package s3

import (
"context"
"io/ioutil"
"os"
"testing"
"time"
Expand All @@ -21,18 +20,17 @@ import (
//
// To run a Minio for this :
//
// env MINIO_ROOT_USER=test MINIO_ROOT_PASSWORD=secret minio server /tmp/test-data/
// env MINIO_ROOT_USER=test MINIO_ROOT_PASSWORD=secret minio server /tmp/test-data/
//
// Example test config:
//
// {
// "access_key": "test",
// "secret_key": "verysecret",
// "region": "us-east-1",
// "bucket": "test-bucket",
// "endpoint_url": "http://127.0.0.1:9000"
// }
//
// {
// "access_key": "test",
// "secret_key": "verysecret",
// "region": "us-east-1",
// "bucket": "test-bucket",
// "endpoint_url": "http://127.0.0.1:9000"
// }
const TestConfigPathEnv = "SIMPLEBLOB_TEST_S3_CONFIG"

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

cfgContents, err := ioutil.ReadFile(cfgPath)
cfgContents, err := os.ReadFile(cfgPath)
require.NoError(t, err)

var opt Options
Expand All @@ -59,13 +57,13 @@ func getBackend(ctx context.Context, t *testing.T) (b *Backend) {
return
}
for _, blob := range blobs {
err := b.client.RemoveObject(ctx, b.opt.Bucket, blob.Name, minio.RemoveObjectOptions{})
err := b.client.RemoveObject(ctx, b.opt.Bucket, blob.Name, minio.RemoveObjectOptions{})
if err != nil {
t.Logf("Object delete error: %s", err)
}
}
// This one is not returned by the List command
err = b.client.RemoveObject(ctx, b.opt.Bucket, UpdateMarkerFilename, minio.RemoveObjectOptions{})
err = b.client.RemoveObject(ctx, b.opt.Bucket, UpdateMarkerFilename, minio.RemoveObjectOptions{})
require.NoError(t, err)
}
t.Cleanup(cleanup)
Expand Down
52 changes: 24 additions & 28 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module github.com/PowerDNS/simpleblob

go 1.17
go 1.18

require (
github.com/PowerDNS/go-tlsconfig v0.0.0-20201014142732-fe6ff56e2a95
github.com/minio/minio-go/v7 v7.0.30
github.com/prometheus/client_golang v1.12.0
github.com/stretchr/testify v1.7.0
github.com/PowerDNS/go-tlsconfig v0.0.0-20221101135152-0956853b28df
github.com/go-logr/logr v1.2.3
github.com/minio/minio-go/v7 v7.0.42
github.com/prometheus/client_golang v1.13.0
github.com/stretchr/testify v1.8.1
gopkg.in/yaml.v2 v2.4.0
)

Expand All @@ -15,35 +16,30 @@ require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/go-logr/logr v0.2.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/uuid v1.1.1 // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/klauspost/compress v1.13.5 // indirect
github.com/klauspost/cpuid v1.3.1 // indirect
github.com/klauspost/compress v1.15.12 // indirect
github.com/klauspost/cpuid/v2 v2.1.2 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/minio/md5-simd v1.1.0 // indirect
github.com/minio/sha256-simd v0.1.1 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/rs/xid v1.2.1 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/smartystreets/assertions v1.13.0 // indirect
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
golang.org/x/text v0.3.6 // indirect
google.golang.org/protobuf v1.27.1 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/rs/xid v1.4.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/net v0.1.0 // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/text v0.4.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/ini.v1 v1.57.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading