Skip to content

Commit 6bb6621

Browse files
committed
Make SingleValueStore extend Store instead of the other way around.
Signed-off-by: Felix Fontein <[email protected]>
1 parent ffc1e26 commit 6bb6621

File tree

6 files changed

+14
-25
lines changed

6 files changed

+14
-25
lines changed

cmd/sops/main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,7 +2090,12 @@ func getEncryptConfig(c *cli.Context, fileName string, inputStore common.Store,
20902090
}
20912091
}
20922092

2093-
if inputStore.IsSingleValueStore() {
2093+
isSingleValueStore := false
2094+
if svs, ok := inputStore.(sops.SingleValueStore); ok {
2095+
isSingleValueStore = svs.IsSingleValueStore()
2096+
}
2097+
2098+
if isSingleValueStore {
20942099
// Warn about settings that potentially disable encryption of the single key.
20952100
if unencryptedSuffix != "" {
20962101
log.Warn(fmt.Sprintf("Using an unencrypted suffix does not make sense with the input store (the %s store produces one key that should always be encrypted) and will be ignored.", inputStore.Name()))
@@ -2142,7 +2147,7 @@ func getEncryptConfig(c *cli.Context, fileName string, inputStore common.Store,
21422147
}
21432148

21442149
// only supply the default UnencryptedSuffix when EncryptedSuffix, EncryptedRegex, and others are not provided
2145-
if cryptRuleCount == 0 && !inputStore.IsSingleValueStore() {
2150+
if cryptRuleCount == 0 && !isSingleValueStore {
21462151
unencryptedSuffix = sops.DefaultUnencryptedSuffix
21472152
}
21482153

sops.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -726,12 +726,6 @@ type CheckEncrypted interface {
726726
HasSopsTopLevelKey(TreeBranch) bool
727727
}
728728

729-
// SingleValueStore is the interface for determining whether a store uses only
730-
// one single key and no comments. This is basically identifying the binary store.
731-
type SingleValueStore interface {
732-
IsSingleValueStore() bool
733-
}
734-
735729
// Store is used to interact with files, both encrypted and unencrypted.
736730
type Store interface {
737731
EncryptedFileLoader
@@ -740,10 +734,16 @@ type Store interface {
740734
PlainFileEmitter
741735
ValueEmitter
742736
CheckEncrypted
743-
SingleValueStore
744737
Name() string
745738
}
746739

740+
// SingleValueStore is the interface for determining whether a store uses only
741+
// one single key and no comments. This is basically identifying the binary store.
742+
type SingleValueStore interface {
743+
Store
744+
IsSingleValueStore() bool
745+
}
746+
747747
// MasterKeyCount returns the number of master keys available
748748
func (m *Metadata) MasterKeyCount() int {
749749
count := 0

stores/dotenv/store.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ func NewStore(c *config.DotenvStoreConfig) *Store {
2323
return &Store{config: *c}
2424
}
2525

26-
func (store *Store) IsSingleValueStore() bool {
27-
return false
28-
}
29-
3026
func (store *Store) Name() string {
3127
return "dotenv"
3228
}

stores/ini/store.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ func NewStore(c *config.INIStoreConfig) *Store {
2121
return &Store{config: c}
2222
}
2323

24-
func (store *Store) IsSingleValueStore() bool {
25-
return false
26-
}
27-
2824
func (store *Store) Name() string {
2925
return "ini"
3026
}

stores/json/store.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ func NewStore(c *config.JSONStoreConfig) *Store {
2222
return &Store{config: *c}
2323
}
2424

25-
func (store *Store) IsSingleValueStore() bool {
26-
return false
27-
}
28-
2925
func (store *Store) Name() string {
3026
return "json"
3127
}

stores/yaml/store.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ func NewStore(c *config.YAMLStoreConfig) *Store {
2424
return &Store{config: *c}
2525
}
2626

27-
func (store *Store) IsSingleValueStore() bool {
28-
return false
29-
}
30-
3127
func (store *Store) Name() string {
3228
return "yaml"
3329
}

0 commit comments

Comments
 (0)