From ced2be57d4567e6299a3baf8f9fbabd09aac3506 Mon Sep 17 00:00:00 2001 From: nanjiangshu Date: Mon, 16 Dec 2024 18:15:42 +0100 Subject: [PATCH] fix lint --- sda/cmd/ingest/ingest.go | 2 +- sda/cmd/ingest/ingest_test.go | 2 ++ sda/internal/config/config.go | 9 ++++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/sda/cmd/ingest/ingest.go b/sda/cmd/ingest/ingest.go index dd91c503f..accfd6f23 100644 --- a/sda/cmd/ingest/ingest.go +++ b/sda/cmd/ingest/ingest.go @@ -372,8 +372,8 @@ func main() { for _, key := range keyList { header, err = tryDecrypt(key, readBuffer) if err == nil { - // Decryption successful, store the successful key successfulKey = key + break } log.Warnf("Decryption failed with key, trying next key. Reason: (%s)", err.Error()) diff --git a/sda/cmd/ingest/ingest_test.go b/sda/cmd/ingest/ingest_test.go index 6b0eee517..9e5501f00 100644 --- a/sda/cmd/ingest/ingest_test.go +++ b/sda/cmd/ingest/ingest_test.go @@ -93,6 +93,7 @@ func (suite *TestSuite) TestTryDecrypt_wrongFile() { b, err := tryDecrypt(key, buf) if b != nil || err == nil { decryptionSuccessful = true + break } assert.EqualError(suite.T(), err, "not a Crypt4GH file") @@ -134,6 +135,7 @@ func (suite *TestSuite) TestTryDecrypt() { for _, key := range keyList { header, err := tryDecrypt(key, buf) if header != nil && err == nil { + break } assert.NoError(suite.T(), err) diff --git a/sda/internal/config/config.go b/sda/internal/config/config.go index 1b7c60131..0e4ede289 100644 --- a/sda/internal/config/config.go +++ b/sda/internal/config/config.go @@ -463,13 +463,16 @@ func NewConfig(app string) (*Config, error) { for _, s := range requiredConfVars { if s == "c4gh.keys" { // Check if at least one key entry has a valid filepath and passphrase - var keysConfig []map[string]string - viper.UnmarshalKey("c4gh.keys", &keysConfig) + var keyConfigs []map[string]string + if err := viper.UnmarshalKey("c4gh.keys", &keyConfigs); err != nil { + return nil, fmt.Errorf("failed to parse key configurations: %v", err) + } atLeastOneKeySet := false - for _, key := range keysConfig { + for _, key := range keyConfigs { if key["filepath"] != "" && key["passphrase"] != "" { atLeastOneKeySet = true + break } }