From 1ec065ec3d779964043697f338886af08a56d061 Mon Sep 17 00:00:00 2001 From: Yoni Date: Sun, 5 Mar 2023 22:28:20 +0700 Subject: [PATCH] Use default storage namespace in local settings (#5373) --- pkg/api/controller.go | 6 +++++- pkg/block/local/adapter.go | 5 +++++ pkg/block/namespace.go | 9 +++++---- pkg/config/config.go | 4 ++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/pkg/api/controller.go b/pkg/api/controller.go index 946ec8ca7a5..bc0798ed67e 100644 --- a/pkg/api/controller.go +++ b/pkg/api/controller.go @@ -1280,11 +1280,15 @@ func (c *Controller) GetStorageConfig(w http.ResponseWriter, r *http.Request) { return } info := c.BlockAdapter.GetStorageNamespaceInfo() + defaultNamespacePrefix := swag.String(info.DefaultNamespacePrefix) + if c.Config.Blockstore.DefaultNamespacePrefix != nil { + defaultNamespacePrefix = c.Config.Blockstore.DefaultNamespacePrefix + } response := StorageConfig{ BlockstoreType: c.Config.BlockstoreType(), BlockstoreNamespaceValidityRegex: info.ValidityRegex, BlockstoreNamespaceExample: info.Example, - DefaultNamespacePrefix: swag.String(c.Config.Blockstore.DefaultNamespacePrefix), + DefaultNamespacePrefix: defaultNamespacePrefix, PreSignSupport: info.PreSignSupport, ImportSupport: info.ImportSupport, } diff --git a/pkg/block/local/adapter.go b/pkg/block/local/adapter.go index 18510129104..256c9c118be 100644 --- a/pkg/block/local/adapter.go +++ b/pkg/block/local/adapter.go @@ -28,6 +28,10 @@ type Adapter struct { importEnabled bool } +const ( + DefaultNamespacePrefix = "local:/" +) + var ( ErrPathNotWritable = errors.New("path provided is not writable") ErrInventoryNotSupported = errors.New("inventory feature not implemented for local storage adapter") @@ -480,6 +484,7 @@ func (l *Adapter) BlockstoreType() string { func (l *Adapter) GetStorageNamespaceInfo() block.StorageNamespaceInfo { info := block.DefaultStorageNamespaceInfo(block.BlockstoreTypeLocal) info.PreSignSupport = false + info.DefaultNamespacePrefix = DefaultNamespacePrefix info.ImportSupport = l.importEnabled return info } diff --git a/pkg/block/namespace.go b/pkg/block/namespace.go index 47af021507d..930738b1e5e 100644 --- a/pkg/block/namespace.go +++ b/pkg/block/namespace.go @@ -48,10 +48,11 @@ func (s StorageType) Scheme() string { } type StorageNamespaceInfo struct { - ValidityRegex string // regex pattern that could be used to validate the namespace - Example string // example of a valid namespace - PreSignSupport bool - ImportSupport bool + ValidityRegex string // regex pattern that could be used to validate the namespace + Example string // example of a valid namespace + DefaultNamespacePrefix string // when a repo is created from the UI, suggest a default storage namespace under this prefix + PreSignSupport bool + ImportSupport bool } type QualifiedKey struct { diff --git a/pkg/config/config.go b/pkg/config/config.go index 530bd80869d..2dccc204f95 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -178,8 +178,8 @@ type Config struct { } `mapstructure:"ui_config"` } Blockstore struct { - Type string `mapstructure:"type" validate:"required"` - DefaultNamespacePrefix string `mapstructure:"default_namespace_prefix"` + Type string `mapstructure:"type" validate:"required"` + DefaultNamespacePrefix *string `mapstructure:"default_namespace_prefix"` Local *struct { Path string `mapstructure:"path"` ImportEnabled bool `mapstructure:"import_enabled"`