Skip to content

Commit

Permalink
split variable names for more clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
aaperis committed Dec 14, 2024
1 parent 72c0e6b commit 3a4f095
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions charts/sda-svc/templates/download-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ spec:
value: {{ .Values.global.log.level | quote }}
{{- end }}
{{- if .Values.global.download.serveDecrypted.c4ghKeyFile }}
- name: APP_C4GHPRIVATEKEYPATH
- name: APP_C4GH_PRIVATEKEYPATH
value: {{ template "c4ghPath" . }}/{{ .Values.global.download.serveDecrypted.c4ghKeyFile }}
- name: APP_C4GHPASSPHRASE
- name: APP_C4GH_PASSPHRASE
valueFrom:
secretKeyRef:
name: {{ required "A secret for the transient c4gh key is required" .Values.global.download.serveDecrypted.secretName }}
Expand Down
40 changes: 20 additions & 20 deletions sda-download/api/sda/sda_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ func TestDownload_Fail_FileNotFound(t *testing.T) {
return "", errors.New("file not found")
}

viper.Set("app.c4ghPrivateKeyPath", privateKeyFilePath)
viper.Set("app.c4ghPassphrase", "password")
viper.Set("app.c4gh.privateKeyPath", privateKeyFilePath)
viper.Set("app.c4gh.passphrase", "password")
config.Config.App.Crypt4GHPrivateKey, config.Config.App.Crypt4GHPublicKeyB64, err = config.GetC4GHKeys()
assert.NoError(t, err, "Could not load c4gh keys")

Expand Down Expand Up @@ -443,8 +443,8 @@ func TestDownload_Fail_FileNotFound(t *testing.T) {
database.CheckFilePermission = originalCheckFilePermission
config.Config.App.Crypt4GHPublicKeyB64 = originalServeUnencryptedDataTrigger
config.Config.App.Crypt4GHPrivateKey = originalC4ghPrivateKeyFilepath
viper.Set("app.c4ghPrivateKeyPath", "")
viper.Set("app.c4ghPassphrase", "")
viper.Set("app.c4gh.privateKeyPath", "")
viper.Set("app.c4gh.passphrase", "")

}

Expand All @@ -468,8 +468,8 @@ func TestDownload_Fail_NoPermissions(t *testing.T) {
return session.Cache{}
}

viper.Set("app.c4ghPrivateKeyPath", privateKeyFilePath)
viper.Set("app.c4ghPassphrase", "password")
viper.Set("app.c4gh.privateKeyPath", privateKeyFilePath)
viper.Set("app.c4gh.passphrase", "password")
config.Config.App.Crypt4GHPrivateKey, config.Config.App.Crypt4GHPublicKeyB64, err = config.GetC4GHKeys()
assert.NoError(t, err, "Could not load c4gh keys")

Expand Down Expand Up @@ -502,8 +502,8 @@ func TestDownload_Fail_NoPermissions(t *testing.T) {
middleware.GetCacheFromContext = originalGetCacheFromContext
config.Config.App.Crypt4GHPublicKeyB64 = originalServeUnencryptedDataTrigger
config.Config.App.Crypt4GHPrivateKey = originalC4ghPrivateKeyFilepath
viper.Set("app.c4ghPrivateKeyPath", "")
viper.Set("app.c4ghPassphrase", "")
viper.Set("app.c4gh.privateKeyPath", "")
viper.Set("app.c4gh.passphrase", "")

}

Expand Down Expand Up @@ -532,8 +532,8 @@ func TestDownload_Fail_GetFile(t *testing.T) {
return nil, errors.New("database error")
}

viper.Set("app.c4ghPrivateKeyPath", privateKeyFilePath)
viper.Set("app.c4ghPassphrase", "password")
viper.Set("app.c4gh.privateKeyPath", privateKeyFilePath)
viper.Set("app.c4gh.passphrase", "password")
config.Config.App.Crypt4GHPrivateKey, config.Config.App.Crypt4GHPublicKeyB64, err = config.GetC4GHKeys()
assert.NoError(t, err, "Could not load c4gh keys")

