fix: use secretId to match secret names in configs
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
decentral1se 2023-09-25 15:51:15 +02:00
parent 776a83d8d1
commit d5b18d74ef
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
2 changed files with 49 additions and 11 deletions

View File

@ -87,22 +87,19 @@ func ReadSecretsConfig(appEnv map[string]string, composeFiles []string, recipeNa
return secretConfigs, nil return secretConfigs, nil
} }
for _, secret := range config.Secrets { for secretId, secretConfig := range config.Secrets {
firstIdx := strings.Index(secret.Name, "_") if string(secretConfig.Name[len(secretConfig.Name)-1]) == "_" {
lastIdx := strings.LastIndex(secret.Name, "_") return secretConfigs, fmt.Errorf("missing version for secret? (%s)", secretId)
secretName := secret.Name[firstIdx+1 : lastIdx]
if secret.Name != "" && string(secret.Name[len(secret.Name)-1]) == "_" {
return secretConfigs, fmt.Errorf("missing version for secret? (%s)", secretName)
} }
if !(slices.Contains(enabledSecrets, secretName)) { if !(slices.Contains(enabledSecrets, secretId)) {
logrus.Debugf("%s not enabled in recipe config, not generating", secretName) logrus.Warnf("%s not enabled in recipe config, not generating", secretId)
continue continue
} }
secretVersion := secret.Name[lastIdx+1:] lastIdx := strings.LastIndex(secretConfig.Name, "_")
secretConfigs[secretName] = secretVersion secretVersion := secretConfig.Name[lastIdx+1:]
secretConfigs[secretId] = secretVersion
} }
return secretConfigs, nil return secretConfigs, nil

41
pkg/secret/secret_test.go Normal file
View File

@ -0,0 +1,41 @@
package secret
import (
"path"
"testing"
"coopcloud.tech/abra/pkg/config"
"coopcloud.tech/abra/pkg/recipe"
"coopcloud.tech/abra/pkg/upstream/stack"
loader "coopcloud.tech/abra/pkg/upstream/stack"
"github.com/stretchr/testify/assert"
)
func TestReadSecretsConfig(t *testing.T) {
offline := true
recipe, err := recipe.Get("matrix-synapse", offline)
if err != nil {
t.Fatal(err)
}
sampleEnv, err := recipe.SampleEnv()
if err != nil {
t.Fatal(err)
}
composeFiles := []string{path.Join(config.RECIPES_DIR, recipe.Name, "compose.yml")}
secretsFromConfig, err := ReadSecretsConfig(sampleEnv, composeFiles, recipe.Name)
if err != nil {
t.Fatal(err)
}
opts := stack.Deploy{Composefiles: composeFiles}
config, err := loader.LoadComposefile(opts, sampleEnv)
if err != nil {
t.Fatal(err)
}
for secretId := range config.Secrets {
assert.Contains(t, secretsFromConfig, secretId)
}
}