mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-04-26 18:45:10 +00:00
always allow 'bucket' as a config key for object stores (#1349)
Signed-off-by: Steve Kriss <krisss@vmware.com>
This commit is contained in:
@@ -64,7 +64,7 @@ func isValidSignatureVersion(signatureVersion string) bool {
|
||||
}
|
||||
|
||||
func (o *ObjectStore) Init(config map[string]string) error {
|
||||
if err := cloudprovider.ValidateConfigKeys(config,
|
||||
if err := cloudprovider.ValidateObjectStoreConfigKeys(config,
|
||||
regionKey,
|
||||
s3URLKey,
|
||||
publicURLKey,
|
||||
|
||||
@@ -66,7 +66,7 @@ func NewVolumeSnapshotter(logger logrus.FieldLogger) *VolumeSnapshotter {
|
||||
}
|
||||
|
||||
func (b *VolumeSnapshotter) Init(config map[string]string) error {
|
||||
if err := cloudprovider.ValidateConfigKeys(config, regionKey); err != nil {
|
||||
if err := cloudprovider.ValidateVolumeSnapshotterConfigKeys(config, regionKey); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ func mapLookup(data map[string]string) func(string) string {
|
||||
}
|
||||
|
||||
func (o *ObjectStore) Init(config map[string]string) error {
|
||||
if err := cloudprovider.ValidateConfigKeys(config, resourceGroupConfigKey, storageAccountConfigKey); err != nil {
|
||||
if err := cloudprovider.ValidateObjectStoreConfigKeys(config, resourceGroupConfigKey, storageAccountConfigKey); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ func NewVolumeSnapshotter(logger logrus.FieldLogger) *VolumeSnapshotter {
|
||||
}
|
||||
|
||||
func (b *VolumeSnapshotter) Init(config map[string]string) error {
|
||||
if err := cloudprovider.ValidateConfigKeys(config, resourceGroupConfigKey, apiTimeoutConfigKey); err != nil {
|
||||
if err := cloudprovider.ValidateVolumeSnapshotterConfigKeys(config, resourceGroupConfigKey, apiTimeoutConfigKey); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,22 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
)
|
||||
|
||||
func ValidateConfigKeys(config map[string]string, validKeys ...string) error {
|
||||
// ValidateObjectStoreConfigKeys ensures that an object store's config
|
||||
// is valid by making sure each `config` key is in the `validKeys` list.
|
||||
// The special key "bucket" is always considered valid.
|
||||
func ValidateObjectStoreConfigKeys(config map[string]string, validKeys ...string) error {
|
||||
// `bucket` is automatically added to all object store config by
|
||||
// velero, so add it as a valid key.
|
||||
return validateConfigKeys(config, append(validKeys, "bucket")...)
|
||||
}
|
||||
|
||||
// ValidateVolumeSnapshotterConfigKeys ensures that a volume snapshotter's
|
||||
// config is valid by making sure each `config` key is in the `validKeys` list.
|
||||
func ValidateVolumeSnapshotterConfigKeys(config map[string]string, validKeys ...string) error {
|
||||
return validateConfigKeys(config, validKeys...)
|
||||
}
|
||||
|
||||
func validateConfigKeys(config map[string]string, validKeys ...string) error {
|
||||
validKeysSet := sets.NewString(validKeys...)
|
||||
|
||||
var invalidKeys []string
|
||||
|
||||
@@ -23,12 +23,15 @@ import (
|
||||
)
|
||||
|
||||
func TestValidateConfigKeys(t *testing.T) {
|
||||
assert.NoError(t, ValidateConfigKeys(nil))
|
||||
assert.NoError(t, ValidateConfigKeys(map[string]string{}))
|
||||
assert.NoError(t, ValidateConfigKeys(map[string]string{"foo": "bar"}, "foo"))
|
||||
assert.NoError(t, ValidateConfigKeys(map[string]string{"foo": "bar", "bar": "baz"}, "foo", "bar"))
|
||||
assert.NoError(t, validateConfigKeys(nil))
|
||||
assert.NoError(t, validateConfigKeys(map[string]string{}))
|
||||
assert.NoError(t, validateConfigKeys(map[string]string{"foo": "bar"}, "foo"))
|
||||
assert.NoError(t, validateConfigKeys(map[string]string{"foo": "bar", "bar": "baz"}, "foo", "bar"))
|
||||
|
||||
assert.Error(t, ValidateConfigKeys(map[string]string{"foo": "bar"}))
|
||||
assert.Error(t, ValidateConfigKeys(map[string]string{"foo": "bar"}, "Foo"))
|
||||
assert.Error(t, ValidateConfigKeys(map[string]string{"foo": "bar", "boo": ""}, "foo"))
|
||||
assert.Error(t, validateConfigKeys(map[string]string{"foo": "bar"}))
|
||||
assert.Error(t, validateConfigKeys(map[string]string{"foo": "bar"}, "Foo"))
|
||||
assert.Error(t, validateConfigKeys(map[string]string{"foo": "bar", "boo": ""}, "foo"))
|
||||
|
||||
assert.NoError(t, ValidateObjectStoreConfigKeys(map[string]string{"bucket": "foo"}))
|
||||
assert.Error(t, ValidateVolumeSnapshotterConfigKeys(map[string]string{"bucket": "foo"}))
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func NewObjectStore(logger logrus.FieldLogger) *ObjectStore {
|
||||
}
|
||||
|
||||
func (o *ObjectStore) Init(config map[string]string) error {
|
||||
if err := cloudprovider.ValidateConfigKeys(config); err != nil {
|
||||
if err := cloudprovider.ValidateObjectStoreConfigKeys(config); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ func NewVolumeSnapshotter(logger logrus.FieldLogger) *VolumeSnapshotter {
|
||||
}
|
||||
|
||||
func (b *VolumeSnapshotter) Init(config map[string]string) error {
|
||||
if err := cloudprovider.ValidateConfigKeys(config); err != nil {
|
||||
if err := cloudprovider.ValidateVolumeSnapshotterConfigKeys(config); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user