Expand Down Expand Up @@ -567,8 +567,8 @@ func TestDownload_Fail_GetFile(t *testing.T) {
database.GetFile = originalGetFile
config.Config.App.Crypt4GHPublicKeyB64 = originalServeUnencryptedDataTrigger
config.Config.App.Crypt4GHPrivateKey = originalC4ghPrivateKeyFilepath
viper.Set("app.c4ghPrivateKeyPath", "")
viper.Set("app.c4ghPassphrase", "")
viper.Set("app.c4gh.privateKeyPath", "")
viper.Set("app.c4gh.passphrase", "")

}

Expand Down Expand Up @@ -604,8 +604,8 @@ func TestDownload_Fail_OpenFile(t *testing.T) {
return fileDetails, nil
}

viper.Set("app.c4ghPrivateKeyPath", privateKeyFilePath)
viper.Set("app.c4ghPassphrase", "password")
viper.Set("app.c4gh.privateKeyPath", privateKeyFilePath)
viper.Set("app.c4gh.passphrase", "password")
config.Config.App.Crypt4GHPrivateKey, config.Config.App.Crypt4GHPublicKeyB64, err = config.GetC4GHKeys()
assert.NoError(t, err, "Could not load c4gh keys")

Expand Down Expand Up @@ -642,8 +642,8 @@ func TestDownload_Fail_OpenFile(t *testing.T) {
database.GetFile = originalGetFile
config.Config.App.Crypt4GHPublicKeyB64 = originalServeUnencryptedDataTrigger
config.Config.App.Crypt4GHPrivateKey = originalC4ghPrivateKeyFilepath
viper.Set("app.c4ghPrivateKeyPath", "")
viper.Set("app.c4ghPassphrase", "")
viper.Set("app.c4gh.privateKeyPath", "")
viper.Set("app.c4gh.passphrase", "")
}

