Skip to content

Commit

Permalink
chore(config): rename Git storage to backend for distinction
Browse files Browse the repository at this point in the history
Signed-off-by: George MacRorie <[email protected]>
  • Loading branch information
GeorgeMac committed May 21, 2024
1 parent 6aeff2f commit 17909d0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
26 changes: 13 additions & 13 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,8 @@ func TestLoad(t *testing.T) {
cfg.Storage = StorageConfig{
Type: GitStorageType,
Git: &Git{
Storage: GitStorageConfig{
Type: GitStorageMemory,
Backend: GitBackend{
Type: GotBackendMemory,
},
Repository: "https://github.com/flipt-io/flipt.git",
Ref: "production",
Expand Down Expand Up @@ -820,8 +820,8 @@ func TestLoad(t *testing.T) {
cfg.Storage = StorageConfig{
Type: GitStorageType,
Git: &Git{
Storage: GitStorageConfig{
Type: GitStorageMemory,
Backend: GitBackend{
Type: GotBackendMemory,
},
Ref: "main",
RefType: GitRefTypeStatic,
Expand All @@ -840,8 +840,8 @@ func TestLoad(t *testing.T) {
cfg.Storage = StorageConfig{
Type: GitStorageType,
Git: &Git{
Storage: GitStorageConfig{
Type: GitStorageMemory,
Backend: GitBackend{
Type: GotBackendMemory,
},
Ref: "main",
RefType: GitRefTypeStatic,
Expand All @@ -861,8 +861,8 @@ func TestLoad(t *testing.T) {
cfg.Storage = StorageConfig{
Type: GitStorageType,
Git: &Git{
Storage: GitStorageConfig{
Type: GitStorageMemory,
Backend: GitBackend{
Type: GotBackendMemory,
},
Ref: "main",
RefType: GitRefTypeSemver,
Expand All @@ -876,14 +876,14 @@ func TestLoad(t *testing.T) {
},
{
name: "git config provided with ref_type",
path: "./testdata/storage/git_provided_with_storage_type.yml",
path: "./testdata/storage/git_provided_with_backend_type.yml",
expected: func() *Config {
cfg := Default()
cfg.Storage = StorageConfig{
Type: GitStorageType,
Git: &Git{
Storage: GitStorageConfig{
Type: GitStorageFilesystem,
Backend: GitBackend{
Type: GitBackendFilesystem,
Path: "/path/to/gitdir",
},
Ref: "main",
Expand Down Expand Up @@ -933,8 +933,8 @@ func TestLoad(t *testing.T) {
cfg.Storage = StorageConfig{
Type: GitStorageType,
Git: &Git{
Storage: GitStorageConfig{
Type: GitStorageMemory,
Backend: GitBackend{
Type: GotBackendMemory,
},
Ref: "main",
RefType: GitRefTypeStatic,
Expand Down
34 changes: 17 additions & 17 deletions internal/config/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (c *StorageConfig) setDefaults(v *viper.Viper) error {
case string(LocalStorageType):
v.SetDefault("storage.local.path", ".")
case string(GitStorageType):
v.SetDefault("storage.git.storage.type", "memory")
v.SetDefault("storage.git.backend.type", "memory")
v.SetDefault("storage.git.ref", "main")
v.SetDefault("storage.git.ref_type", "static")
v.SetDefault("storage.git.poll_interval", "30s")
Expand Down Expand Up @@ -164,16 +164,16 @@ const (

// Git contains configuration for referencing a git repository.
type Git struct {
Repository string `json:"repository,omitempty" mapstructure:"repository" yaml:"repository,omitempty"`
Storage GitStorageConfig `json:"storage,omitempty" mapstructure:"storage" yaml:"storage,omitempty"`
Ref string `json:"ref,omitempty" mapstructure:"ref" yaml:"ref,omitempty"`
RefType GitRefType `json:"refType,omitempty" mapstructure:"ref_type" yaml:"ref_type,omitempty"`
Directory string `json:"directory,omitempty" mapstructure:"directory" yaml:"directory,omitempty"`
CaCertBytes string `json:"-" mapstructure:"ca_cert_bytes" yaml:"-"`
CaCertPath string `json:"-" mapstructure:"ca_cert_path" yaml:"-"`
InsecureSkipTLS bool `json:"-" mapstructure:"insecure_skip_tls" yaml:"-"`
PollInterval time.Duration `json:"pollInterval,omitempty" mapstructure:"poll_interval" yaml:"poll_interval,omitempty"`
Authentication Authentication `json:"-" mapstructure:"authentication,omitempty" yaml:"-"`
Repository string `json:"repository,omitempty" mapstructure:"repository" yaml:"repository,omitempty"`
Backend GitBackend `json:"backend,omitempty" mapstructure:"backend" yaml:"backend,omitempty"`
Ref string `json:"ref,omitempty" mapstructure:"ref" yaml:"ref,omitempty"`
RefType GitRefType `json:"refType,omitempty" mapstructure:"ref_type" yaml:"ref_type,omitempty"`
Directory string `json:"directory,omitempty" mapstructure:"directory" yaml:"directory,omitempty"`
CaCertBytes string `json:"-" mapstructure:"ca_cert_bytes" yaml:"-"`
CaCertPath string `json:"-" mapstructure:"ca_cert_path" yaml:"-"`
InsecureSkipTLS bool `json:"-" mapstructure:"insecure_skip_tls" yaml:"-"`
PollInterval time.Duration `json:"pollInterval,omitempty" mapstructure:"poll_interval" yaml:"poll_interval,omitempty"`
Authentication Authentication `json:"-" mapstructure:"authentication,omitempty" yaml:"-"`
}

func (g *Git) validate() error {
Expand All @@ -188,16 +188,16 @@ func (g *Git) validate() error {
return nil
}

type GitStorage string
type GitBackendType string

const (
GitStorageMemory = GitStorage("memory")
GitStorageFilesystem = GitStorage("filesystem")
GotBackendMemory = GitBackendType("memory")
GitBackendFilesystem = GitBackendType("filesystem")
)

type GitStorageConfig struct {
Type GitStorage `json:"type,omitempty" mapstructure:"type" yaml:"type,omitempty"`
Path string `json:"path,omitempty" mapstructure:"path" yaml:"path,omitempty"`
type GitBackend struct {
Type GitBackendType `json:"type,omitempty" mapstructure:"type" yaml:"type,omitempty"`
Path string `json:"path,omitempty" mapstructure:"path" yaml:"path,omitempty"`
}

// Object contains configuration of readonly object storage.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ storage:
type: git
git:
repository: "[email protected]:foo/bar.git"
storage:
backend:
type: "filesystem"
path: "/path/to/gitdir"
8 changes: 4 additions & 4 deletions internal/storage/fs/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ func NewStore(ctx context.Context, logger *zap.Logger, cfg *config.Config) (_ st
opts = append(opts, git.WithSemverResolver())
}

switch storage.Storage.Type {
case config.GitStorageFilesystem:
path := storage.Storage.Path
switch storage.Backend.Type {
case config.GitBackendFilesystem:
path := storage.Backend.Path
if path == "" {
path, err = os.MkdirTemp(os.TempDir(), "flipt-git-*")
if err != nil {
Expand All @@ -58,7 +58,7 @@ func NewStore(ctx context.Context, logger *zap.Logger, cfg *config.Config) (_ st

opts = append(opts, git.WithFilesystemStorage(path))
logger = logger.With(zap.String("git_storage_type", "filesystem"), zap.String("git_storage_path", path))
case config.GitStorageMemory:
case config.GotBackendMemory:
logger = logger.With(zap.String("git_storage_type", "memory"))
}

Expand Down

0 comments on commit 17909d0

Please sign in to comment.