Skip to content

Commit 6814190

Browse files
committed
renaming
Signed-off-by: Roman Dmytrenko <rdmytrenko@gmail.com>
1 parent 5642bcd commit 6814190

File tree

7 files changed

+82
-81
lines changed

7 files changed

+82
-81
lines changed

config/flipt.schema.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,8 @@
778778
},
779779
"fetchPolicy": {
780780
"type": "string",
781-
"enum": ["required", "optional"]
781+
"enum": ["strict", "lenient"],
782+
"default": "strict"
782783
},
783784
"backend": {
784785
"type": [

internal/config/config_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ func TestLoad(t *testing.T) {
459459
Type: MemoryStorageBackendType,
460460
},
461461
Remote: "https://github.com/flipt-io/flipt.git",
462-
RemoteStartupFetchPolicy: "required",
462+
FetchPolicy: "strict",
463463
Branch: "main",
464464
PollInterval: 5 * time.Second,
465465
Credentials: "git",
@@ -578,10 +578,10 @@ func TestLoad(t *testing.T) {
578578
Backend: StorageBackendConfig{
579579
Type: MemoryStorageBackendType,
580580
},
581-
Remote: "git@github.com:foo/bar.git",
582-
RemoteStartupFetchPolicy: "required",
583-
Branch: "main",
584-
PollInterval: 30 * time.Second,
581+
Remote: "git@github.com:foo/bar.git",
582+
FetchPolicy: "strict",
583+
Branch: "main",
584+
PollInterval: 30 * time.Second,
585585
},
586586
}
587587
return cfg
@@ -598,10 +598,10 @@ func TestLoad(t *testing.T) {
598598
Type: LocalStorageBackendType,
599599
Path: "/path/to/gitdir",
600600
},
601-
Remote: "git@github.com:foo/bar.git",
602-
RemoteStartupFetchPolicy: "optional",
603-
Branch: "main",
604-
PollInterval: 30 * time.Second,
601+
Remote: "git@github.com:foo/bar.git",
602+
FetchPolicy: "lenient",
603+
Branch: "main",
604+
PollInterval: 30 * time.Second,
605605
},
606606
}
607607
return cfg
@@ -637,11 +637,11 @@ func TestLoad(t *testing.T) {
637637
Backend: StorageBackendConfig{
638638
Type: MemoryStorageBackendType,
639639
},
640-
Remote: "git@github.com:foo/bar.git",
641-
RemoteStartupFetchPolicy: "required",
642-
Branch: "main",
643-
PollInterval: 30 * time.Second,
644-
Credentials: "git",
640+
Remote: "git@github.com:foo/bar.git",
641+
FetchPolicy: "strict",
642+
Branch: "main",
643+
PollInterval: 30 * time.Second,
644+
Credentials: "git",
645645
},
646646
}
647647
cfg.Credentials = CredentialsConfig{
@@ -892,10 +892,10 @@ func TestLoad(t *testing.T) {
892892
Backend: StorageBackendConfig{
893893
Type: MemoryStorageBackendType,
894894
},
895-
Remote: "git@github.com:foo/bar.git",
896-
RemoteStartupFetchPolicy: "required",
897-
Branch: "main",
898-
PollInterval: 30 * time.Second,
895+
Remote: "git@github.com:foo/bar.git",
896+
FetchPolicy: "strict",
897+
Branch: "main",
898+
PollInterval: 30 * time.Second,
899899
Signature: SignatureConfig{
900900
Name: "Flipt Bot",
901901
Email: "bot@flipt.io",

internal/config/storage.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ func (s *StoragesConfig) setDefaults(v *viper.Viper) error {
6161
setDefault("poll_interval", "30s")
6262
}
6363

64-
if getString("remote") != "" && getString("remote_startup_fetch_policy") == "" {
65-
setDefault("remote_startup_fetch_policy", RemoteStartupFetchPolicyRequired)
64+
if getString("remote") != "" && getString("fetch_policy") == "" {
65+
setDefault("fetch_policy", FetchPolicyStrict)
6666
}
6767
}
6868

@@ -84,23 +84,23 @@ type StorageBackendConfig struct {
8484
type FetchPolicy string
8585

8686
const (
87-
RemoteStartupFetchPolicyRequired = RemoteStartupFetchPolicy("required")
88-
RemoteStartupFetchPolicyOptional = RemoteStartupFetchPolicy("optional")
87+
FetchPolicyStrict = FetchPolicy("strict")
88+
FetchPolicyLenient = FetchPolicy("lenient")
8989
)
9090

9191
// StorageConfig contains fields which will configure the type of backend in which Flipt will serve
9292
// flag state.
9393
type StorageConfig struct {
94-
Remote string `json:"remote,omitempty" mapstructure:"remote" yaml:"remote,omitempty"`
95-
RemoteStartupFetchPolicy RemoteStartupFetchPolicy `json:"remote_startup_fetch_policy,omitempty" mapstructure:"remote_startup_fetch_policy" yaml:"remote_startup_fetch_policy,omitempty"`
96-
Backend StorageBackendConfig `json:"backend,omitempty" mapstructure:"backend" yaml:"backend,omitempty"`
97-
Branch string `json:"branch,omitempty" mapstructure:"branch" yaml:"branch,omitempty"`
98-
CaCertBytes string `json:"-" mapstructure:"ca_cert_bytes" yaml:"-"`
99-
CaCertPath string `json:"-" mapstructure:"ca_cert_path" yaml:"-"`
100-
PollInterval time.Duration `json:"pollInterval,omitempty" mapstructure:"poll_interval" yaml:"poll_interval,omitempty"`
101-
InsecureSkipTLS bool `json:"-" mapstructure:"insecure_skip_tls" yaml:"-"`
102-
Credentials string `json:"-" mapstructure:"credentials" yaml:"-"`
103-
Signature SignatureConfig `json:"signature,omitempty" mapstructure:"signature,omitempty" yaml:"signature,omitempty"`
94+
Remote string `json:"remote,omitempty" mapstructure:"remote" yaml:"remote,omitempty"`
95+
FetchPolicy FetchPolicy `json:"fetch_policy,omitempty" mapstructure:"fetch_policy" yaml:"fetch_policy,omitempty"`
96+
Backend StorageBackendConfig `json:"backend,omitempty" mapstructure:"backend" yaml:"backend,omitempty"`
97+
Branch string `json:"branch,omitempty" mapstructure:"branch" yaml:"branch,omitempty"`
98+
CaCertBytes string `json:"-" mapstructure:"ca_cert_bytes" yaml:"-"`
99+
CaCertPath string `json:"-" mapstructure:"ca_cert_path" yaml:"-"`
100+
PollInterval time.Duration `json:"pollInterval,omitempty" mapstructure:"poll_interval" yaml:"poll_interval,omitempty"`
101+
InsecureSkipTLS bool `json:"-" mapstructure:"insecure_skip_tls" yaml:"-"`
102+
Credentials string `json:"-" mapstructure:"credentials" yaml:"-"`
103+
Signature SignatureConfig `json:"signature,omitempty" mapstructure:"signature,omitempty" yaml:"signature,omitempty"`
104104
}
105105

106106
func (c *StorageConfig) validate() error {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
storage:
22
default:
33
remote: "git@github.com:foo/bar.git"
4-
remote_startup_fetch_policy: optional
4+
fetch_policy: lenient
55
backend:
66
type: "local"
77
path: "/path/to/gitdir"

internal/storage/environments/environments.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ func (rm *RepositoryManager) GetOrCreate(ctx context.Context, envConf *config.En
147147
zap.String("key_id", storage.Signature.KeyID))
148148
}
149149
}
150-
if storage.RemoteStartupFetchPolicy == config.RemoteStartupFetchPolicyOptional {
151-
opts = append(opts, storagegit.WithOptionalRemoteStartupFetchPolicy())
150+
if storage.FetchPolicy == config.FetchPolicyLenient {
151+
opts = append(opts, storagegit.WithLenientFetchPolicy())
152152
}
153153

154154
newRepo, err := storagegit.NewRepository(ctx, logger, opts...)
@@ -516,7 +516,7 @@ func NewStore(ctx context.Context, logger *zap.Logger, cfg *config.Config, secre
516516
for _, repo := range repoManager.repos {
517517
if err := repo.Fetch(ctx); err != nil {
518518
switch {
519-
case repo.IsRemoteStartupFetchOptional() && repo.IsConnectionRefused(err):
519+
case repo.HasLenientFetchPolicy() && repo.IsConnectionRefused(err):
520520
continue
521521
case errors.Is(err, transport.ErrEmptyRemoteRepository) || errors.Is(err, git.ErrRemoteRefNotFound):
522522
continue

internal/storage/git/repository.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,20 @@ type Repository struct {
3434

3535
logger *zap.Logger
3636

37-
mu sync.RWMutex
38-
remote *config.RemoteConfig
39-
optionalRemoteStartupFetch bool
40-
defaultBranch string
41-
auth transport.AuthMethod
42-
insecureSkipTLS bool
43-
caBundle []byte
44-
localPath string
45-
readme []byte
46-
sigName string
47-
sigEmail string
48-
signer signing.Signer
49-
maxOpenDescriptors int
50-
isNormalRepo bool // true if opened with PlainOpen, false if bare repository
37+
mu sync.RWMutex
38+
remote *config.RemoteConfig
39+
lenientFetchPolicyEnabled bool
40+
defaultBranch string
41+
auth transport.AuthMethod
42+
insecureSkipTLS bool
43+
caBundle []byte
44+
localPath string
45+
readme []byte
46+
sigName string
47+
sigEmail string
48+
signer signing.Signer
49+
maxOpenDescriptors int
50+
isNormalRepo bool // true if opened with PlainOpen, false if bare repository
5151

5252
subs []Subscriber
5353

@@ -202,8 +202,8 @@ func newRepository(ctx context.Context, logger *zap.Logger, opts ...containers.O
202202
if err := r.Fetch(ctx); err != nil {
203203
fetchErr := fmt.Errorf("performing initial fetch: %w", err)
204204
switch {
205-
case r.optionalRemoteStartupFetch && r.IsConnectionRefused(err):
206-
// if optional, we check if the error is connection refused
205+
case r.HasLenientFetchPolicy() && r.IsConnectionRefused(err):
206+
// if lenient, we check if the error is connection refused
207207
// and there is non-empty repo and flags could be evaluated
208208
objs, rerr := r.CommitObjects()
209209
if rerr != nil {
@@ -317,9 +317,9 @@ func (r *Repository) IsConnectionRefused(err error) bool {
317317
errors.Is(err, syscall.ENETUNREACH) || errors.Is(err, syscall.EHOSTDOWN)
318318
}
319319

320-
// IsRemoteStartupFetchOptional returns true if the startup fetch is optional.
321-
func (r *Repository) IsRemoteStartupFetchOptional() bool {
322-
return r.optionalRemoteStartupFetch
320+
// HasLenientFetchPolicy returns true if the fetch policy set to lenient.
321+
func (r *Repository) HasLenientFetchPolicy() bool {
322+
return r.lenientFetchPolicyEnabled
323323
}
324324

325325
// Fetch does a fetch for the requested head names on a configured remote.
@@ -856,10 +856,10 @@ func WithMaxOpenDescriptors(n int) containers.Option[Repository] {
856856
}
857857
}
858858

859-
// WithOptionalRemoteStartupFetchPolicy sets the optional remote startup fetch policy.
860-
func WithOptionalRemoteStartupFetchPolicy() containers.Option[Repository] {
859+
// WithLenientFetchPolicy sets the lenient fetch policy which allows skip startup git fetch.
860+
func WithLenientFetchPolicy() containers.Option[Repository] {
861861
return func(r *Repository) {
862-
r.optionalRemoteStartupFetch = true
862+
r.lenientFetchPolicyEnabled = true
863863
}
864864
}
865865

internal/storage/git/repository_test.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -301,32 +301,32 @@ func TestRepositoryWithCustomBranch(t *testing.T) {
301301
assert.Equal(t, "develop", repo.defaultBranch, "should use custom default branch")
302302
}
303303

304-
func TestRemoteStartupPolicy_Required(t *testing.T) {
304+
func TestFetchPolicy_Strict(t *testing.T) {
305305
tempDir := t.TempDir()
306306
logger := zap.NewNop()
307307

308-
// Create a repository with required fetch policy (default)
308+
// Create a repository with strict fetch policy (default)
309309
repo, _, err := newRepository(t.Context(), logger,
310310
WithFilesystemStorage(tempDir))
311311
require.NoError(t, err)
312312
require.NotNil(t, repo)
313313

314-
assert.False(t, repo.optionalRemoteStartupFetch, "should set fetch policy to required")
314+
assert.False(t, repo.lenientFetchPolicyEnabled, "should set fetch policy to strict")
315315
}
316316

317-
func TestRemoteStartupPolicy_Optional(t *testing.T) {
317+
func TestFetchPolicy_Lenient(t *testing.T) {
318318
tempDir := t.TempDir()
319319
logger := zap.NewNop()
320320

321-
// Create a repository with optional fetch policy
321+
// Create a repository with lenient fetch policy
322322
repo, _, err := newRepository(t.Context(), logger,
323323
WithFilesystemStorage(tempDir),
324-
WithOptionalRemoteStartupFetchPolicy(),
324+
WithLenientFetchPolicy(),
325325
)
326326
require.NoError(t, err)
327327
require.NotNil(t, repo)
328328

329-
assert.True(t, repo.optionalRemoteStartupFetch, "should set fetch policy to optional")
329+
assert.True(t, repo.lenientFetchPolicyEnabled, "should set fetch policy to lenient")
330330
}
331331

332332
func TestIsConnectionRefused(t *testing.T) {
@@ -391,19 +391,19 @@ func TestFetch_NoRemote(t *testing.T) {
391391
assert.NoError(t, err, "fetch without remote should succeed silently")
392392
}
393393

394-
func TestFetch_RequiredPolicy_WithConnectionRefused(t *testing.T) {
394+
func TestFetch_StrictPolicy_WithConnectionRefused(t *testing.T) {
395395
tempDir := t.TempDir()
396396
logger := zap.NewNop()
397397

398-
// Create repository with required fetch policy and invalid remote
398+
// Create repository with strict fetch policy and invalid remote
399399
_, _, err := newRepository(t.Context(), logger,
400400
WithFilesystemStorage(tempDir),
401401
WithRemote("origin", "http://localhost:1/invalid-repo.git"),
402402
)
403403
require.Error(t, err)
404404
}
405405

406-
func TestFetch_OptionalPolicy_WithConnectionRefusedAndCommits(t *testing.T) {
406+
func TestFetch_LenientPolicy_WithConnectionRefusedAndCommits(t *testing.T) {
407407
tempDir := t.TempDir()
408408
logger := zap.NewNop()
409409

@@ -430,50 +430,50 @@ func TestFetch_OptionalPolicy_WithConnectionRefusedAndCommits(t *testing.T) {
430430
})
431431
require.NoError(t, err)
432432

433-
// Now create our Repository wrapper with optional policy and invalid remote
433+
// Now create our Repository wrapper with lenient policy and invalid remote
434434
repo, _, err := newRepository(t.Context(), logger,
435435
WithFilesystemStorage(tempDir),
436436
WithRemote("origin", "http://localhost:1/invalid-repo.git"),
437-
WithOptionalRemoteStartupFetchPolicy())
437+
WithLenientFetchPolicy())
438438
require.NoError(t, err)
439-
assert.True(t, repo.optionalRemoteStartupFetch)
440-
assert.True(t, repo.IsRemoteStartupFetchOptional())
439+
assert.True(t, repo.lenientFetchPolicyEnabled)
440+
assert.True(t, repo.HasLenientFetchPolicy())
441441

442442
err = repo.Fetch(t.Context())
443443
assert.Error(t, err)
444444
}
445445

446-
func TestFetch_OptionalPolicy_WithConnectionRefusedAndNoCommits(t *testing.T) {
446+
func TestFetch_LenientPolicy_WithConnectionRefusedAndNoCommits(t *testing.T) {
447447
tempDir := t.TempDir()
448448
logger := zap.NewNop()
449449

450-
// Create repository with optional fetch policy and invalid remote, but no commits
450+
// Create repository with lenient fetch policy and invalid remote, but no commits
451451
repo, _, err := newRepository(t.Context(), logger,
452452
WithFilesystemStorage(tempDir),
453453
WithRemote("origin", "http://localhost:1/invalid-repo.git"),
454-
WithOptionalRemoteStartupFetchPolicy())
454+
WithLenientFetchPolicy())
455455
require.Error(t, err)
456456
assert.Nil(t, repo)
457457
}
458458

459-
func TestFetch_OptionalPolicy_WithNonConnectionError(t *testing.T) {
459+
func TestFetch_LenientPolicy_WithNonConnectionError(t *testing.T) {
460460
tempDir := t.TempDir()
461461
logger := zap.NewNop()
462462

463-
// Create repository with optional fetch policy but a different type of error (not connection refused)
463+
// Create repository with lenient fetch policy but a different type of error (not connection refused)
464464
// Using an invalid URL format to trigger a different error
465465
_, _, err := newRepository(t.Context(), logger,
466466
WithFilesystemStorage(tempDir),
467467
WithRemote("origin", "invalid://bad-url"),
468-
WithOptionalRemoteStartupFetchPolicy())
468+
WithLenientFetchPolicy())
469469
require.Error(t, err)
470470
}
471471

472-
func TestFetch_DefaultPolicy_BehavesAsRequired(t *testing.T) {
472+
func TestFetch_DefaultPolicy_BehavesAsStrict(t *testing.T) {
473473
tempDir := t.TempDir()
474474
logger := zap.NewNop()
475475

476-
// Create repository without specifying policy (should default to required behavior)
476+
// Create repository without specifying policy (should default to strict behavior)
477477
_, _, err := newRepository(t.Context(), logger,
478478
WithFilesystemStorage(tempDir),
479479
WithRemote("origin", "http://localhost:1/invalid-repo.git"))

0 commit comments

Comments
 (0)