func Test_CalucalateCoords(t *testing.T) {
Expand Down Expand Up @@ -795,8 +795,8 @@ func TestDownload_Whole_Range_Encrypted(t *testing.T) {
config.Config.Reencrypt.ClientKey = keyfile.Name()
config.Config.Reencrypt.Timeout = 10

viper.Set("app.c4ghPrivateKeyPath", privateKeyFilePath)
viper.Set("app.c4ghPassphrase", "password")
viper.Set("app.c4gh.privateKeyPath", privateKeyFilePath)
viper.Set("app.c4gh.passphrase", "password")
config.Config.App.Crypt4GHPrivateKey, config.Config.App.Crypt4GHPublicKeyB64, err = config.GetC4GHKeys()
assert.NoError(t, err, "Could not load c4gh keys")

Expand Down Expand Up @@ -944,8 +944,8 @@ func TestDownload_Whole_Range_Encrypted(t *testing.T) {
database.GetFile = originalGetFile
config.Config.App.Crypt4GHPublicKeyB64 = originalServeUnencryptedDataTrigger
config.Config.App.Crypt4GHPrivateKey = originalC4ghPrivateKeyFilepath
viper.Set("app.c4ghPrivateKeyPath", "")
viper.Set("app.c4ghPassphrase", "")
viper.Set("app.c4gh.privateKeyPath", "")
viper.Set("app.c4gh.passphrase", "")
}

func GenerateTestC4ghKey(t *testing.T) (string, error) {
Expand Down
4 changes: 2 additions & 2 deletions sda-download/dev_utils/compose-no-tls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ services:
- ARCHIVE_URL=http://s3
- ARCHIVE_TYPE=s3
- DB_HOST=db
- APP_C4GHPRIVATEKEYPATH=/dev_utils/c4gh.sec.pem
- APP_C4GHPASSPHRASE=oaagCP1YgAZeEyl2eJAkHv9lkcWXWFgm
- APP_C4GH_PRIVATEKEYPATH=/dev_utils/c4gh.sec.pem
- APP_C4GH_PASSPHRASE=oaagCP1YgAZeEyl2eJAkHv9lkcWXWFgm
image: neicnordic/sda-download:latest
build:
context: ..
Expand Down
4 changes: 2 additions & 2 deletions sda-download/dev_utils/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ services:
condition: service_started
env_file: ./env.download
environment:
- APP_C4GHPRIVATEKEYPATH=/dev_utils/c4gh.sec.pem
- APP_C4GHPASSPHRASE=oaagCP1YgAZeEyl2eJAkHv9lkcWXWFgm
- APP_C4GH_PRIVATEKEYPATH=/dev_utils/c4gh.sec.pem
- APP_C4GH_PASSPHRASE=oaagCP1YgAZeEyl2eJAkHv9lkcWXWFgm
image: neicnordic/sda-download:latest
volumes:
- ./config.yaml:/config.yaml
Expand Down
10 changes: 5 additions & 5 deletions sda-download/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,10 @@ func (c *Map) appConfig() error {
}

var err error
if viper.IsSet("app.c4ghPrivateKeyPath") {
if viper.IsSet("app.c4gh.privateKeyPath") {

if !viper.IsSet("app.c4ghPassphrase") {
return errors.New("app.c4ghPassphrase is not set")
if !viper.IsSet("app.c4gh.passphrase") {
return errors.New("app.c4gh.passphrase is not set")
}

c.App.Crypt4GHPrivateKey, c.App.Crypt4GHPublicKeyB64, err = GetC4GHKeys()
Expand Down Expand Up @@ -487,8 +487,8 @@ func constructWhitelist(obj []TrustedISS) *jwk.MapWhitelist {

// GetC4GHKey reads and decrypts and returns the c4gh key
func GetC4GHKeys() ([32]byte, string, error) {
keyPath := viper.GetString("app.c4ghPrivateKeyPath")
passphrase := viper.GetString("app.c4ghPassphrase")
keyPath := viper.GetString("app.c4gh.privateKeyPath")
passphrase := viper.GetString("app.c4gh.passphrase")

// Make sure the key path and passphrase is valid
keyFile, err := os.Open(keyPath)
Expand Down
10 changes: 5 additions & 5 deletions sda-download/internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func (suite *TestSuite) TestAppConfig() {
viper.Set("app.serverkey", "test")
viper.Set("log.logLevel", "debug")
viper.Set("db.sslmode", "disable")
viper.Set("app.c4ghPrivateKeyPath", privateKeyFile.Name())
viper.Set("app.c4ghPassphrase", "password")
viper.Set("app.c4gh.PrivateKeyPath", privateKeyFile.Name())
viper.Set("app.c4gh.passphrase", "password")

c = &Map{}
err = c.appConfig()
Expand All @@ -116,13 +116,13 @@ func (suite *TestSuite) TestAppConfig() {
assert.Nilf(suite.T(), err, "Incorrect public c4gh key generated (bad key)")

// Check false c4gh key
viper.Set("app.c4ghPrivateKeyPath", "some/nonexistent.key")
viper.Set("app.c4gh.privateKeyPath", "some/nonexistent.key")
err = c.appConfig()
assert.ErrorContains(suite.T(), err, "no such file or directory")

// Check false c4gh key
viper.Set("app.c4ghPrivateKeyPath", privateKeyFile.Name())
viper.Set("app.c4ghPassphrase", "blablabla")
viper.Set("app.c4gh.privateKeyPath", privateKeyFile.Name())
viper.Set("app.c4gh.passphrase", "blablabla")
err = c.appConfig()
assert.ErrorContains(suite.T(), err, "chacha20poly1305: message authentication failed")
}
Expand Down

0 comments on commit 3a4f095

Please sign in to comment.