Minor refactor of storage provider stringer (#4228)
<!-- PR description--> One of the setup PRs before introducing local storage support for corso. Changes 1. Export `storage.storageProvider` and rename it to `storage.Provider`. Without the rename, linter errors out with `exported: type name will be used as storage.StorageProvider by other packages, and that stutters; consider calling this Provider` 2. Rerun stringer - `stringer -type=Provider -linecomment` 3. Introduce a new Provider - `FS` for filesystem. This is in line with kopia naming for local/network attached storage. 4. Fix hardcoded string values for storage providers in test code. --- #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No #### Type of change <!--- Please check the type of change your PR introduces: ---> - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [x] 🧹 Tech Debt/Cleanup #### Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * #<issue> #### Test Plan <!-- How will this be tested prior to merging.--> - [x] 💪 Manual - [ ] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
e3bde06457
commit
de062cd5de
@ -144,8 +144,8 @@ func prepM365Test(
|
|||||||
require.NoError(t, err, clues.ToCore(err))
|
require.NoError(t, err, clues.ToCore(err))
|
||||||
|
|
||||||
force := map[string]string{
|
force := map[string]string{
|
||||||
tconfig.TestCfgAccountProvider: "M365",
|
tconfig.TestCfgAccountProvider: account.ProviderM365.String(),
|
||||||
tconfig.TestCfgStorageProvider: "S3",
|
tconfig.TestCfgStorageProvider: storage.ProviderS3.String(),
|
||||||
tconfig.TestCfgPrefix: cfg.Prefix,
|
tconfig.TestCfgPrefix: cfg.Prefix,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import (
|
|||||||
"github.com/alcionai/corso/src/pkg/control"
|
"github.com/alcionai/corso/src/pkg/control"
|
||||||
ctrlRepo "github.com/alcionai/corso/src/pkg/control/repository"
|
ctrlRepo "github.com/alcionai/corso/src/pkg/control/repository"
|
||||||
"github.com/alcionai/corso/src/pkg/repository"
|
"github.com/alcionai/corso/src/pkg/repository"
|
||||||
|
"github.com/alcionai/corso/src/pkg/storage"
|
||||||
storeTD "github.com/alcionai/corso/src/pkg/storage/testdata"
|
storeTD "github.com/alcionai/corso/src/pkg/storage/testdata"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -185,8 +186,8 @@ func (suite *S3E2ESuite) TestConnectS3Cmd() {
|
|||||||
require.NoError(t, err, clues.ToCore(err))
|
require.NoError(t, err, clues.ToCore(err))
|
||||||
|
|
||||||
force := map[string]string{
|
force := map[string]string{
|
||||||
tconfig.TestCfgAccountProvider: "M365",
|
tconfig.TestCfgAccountProvider: account.ProviderM365.String(),
|
||||||
tconfig.TestCfgStorageProvider: "S3",
|
tconfig.TestCfgStorageProvider: storage.ProviderS3.String(),
|
||||||
tconfig.TestCfgPrefix: cfg.Prefix,
|
tconfig.TestCfgPrefix: cfg.Prefix,
|
||||||
}
|
}
|
||||||
vpr, configFP := tconfig.MakeTempTestConfigClone(t, force)
|
vpr, configFP := tconfig.MakeTempTestConfigClone(t, force)
|
||||||
|
|||||||
@ -70,8 +70,8 @@ func (suite *RestoreExchangeE2ESuite) SetupSuite() {
|
|||||||
require.NoError(t, err, clues.ToCore(err))
|
require.NoError(t, err, clues.ToCore(err))
|
||||||
|
|
||||||
force := map[string]string{
|
force := map[string]string{
|
||||||
tconfig.TestCfgAccountProvider: "M365",
|
tconfig.TestCfgAccountProvider: account.ProviderM365.String(),
|
||||||
tconfig.TestCfgStorageProvider: "S3",
|
tconfig.TestCfgStorageProvider: storage.ProviderS3.String(),
|
||||||
tconfig.TestCfgPrefix: cfg.Prefix,
|
tconfig.TestCfgPrefix: cfg.Prefix,
|
||||||
}
|
}
|
||||||
suite.vpr, suite.cfgFP = tconfig.MakeTempTestConfigClone(t, force)
|
suite.vpr, suite.cfgFP = tconfig.MakeTempTestConfigClone(t, force)
|
||||||
|
|||||||
25
src/pkg/storage/providertype_string.go
Normal file
25
src/pkg/storage/providertype_string.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Code generated by "stringer -type=ProviderType -linecomment"; DO NOT EDIT.
|
||||||
|
|
||||||
|
package storage
|
||||||
|
|
||||||
|
import "strconv"
|
||||||
|
|
||||||
|
func _() {
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[ProviderUnknown-0]
|
||||||
|
_ = x[ProviderS3-1]
|
||||||
|
_ = x[ProviderFilesystem-2]
|
||||||
|
}
|
||||||
|
|
||||||
|
const _ProviderType_name = "Unknown ProviderS3Filesystem"
|
||||||
|
|
||||||
|
var _ProviderType_index = [...]uint8{0, 16, 18, 28}
|
||||||
|
|
||||||
|
func (i ProviderType) String() string {
|
||||||
|
if i < 0 || i >= ProviderType(len(_ProviderType_index)-1) {
|
||||||
|
return "ProviderType(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
|
}
|
||||||
|
return _ProviderType_name[_ProviderType_index[i]:_ProviderType_index[i+1]]
|
||||||
|
}
|
||||||
@ -8,12 +8,13 @@ import (
|
|||||||
"github.com/alcionai/corso/src/internal/common"
|
"github.com/alcionai/corso/src/internal/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type storageProvider int
|
type ProviderType int
|
||||||
|
|
||||||
//go:generate stringer -type=storageProvider -linecomment
|
//go:generate stringer -type=ProviderType -linecomment
|
||||||
const (
|
const (
|
||||||
ProviderUnknown storageProvider = 0 // Unknown Provider
|
ProviderUnknown ProviderType = 0 // Unknown Provider
|
||||||
ProviderS3 storageProvider = 1 // S3
|
ProviderS3 ProviderType = 1 // S3
|
||||||
|
ProviderFilesystem ProviderType = 2 // Filesystem
|
||||||
)
|
)
|
||||||
|
|
||||||
// storage parsing errors
|
// storage parsing errors
|
||||||
@ -24,7 +25,7 @@ var (
|
|||||||
// Storage defines a storage provider, along with any configuration
|
// Storage defines a storage provider, along with any configuration
|
||||||
// required to set up or communicate with that provider.
|
// required to set up or communicate with that provider.
|
||||||
type Storage struct {
|
type Storage struct {
|
||||||
Provider storageProvider
|
Provider ProviderType
|
||||||
Config map[string]string
|
Config map[string]string
|
||||||
// TODO: These are AWS S3 specific -> move these out
|
// TODO: These are AWS S3 specific -> move these out
|
||||||
SessionTags map[string]string
|
SessionTags map[string]string
|
||||||
@ -34,7 +35,7 @@ type Storage struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewStorage aggregates all the supplied configurations into a single configuration.
|
// NewStorage aggregates all the supplied configurations into a single configuration.
|
||||||
func NewStorage(p storageProvider, cfgs ...common.StringConfigurer) (Storage, error) {
|
func NewStorage(p ProviderType, cfgs ...common.StringConfigurer) (Storage, error) {
|
||||||
cs, err := common.UnionStringConfigs(cfgs...)
|
cs, err := common.UnionStringConfigs(cfgs...)
|
||||||
|
|
||||||
return Storage{
|
return Storage{
|
||||||
@ -46,7 +47,7 @@ func NewStorage(p storageProvider, cfgs ...common.StringConfigurer) (Storage, er
|
|||||||
// NewStorageUsingRole supports specifying an AWS IAM role the storage provider
|
// NewStorageUsingRole supports specifying an AWS IAM role the storage provider
|
||||||
// should assume.
|
// should assume.
|
||||||
func NewStorageUsingRole(
|
func NewStorageUsingRole(
|
||||||
p storageProvider,
|
p ProviderType,
|
||||||
roleARN string,
|
roleARN string,
|
||||||
sessionName string,
|
sessionName string,
|
||||||
sessionTags map[string]string,
|
sessionTags map[string]string,
|
||||||
|
|||||||
@ -28,7 +28,7 @@ func TestStorageSuite(t *testing.T) {
|
|||||||
func (suite *StorageSuite) TestNewStorage() {
|
func (suite *StorageSuite) TestNewStorage() {
|
||||||
table := []struct {
|
table := []struct {
|
||||||
name string
|
name string
|
||||||
p storageProvider
|
p ProviderType
|
||||||
c testConfig
|
c testConfig
|
||||||
errCheck assert.ErrorAssertionFunc
|
errCheck assert.ErrorAssertionFunc
|
||||||
}{
|
}{
|
||||||
|
|||||||
@ -1,24 +0,0 @@
|
|||||||
// Code generated by "stringer -type=storageProvider -linecomment"; DO NOT EDIT.
|
|
||||||
|
|
||||||
package storage
|
|
||||||
|
|
||||||
import "strconv"
|
|
||||||
|
|
||||||
func _() {
|
|
||||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
|
||||||
// Re-run the stringer command to generate them again.
|
|
||||||
var x [1]struct{}
|
|
||||||
_ = x[ProviderUnknown-0]
|
|
||||||
_ = x[ProviderS3-1]
|
|
||||||
}
|
|
||||||
|
|
||||||
const _storageProvider_name = "Unknown ProviderS3"
|
|
||||||
|
|
||||||
var _storageProvider_index = [...]uint8{0, 16, 18}
|
|
||||||
|
|
||||||
func (i storageProvider) String() string {
|
|
||||||
if i < 0 || i >= storageProvider(len(_storageProvider_index)-1) {
|
|
||||||
return "storageProvider(" + strconv.FormatInt(int64(i), 10) + ")"
|
|
||||||
}
|
|
||||||
return _storageProvider_name[_storageProvider_index[i]:_storageProvider_index[i+1]]
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user