Skip to content

Commit aae8110

Browse files
committed
Run go fix ./...
Signed-off-by: Ilia Choly <ilia.choly@gmail.com>
1 parent 54deaac commit aae8110

52 files changed

Lines changed: 386 additions & 401 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

aes/cipher.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const nonceSize int = 32
3535

3636
type stashKey struct {
3737
additionalData string
38-
plaintext interface{}
38+
plaintext any
3939
}
4040

4141
// Cipher encrypts and decrypts data keys with AES GCM 256
@@ -77,7 +77,7 @@ func parse(value string) (*encryptedValue, error) {
7777
}
7878

7979
// Decrypt takes a sops-format value string and a key and returns the decrypted value and a stash value
80-
func (c Cipher) Decrypt(ciphertext string, key []byte, additionalData string) (plaintext interface{}, err error) {
80+
func (c Cipher) Decrypt(ciphertext string, key []byte, additionalData string) (plaintext any, err error) {
8181
if isEmpty(ciphertext) {
8282
return "", nil
8383
}
@@ -124,7 +124,7 @@ func (c Cipher) Decrypt(ciphertext string, key []byte, additionalData string) (p
124124
return plaintext, err
125125
}
126126

127-
func isEmpty(value interface{}) bool {
127+
func isEmpty(value any) bool {
128128
switch value := value.(type) {
129129
case string:
130130
return value == ""
@@ -138,7 +138,7 @@ func isEmpty(value interface{}) bool {
138138
}
139139

140140
// Encrypt takes one of (string, int, float, bool) and encrypts it with the provided key and additional auth data, returning a sops-format encrypted string.
141-
func (c Cipher) Encrypt(plaintext interface{}, key []byte, additionalData string) (ciphertext string, err error) {
141+
func (c Cipher) Encrypt(plaintext any, key []byte, additionalData string) (ciphertext string, err error) {
142142
if isEmpty(plaintext) {
143143
return "", nil
144144
}

age/keysource.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func formatError(msg string, err error, errs errSet, unusedLocations []string) e
227227
} else if count == 2 {
228228
unusedSuffix = fmt.Sprintf("s '%s' and '%s'", unusedLocations[0], unusedLocations[1])
229229
} else {
230-
unusedSuffix = fmt.Sprintf("s '%s', and '%s'", strings.Join(unusedLocations[:count - 1], "', '"), unusedLocations[count - 1])
230+
unusedSuffix = fmt.Sprintf("s '%s', and '%s'", strings.Join(unusedLocations[:count-1], "', '"), unusedLocations[count-1])
231231
}
232232
unusedSuffix = fmt.Sprintf(". Did not find keys in location%s.", unusedSuffix)
233233
}
@@ -282,8 +282,8 @@ func (key *MasterKey) ToString() string {
282282
}
283283

284284
// ToMap converts the MasterKey to a map for serialization purposes.
285-
func (key *MasterKey) ToMap() map[string]interface{} {
286-
out := make(map[string]interface{})
285+
func (key *MasterKey) ToMap() map[string]any {
286+
out := make(map[string]any)
287287
out["recipient"] = key.Recipient
288288
out["enc"] = key.EncryptedKey
289289
return out

age/keysource_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ func TestMasterKey_ToMap(t *testing.T) {
356356
Recipient: mockRecipient,
357357
EncryptedKey: "some-encrypted-key",
358358
}
359-
assert.Equal(t, map[string]interface{}{
359+
assert.Equal(t, map[string]any{
360360
"recipient": mockRecipient,
361361
"enc": key.EncryptedKey,
362362
}, key.ToMap())

age/tui.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import (
77

88
var testOnlyAgePassword string
99

10-
func printf(format string, v ...interface{}) {
10+
func printf(format string, v ...any) {
1111
log.Printf("age: "+format, v...)
1212
}
1313

14-
func warningf(format string, v ...interface{}) {
14+
func warningf(format string, v ...any) {
1515
log.Printf("age: warning: "+format, v...)
1616
}
1717

@@ -27,7 +27,7 @@ var pluginTerminalUI = &plugin.ClientUI{
2727
if testing.Testing() && testOnlyAgePassword != "" {
2828
return testOnlyAgePassword, nil
2929
}
30-
return pluginTerminalUIImpl.RequestValue(name, message, isSecret);
30+
return pluginTerminalUIImpl.RequestValue(name, message, isSecret)
3131
},
3232
Confirm: func(name, message, yes, no string) (choseYes bool, err error) {
3333
return pluginTerminalUIImpl.Confirm(name, message, yes, no)

audit/audit.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ type config struct {
7070
var auditors []Auditor
7171

7272
// SubmitEvent handles an event for all auditors
73-
func SubmitEvent(event interface{}) {
73+
func SubmitEvent(event any) {
7474
for _, auditor := range auditors {
7575
auditor.Handle(event)
7676
}
@@ -87,7 +87,7 @@ type Auditor interface {
8787
// Handle() takes an audit event and attempts to persists it;
8888
// how it is persisted and how errors are handled is up to the
8989
// implementation of this interface.
90-
Handle(event interface{})
90+
Handle(event any)
9191
}
9292

9393
// DecryptEvent contains fields relevant to a decryption event
@@ -133,7 +133,7 @@ func NewPostgresAuditor(connStr string) (*PostgresAuditor, error) {
133133

134134
// Handle persists the audit event by writing a row to the
135135
// 'audit_event' postgres table
136-
func (p *PostgresAuditor) Handle(event interface{}) {
136+
func (p *PostgresAuditor) Handle(event any) {
137137
u, err := user.Current()
138138
if err != nil {
139139
log.Fatalf("Error getting current user for auditing: %s", err)

azkv/keysource.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func MasterKeysFromURLs(urls string) ([]*MasterKey, error) {
119119
if urls == "" {
120120
return keys, nil
121121
}
122-
for _, s := range strings.Split(urls, ",") {
122+
for s := range strings.SplitSeq(urls, ",") {
123123
k, err := NewMasterKeyFromURL(s)
124124
if err != nil {
125125
return nil, err
@@ -171,7 +171,7 @@ func (key *MasterKey) Encrypt(dataKey []byte) error {
171171
}
172172

173173
func (key *MasterKey) ensureKeyHasVersion(ctx context.Context) error {
174-
if (key.Version != "") {
174+
if key.Version != "" {
175175
// Nothing to do
176176
return nil
177177
}
@@ -301,8 +301,8 @@ func (key *MasterKey) ToString() string {
301301
}
302302

303303
// ToMap converts the MasterKey to a map for serialization purposes.
304-
func (key MasterKey) ToMap() map[string]interface{} {
305-
out := make(map[string]interface{})
304+
func (key MasterKey) ToMap() map[string]any {
305+
out := make(map[string]any)
306306
out["vaultUrl"] = key.VaultURL
307307
out["key"] = key.Name
308308
out["version"] = key.Version

azkv/keysource_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func TestMasterKey_ToMap(t *testing.T) {
201201
Version: "1",
202202
EncryptedKey: "this is encrypted",
203203
}
204-
assert.Equal(t, map[string]interface{}{
204+
assert.Equal(t, map[string]any{
205205
"vaultUrl": key.VaultURL,
206206
"key": key.Name,
207207
"version": key.Version,

cmd/sops/common/common.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func LoadEncryptedFile(loader sops.EncryptedFileLoader, inputPath string) (*sops
162162

163163
// NewExitError returns a cli.ExitError given an error (wrapped in a generic interface{})
164164
// and an exit code to represent the failure
165-
func NewExitError(i interface{}, exitCode int) *cli.ExitError {
165+
func NewExitError(i any, exitCode int) *cli.ExitError {
166166
if userErr, ok := i.(sops.UserError); ok {
167167
return NewExitError(userErr.UserError(), exitCode)
168168
}
@@ -365,7 +365,7 @@ func RecoverDataKeyFromBuggyKMS(opts GenericDecryptOpts, tree *sops.Tree) []byte
365365

366366
keyToEdit := *originalKey
367367

368-
encCtxVals := map[string]interface{}{}
368+
encCtxVals := map[string]any{}
369369
for _, v := range keyToEdit.EncryptionContext {
370370
encCtxVals[*v] = ""
371371
}
@@ -406,13 +406,6 @@ type Diff struct {
406406
Removed []keys.MasterKey
407407
}
408408

409-
func max(a, b int) int {
410-
if a > b {
411-
return a
412-
}
413-
return b
414-
}
415-
416409
// DiffKeyGroups returns the list of diffs found in two sops.keyGroup slices
417410
func DiffKeyGroups(ours, theirs []sops.KeyGroup) []Diff {
418411
var diffs []Diff

cmd/sops/decrypt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type decryptOpts struct {
2121
InputPath string
2222
ReadFromStdin bool
2323
IgnoreMAC bool
24-
Extract []interface{}
24+
Extract []any
2525
KeyServices []keyservice.KeyServiceClient
2626
DecryptionOrder []string
2727
}
@@ -72,7 +72,7 @@ func decrypt(opts decryptOpts) (decryptedFile []byte, err error) {
7272
return decryptedFile, err
7373
}
7474

75-
func extract(tree *sops.Tree, path []interface{}, outputStore sops.Store) (output []byte, err error) {
75+
func extract(tree *sops.Tree, path []any, outputStore sops.Store) (output []byte, err error) {
7676
v, err := tree.Branches[0].Truncate(path)
7777
if err != nil {
7878
return nil, fmt.Errorf("error truncating tree: %s", err)

cmd/sops/main.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ func main() {
869869
return toExitError(err)
870870
}
871871

872-
var extract []interface{}
872+
var extract []any
873873
extract, err = parseTreePath(c.String("extract"))
874874
if err != nil {
875875
return common.NewExitError(fmt.Errorf("error parsing --extract path: %s", err), codes.InvalidTreePathFormat)
@@ -1988,7 +1988,7 @@ func main() {
19881988
}
19891989

19901990
if isDecryptMode {
1991-
var extract []interface{}
1991+
var extract []any
19921992
extract, err = parseTreePath(c.String("extract"))
19931993
if err != nil {
19941994
return common.NewExitError(fmt.Errorf("error parsing --extract path: %s", err), codes.InvalidTreePathFormat)
@@ -2019,8 +2019,8 @@ func main() {
20192019
}
20202020

20212021
if isSetMode {
2022-
var path []interface{}
2023-
var value interface{}
2022+
var path []any
2023+
var value any
20242024
path, value, err = extractSetArguments(c.String("set"))
20252025
if err != nil {
20262026
return toExitError(err)
@@ -2398,10 +2398,10 @@ func outputStore(context *cli.Context, path string) (common.Store, error) {
23982398
return common.DefaultStoreForPathOrFormat(storesConf, path, context.String("output-type")), nil
23992399
}
24002400

2401-
func parseTreePath(arg string) ([]interface{}, error) {
2402-
var path []interface{}
2403-
components := strings.Split(arg, "[")
2404-
for _, component := range components {
2401+
func parseTreePath(arg string) ([]any, error) {
2402+
var path []any
2403+
components := strings.SplitSeq(arg, "[")
2404+
for component := range components {
24052405
if component == "" {
24062406
continue
24072407
}
@@ -2554,8 +2554,8 @@ func shamirThreshold(c *cli.Context, file string, optionalConfig *config.Config)
25542554
return conf.ShamirThreshold, nil
25552555
}
25562556

2557-
func jsonValueToTreeInsertableValue(jsonValue string) (interface{}, error) {
2558-
var valueToInsert interface{}
2557+
func jsonValueToTreeInsertableValue(jsonValue string) (any, error) {
2558+
var valueToInsert any
25592559
err := encodingjson.Unmarshal([]byte(jsonValue), &valueToInsert)
25602560
if err != nil {
25612561
return nil, common.NewExitError("Value for --set is not valid JSON", codes.ErrorInvalidSetFormat)
@@ -2581,7 +2581,7 @@ func jsonValueToTreeInsertableValue(jsonValue string) (interface{}, error) {
25812581
return values[0], nil
25822582
}
25832583

2584-
func extractSetArguments(set string) (path []interface{}, valueToInsert interface{}, err error) {
2584+
func extractSetArguments(set string) (path []any, valueToInsert any, err error) {
25852585
// Set is a string with the format "python-dict-index json-value"
25862586
// Since python-dict-index has to end with ], we split at "] " to get the two parts
25872587
pathValuePair := strings.SplitAfterN(set, "] ", 2)

0 commit comments

Comments
 (0)