From 72cebfd8a13ff59dd72712b711f08787c9cc6b0a Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Fri, 28 Mar 2025 20:10:11 +0100 Subject: [PATCH] Run 'gofmt -w' on all .go files. Signed-off-by: Felix Fontein --- cmd/sops/main.go | 6 +-- cmd/sops/subcommand/exec/exec_unix.go | 1 + config/config_test.go | 30 ++++++------ publish/vault.go | 2 +- shamir/shamir.go | 22 ++++----- sops_test.go | 66 +++++++++++++-------------- stores/flatten.go | 20 ++++---- 7 files changed, 72 insertions(+), 75 deletions(-) diff --git a/cmd/sops/main.go b/cmd/sops/main.go index b9a26b15c..c82d8cc96 100644 --- a/cmd/sops/main.go +++ b/cmd/sops/main.go @@ -462,7 +462,7 @@ func main() { Name: "filestatus", Usage: "check the status of the file, returning encryption status", ArgsUsage: `file`, - Flags: []cli.Flag{ + Flags: []cli.Flag{ cli.StringFlag{ Name: "input-type", Usage: "currently ini, json, yaml, dotenv and binary are supported. If not set, sops will use the file's extension to determine the type", @@ -1718,8 +1718,8 @@ func main() { Usage: "set the encrypted comment suffix. When specified, only keys that have comment matching the regex will be encrypted.", }, cli.StringFlag{ - Name: "config", - Usage: "path to sops' config file. If set, sops will not search for the config file recursively.", + Name: "config", + Usage: "path to sops' config file. If set, sops will not search for the config file recursively.", EnvVar: "SOPS_CONFIG", }, cli.StringFlag{ diff --git a/cmd/sops/subcommand/exec/exec_unix.go b/cmd/sops/subcommand/exec/exec_unix.go index a7f63ce8d..bfc268d86 100644 --- a/cmd/sops/subcommand/exec/exec_unix.go +++ b/cmd/sops/subcommand/exec/exec_unix.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package exec diff --git a/config/config_test.go b/config/config_test.go index 9ac63645a..cb8340a7f 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -537,29 +537,29 @@ func TestLoadConfigFileWithMerge(t *testing.T) { "hc_vault: https://foo.vault:8200/v1/foo/keys/foo-key", }, ids(conf.KeyGroups[0])) assert.Equal(t, []string{ - "pgp: foo", // key01 - "kms: foo||foo", //key02 + "pgp: foo", // key01 + "kms: foo||foo", //key02 "kms: foo+123|baz:bam|bar", //key03 - "gcp_kms: foo", //key04 + "gcp_kms: foo", //key04 "azure_kv: https://foo.vault.azure.net/keys/foo-key/fooversion", //key05 - "hc_vault: https://bar.vault:8200/v1/bar/keys/bar-key", //key06 - "pgp: bar", //key07 + "hc_vault: https://bar.vault:8200/v1/bar/keys/bar-key", //key06 + "pgp: bar", //key07 "kms: bar||bar", //key08 - "gcp_kms: bar", //key09 - "gcp_kms: baz", //key10 + "gcp_kms: bar", //key09 + "gcp_kms: baz", //key10 "azure_kv: https://bar.vault.azure.net/keys/bar-key/barversion", //key11 - "hc_vault: https://baz.vault:8200/v1/baz/keys/baz-key", //key12 - "pgp: baz", //key13 + "hc_vault: https://baz.vault:8200/v1/baz/keys/baz-key", //key12 + "pgp: baz", //key13 "kms: baz||baz", //key14 "hc_vault: https://foo.vault:8200/v1/foo/keys/foo-key", //key15 - "pgp: qux", //key16 - "kms: qux||qux", //key17 - "kms: baz||bar", //key18 - "kms: baz+123", //key19 - "gcp_kms: qux", //key20 + "pgp: qux", //key16 + "kms: qux||qux", //key17 + "kms: baz||bar", //key18 + "kms: baz+123", //key19 + "gcp_kms: qux", //key20 "gcp_kms: fnord", //key21 "azure_kv: https://baz.vault.azure.net/keys/baz-key/bazversion", //key22 - "hc_vault: https://qux.vault:8200/v1/qux/keys/qux-key", //key23 + "hc_vault: https://qux.vault:8200/v1/qux/keys/qux-key", //key23 "kms: fnord||fnord", //key24 "hc_vault: https://fnord.vault:8200/v1/fnord/keys/fnord-key", //key25 }, ids(conf.KeyGroups[1])) diff --git a/publish/vault.go b/publish/vault.go index 6f857cd01..4167ec808 100644 --- a/publish/vault.go +++ b/publish/vault.go @@ -4,9 +4,9 @@ import ( "fmt" "strings" + "github.com/getsops/sops/v3/logging" "github.com/google/go-cmp/cmp" vault "github.com/hashicorp/vault/api" - "github.com/getsops/sops/v3/logging" "github.com/sirupsen/logrus" ) diff --git a/shamir/shamir.go b/shamir/shamir.go index 150063131..e9b9e59f6 100644 --- a/shamir/shamir.go +++ b/shamir/shamir.go @@ -123,17 +123,17 @@ func inverse(a uint8) uint8 { // (See also https://github.com/openbao/openbao/commit/a209a052024b70bc563d9674cde21a20b5106570) // In the comments, we use ^ to denote raising to the power: - b := mult(a, a) // b is now a^2 - c := mult(a, b) // c is now a^3 - b = mult(c, c) // b is now a^6 - b = mult(b, b) // b is now a^12 - c = mult(b, c) // c is now a^15 - b = mult(b, b) // b is now a^24 - b = mult(b, b) // b is now a^48 - b = mult(b, c) // b is now a^63 - b = mult(b, b) // b is now a^126 - b = mult(a, b) // b is now a^127 - return mult(b, b) // result is a^254 + b := mult(a, a) // b is now a^2 + c := mult(a, b) // c is now a^3 + b = mult(c, c) // b is now a^6 + b = mult(b, b) // b is now a^12 + c = mult(b, c) // c is now a^15 + b = mult(b, b) // b is now a^24 + b = mult(b, b) // b is now a^48 + b = mult(b, c) // b is now a^63 + b = mult(b, b) // b is now a^126 + b = mult(a, b) // b is now a^127 + return mult(b, b) // result is a^254 } // mult multiplies two numbers in GF(2^8) diff --git a/sops_test.go b/sops_test.go index 0115024a0..e10634eda 100644 --- a/sops_test.go +++ b/sops_test.go @@ -919,7 +919,7 @@ func TestTruncateTreeNotArray(t *testing.T) { func TestTruncateTreeArrayOutOfBounds(t *testing.T) { tree := TreeBranch{ TreeItem{ - Key: "foo", + Key: "foo", Value: []interface{}{ "one", "two", @@ -1198,11 +1198,11 @@ func TestSetArrayNonLeaf(t *testing.T) { func TestUnsetKeyRootLeaf(t *testing.T) { branch := TreeBranch{ TreeItem{ - Key: "foo", + Key: "foo", Value: "foo", }, TreeItem{ - Key: "foofoo", + Key: "foofoo", Value: "foofoo", }, } @@ -1210,7 +1210,7 @@ func TestUnsetKeyRootLeaf(t *testing.T) { assert.NoError(t, err) assert.Equal(t, TreeBranch{ TreeItem{ - Key: "foo", + Key: "foo", Value: "foo", }, }, unset) @@ -1222,11 +1222,11 @@ func TestUnsetKeyBranchLeaf(t *testing.T) { Key: "foo", Value: TreeBranch{ TreeItem{ - Key: "bar", + Key: "bar", Value: "bar", }, TreeItem{ - Key: "barbar", + Key: "barbar", Value: "barbar", }, }, @@ -1239,7 +1239,7 @@ func TestUnsetKeyBranchLeaf(t *testing.T) { Key: "foo", Value: TreeBranch{ TreeItem{ - Key: "bar", + Key: "bar", Value: "bar", }, }, @@ -1250,14 +1250,14 @@ func TestUnsetKeyBranchLeaf(t *testing.T) { func TestUnsetKeyBranch(t *testing.T) { branch := TreeBranch{ TreeItem{ - Key: "foo", + Key: "foo", Value: "foo", }, TreeItem{ Key: "foofoo", Value: TreeBranch{ TreeItem{ - Key: "bar", + Key: "bar", Value: "bar", }, }, @@ -1267,7 +1267,7 @@ func TestUnsetKeyBranch(t *testing.T) { assert.NoError(t, err) assert.Equal(t, TreeBranch{ TreeItem{ - Key: "foo", + Key: "foo", Value: "foo", }, }, unset) @@ -1276,14 +1276,13 @@ func TestUnsetKeyBranch(t *testing.T) { func TestUnsetKeyRootLastLeaf(t *testing.T) { branch := TreeBranch{ TreeItem{ - Key: "foo", + Key: "foo", Value: "foo", }, } unset, err := branch.Unset([]interface{}{"foo"}) assert.NoError(t, err) - assert.Equal(t, TreeBranch{ - }, unset) + assert.Equal(t, TreeBranch{}, unset) } func TestUnsetKeyBranchLastLeaf(t *testing.T) { @@ -1292,7 +1291,7 @@ func TestUnsetKeyBranchLastLeaf(t *testing.T) { Key: "foo", Value: TreeBranch{ TreeItem{ - Key: "bar", + Key: "bar", Value: "bar", }, }, @@ -1302,9 +1301,8 @@ func TestUnsetKeyBranchLastLeaf(t *testing.T) { assert.NoError(t, err) assert.Equal(t, TreeBranch{ TreeItem{ - Key: "foo", - Value: TreeBranch{ - }, + Key: "foo", + Value: TreeBranch{}, }, }, unset) } @@ -1319,7 +1317,7 @@ func TestUnsetKeyArray(t *testing.T) { Value: []interface{}{ TreeBranch{ TreeItem{ - Key: "baz", + Key: "baz", Value: "baz", }, }, @@ -1332,9 +1330,8 @@ func TestUnsetKeyArray(t *testing.T) { assert.NoError(t, err) assert.Equal(t, TreeBranch{ TreeItem{ - Key: "foo", - Value: TreeBranch{ - }, + Key: "foo", + Value: TreeBranch{}, }, }, unset) } @@ -1346,13 +1343,13 @@ func TestUnsetArrayItem(t *testing.T) { Value: []interface{}{ TreeBranch{ TreeItem{ - Key: "bar", + Key: "bar", Value: "bar", }, }, TreeBranch{ TreeItem{ - Key: "barbar", + Key: "barbar", Value: "barbar", }, }, @@ -1367,7 +1364,7 @@ func TestUnsetArrayItem(t *testing.T) { Value: []interface{}{ TreeBranch{ TreeItem{ - Key: "bar", + Key: "bar", Value: "bar", }, }, @@ -1383,11 +1380,11 @@ func TestUnsetKeyInArrayItem(t *testing.T) { Value: []interface{}{ TreeBranch{ TreeItem{ - Key: "bar", + Key: "bar", Value: "bar", }, TreeItem{ - Key: "barbar", + Key: "barbar", Value: "barbar", }, }, @@ -1402,7 +1399,7 @@ func TestUnsetKeyInArrayItem(t *testing.T) { Value: []interface{}{ TreeBranch{ TreeItem{ - Key: "bar", + Key: "bar", Value: "bar", }, }, @@ -1418,7 +1415,7 @@ func TestUnsetArrayLastItem(t *testing.T) { Value: []interface{}{ TreeBranch{ TreeItem{ - Key: "bar", + Key: "bar", Value: "bar", }, }, @@ -1429,9 +1426,8 @@ func TestUnsetArrayLastItem(t *testing.T) { assert.NoError(t, err) assert.Equal(t, TreeBranch{ TreeItem{ - Key: "foo", - Value: []interface{}{ - }, + Key: "foo", + Value: []interface{}{}, }, }, unset) } @@ -1442,7 +1438,7 @@ func TestUnsetKeyNotFound(t *testing.T) { Key: "foo", Value: TreeBranch{ TreeItem{ - Key: "bar", + Key: "bar", Value: "bar", }, }, @@ -1461,7 +1457,7 @@ func TestUnsetKeyInArrayNotFound(t *testing.T) { Value: []interface{}{ TreeBranch{ TreeItem{ - Key: "bar", + Key: "bar", Value: "bar", }, }, @@ -1480,7 +1476,7 @@ func TestUnsetArrayItemOutOfBounds(t *testing.T) { Value: []interface{}{ TreeBranch{ TreeItem{ - Key: "bar", + Key: "bar", Value: "bar", }, }, @@ -1495,7 +1491,7 @@ func TestUnsetArrayItemOutOfBounds(t *testing.T) { func TestUnsetKeyNotABranch(t *testing.T) { branch := TreeBranch{ TreeItem{ - Key: "foo", + Key: "foo", Value: 99, }, } diff --git a/stores/flatten.go b/stores/flatten.go index fe6e981fd..16d730380 100644 --- a/stores/flatten.go +++ b/stores/flatten.go @@ -245,16 +245,16 @@ func DecodeNonStrings(m map[string]interface{}) error { } if v, ok := m["shamir_threshold"]; ok { switch val := v.(type) { - case string: - vInt, err := strconv.Atoi(val) - if err != nil { - return fmt.Errorf("shamir_threshold is not an integer: %s", err.Error()) - } - m["shamir_threshold"] = vInt - case int: - m["shamir_threshold"] = val - default: - return fmt.Errorf("shamir_threshold is neither a string nor an integer, but %T", val) + case string: + vInt, err := strconv.Atoi(val) + if err != nil { + return fmt.Errorf("shamir_threshold is not an integer: %s", err.Error()) + } + m["shamir_threshold"] = vInt + case int: + m["shamir_threshold"] = val + default: + return fmt.Errorf("shamir_threshold is neither a string nor an integer, but %T", val) } } return nil