From a59941574d41fdc0d884a4dd184f37bb983b86ab Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Fri, 13 May 2022 16:04:19 -0700 Subject: [PATCH] Remove BoltDB support Signed-off-by: Dave Henderson --- data/datasource.go | 2 - data/datasource_boltdb.go | 32 ----------- go.mod | 1 - go.sum | 3 - .../integration/datasources_boltdb_test.go | 55 ------------------- libkv/boltdb.go | 42 -------------- libkv/boltdb_test.go | 48 ---------------- 7 files changed, 183 deletions(-) delete mode 100644 data/datasource_boltdb.go delete mode 100644 internal/tests/integration/datasources_boltdb_test.go delete mode 100644 libkv/boltdb.go delete mode 100644 libkv/boltdb_test.go diff --git a/data/datasource.go b/data/datasource.go index 539ba122d..dd4f2fe01 100644 --- a/data/datasource.go +++ b/data/datasource.go @@ -42,8 +42,6 @@ func (d *Data) registerReaders() { d.sourceReaders["aws+smp"] = readAWSSMP d.sourceReaders["aws+sm"] = readAWSSecretsManager - // Deprecated: don't use - d.sourceReaders["boltdb"] = readBoltDB d.sourceReaders["consul"] = readConsul d.sourceReaders["consul+http"] = readConsul d.sourceReaders["consul+https"] = readConsul diff --git a/data/datasource_boltdb.go b/data/datasource_boltdb.go deleted file mode 100644 index 63be1e646..000000000 --- a/data/datasource_boltdb.go +++ /dev/null @@ -1,32 +0,0 @@ -package data - -import ( - "context" - - "github.com/hairyhenderson/gomplate/v3/internal/deprecated" - "github.com/hairyhenderson/gomplate/v3/libkv" - "github.com/pkg/errors" -) - -// Deprecated: don't use -func readBoltDB(ctx context.Context, source *Source, args ...string) (data []byte, err error) { - deprecated.WarnDeprecated(ctx, "boltdb support is deprecated and will be removed in a future major version of gomplate") - if source.kv == nil { - source.kv, err = libkv.NewBoltDB(source.URL) - if err != nil { - return nil, err - } - } - - if len(args) != 1 { - return nil, errors.New("missing key") - } - p := args[0] - - data, err = source.kv.Read(p) - if err != nil { - return nil, err - } - - return data, nil -} diff --git a/go.mod b/go.mod index 0be4cc9ec..493ab1fb0 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,6 @@ require ( github.com/stretchr/testify v1.7.1 github.com/ugorji/go/codec v1.2.7 github.com/zealic/xignore v0.3.3 - go.etcd.io/bbolt v1.3.6 gocloud.dev v0.25.0 golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 golang.org/x/sys v0.0.0-20220412211240-33da011f77ad diff --git a/go.sum b/go.sum index a8834cf0a..3a98dd60a 100644 --- a/go.sum +++ b/go.sum @@ -797,8 +797,6 @@ github.com/zealic/xignore v0.3.3 h1:EpLXUgZY/JEzFkTc+Y/VYypzXtNz+MSOMVCGW5Q4CKQ= github.com/zealic/xignore v0.3.3/go.mod h1:lhS8V7fuSOtJOKsvKI7WfsZE276/7AYEqokv3UiqEAU= github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= -go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU= -go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4= go.opencensus.io v0.15.0/go.mod h1:UffZAU+4sDEINUGP/B7UfBBkq4fqLu9zXAX7ke6CHW0= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= @@ -1032,7 +1030,6 @@ golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200828194041-157a740278f4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/internal/tests/integration/datasources_boltdb_test.go b/internal/tests/integration/datasources_boltdb_test.go deleted file mode 100644 index 848a3119d..000000000 --- a/internal/tests/integration/datasources_boltdb_test.go +++ /dev/null @@ -1,55 +0,0 @@ -package integration - -import ( - "testing" - - "github.com/stretchr/testify/require" - "go.etcd.io/bbolt" - "gotest.tools/v3/fs" -) - -func setupDatasourcesBoltDBTest(t *testing.T) *fs.Dir { - tmpDir := fs.NewDir(t, "gomplate-inttests") - t.Cleanup(tmpDir.Remove) - - db, err := bbolt.Open(tmpDir.Join("config.db"), 0600, nil) - require.NoError(t, err) - defer db.Close() - - err = db.Update(func(tx *bbolt.Tx) error { - var b *bbolt.Bucket - b, err = tx.CreateBucket([]byte("Bucket1")) - if err != nil { - return err - } - // the first 8 bytes are ignored when read by libkv, so we prefix with gibberish - err = b.Put([]byte("foo"), []byte("00000000bar")) - if err != nil { - return err - } - - b, err = tx.CreateBucket([]byte("Bucket2")) - if err != nil { - return err - } - err = b.Put([]byte("foobar"), []byte("00000000baz")) - return err - }) - require.NoError(t, err) - - return tmpDir -} - -func TestDatasources_BoltDB_Datasource(t *testing.T) { - tmpDir := setupDatasourcesBoltDBTest(t) - - // ignore the stderr output, it'll contain boltdb deprecation warning - o, _, err := cmd(t, "-d", "config=boltdb://"+tmpDir.Join("config.db#Bucket1"), - "-i", `{{(ds "config" "foo")}}`).run() - assertSuccess(t, o, "", err, "bar") - - o, _, err = cmd(t, "-d", "config=boltdb://"+tmpDir.Join("config.db#Bucket1"), - "-d", "config2=boltdb://"+tmpDir.Join("config.db#Bucket2"), - "-i", `{{(ds "config" "foo")}}-{{(ds "config2" "foobar")}}`).run() - assertSuccess(t, o, "", err, "bar-baz") -} diff --git a/libkv/boltdb.go b/libkv/boltdb.go deleted file mode 100644 index c8d111ba2..000000000 --- a/libkv/boltdb.go +++ /dev/null @@ -1,42 +0,0 @@ -package libkv - -import ( - "net/url" - "time" - - "github.com/docker/libkv" - "github.com/docker/libkv/store" - "github.com/docker/libkv/store/boltdb" - "github.com/hairyhenderson/gomplate/v3/conv" - "github.com/hairyhenderson/gomplate/v3/env" - "github.com/pkg/errors" -) - -// NewBoltDB - initialize a new BoltDB datasource handler -// Deprecated: don't use -func NewBoltDB(u *url.URL) (*LibKV, error) { - boltdb.Register() - - config, err := setupBoltDB(u.Fragment) - if err != nil { - return nil, err - } - kv, err := libkv.NewStore(store.BOLTDB, []string{u.Path}, config) - if err != nil { - return nil, errors.Wrapf(err, "BoltDB store creation failed") - } - return &LibKV{kv}, nil -} - -func setupBoltDB(bucket string) (*store.Config, error) { - if bucket == "" { - return nil, errors.New("missing bucket - must specify BoltDB bucket in URL fragment") - } - - t := conv.MustParseInt(env.Getenv("BOLTDB_TIMEOUT"), 10, 16) - return &store.Config{ - Bucket: bucket, - ConnectionTimeout: time.Duration(t) * time.Second, - PersistConnection: conv.Bool(env.Getenv("BOLTDB_PERSIST")), - }, nil -} diff --git a/libkv/boltdb_test.go b/libkv/boltdb_test.go deleted file mode 100644 index 7965ae43b..000000000 --- a/libkv/boltdb_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package libkv - -import ( - "net/url" - "os" - "testing" - "time" - - "github.com/docker/libkv/store" - "github.com/stretchr/testify/assert" -) - -func TestSetupBoltDB(t *testing.T) { - _, err := setupBoltDB("") - assert.Error(t, err) - - expectedConfig := &store.Config{Bucket: "foo"} - actualConfig, err := setupBoltDB("foo") - assert.NoError(t, err) - assert.Equal(t, expectedConfig, actualConfig) - - expectedConfig = &store.Config{ - Bucket: "bar", - ConnectionTimeout: 42 * time.Second, - } - os.Setenv("BOLTDB_TIMEOUT", "42") - defer os.Unsetenv("BOLTDB_TIMEOUT") - actualConfig, err = setupBoltDB("bar") - assert.NoError(t, err) - assert.Equal(t, expectedConfig, actualConfig) - - expectedConfig = &store.Config{ - Bucket: "bar", - ConnectionTimeout: 42 * time.Second, - PersistConnection: true, - } - os.Setenv("BOLTDB_PERSIST", "true") - defer os.Unsetenv("BOLTDB_PERSIST") - actualConfig, err = setupBoltDB("bar") - assert.NoError(t, err) - assert.Equal(t, expectedConfig, actualConfig) -} - -func TestNewBoltDB(t *testing.T) { - u, _ := url.Parse("boltdb:///bolt.db") - _, err := NewBoltDB(u) - assert.Error(t, err) -}