Skip to content

Commit

Permalink
feat: envConfig tar høyde for service
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyrremann committed Feb 28, 2022
1 parent 0d344de commit 6a00345
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
30 changes: 18 additions & 12 deletions pkg/config/kafka_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"fmt"
"github.com/nais/cli/pkg/aiven"
"github.com/nais/cli/pkg/common"
"github.com/nais/cli/pkg/consts"
v1 "k8s.io/api/core/v1"
Expand All @@ -14,18 +15,23 @@ const (
KafkaSchemaRegistryEnvName = "kafka-secret.env"
)

func NewEnvConfig(secret *v1.Secret, dest string) Config {
return &KafkaEnvironment{
Envs: fmt.Sprintf("# nais-cli %s .env\n", time.Now().Truncate(time.Minute)),
Secret: secret,
PrefixPath: dest,
RequiredFiles: map[string]RequiredFile{
consts.KafkaCertificateKey: {consts.KafkaCertificateCrtFile, consts.KafkaCertificatePathKey, true},
consts.KafkaPrivateKeyKey: {consts.KafkaPrivateKeyPemFile, consts.KafkaPrivateKeyPathKey, true},
consts.KafkaCAKey: {consts.KafkaCACrtFile, consts.KafkaCAPathKey, true},
consts.KafkaClientKeyStoreP12File: {consts.KafkaClientKeyStoreP12File, consts.KafkaKeystorePathKey, false},
consts.KafkaClientTruststoreJksFile: {consts.KafkaClientTruststoreJksFile, consts.KafkaTruststorePathKey, false},
},
func NewEnvConfig(secret *v1.Secret, dest string, service aiven.Service) (Config, error) {
switch service {
case aiven.Kafka:
return &KafkaEnvironment{
Envs: fmt.Sprintf("# nais-cli %s .env\n", time.Now().Truncate(time.Minute)),
Secret: secret,
PrefixPath: dest,
RequiredFiles: map[string]RequiredFile{
consts.KafkaCertificateKey: {consts.KafkaCertificateCrtFile, consts.KafkaCertificatePathKey, true},
consts.KafkaPrivateKeyKey: {consts.KafkaPrivateKeyPemFile, consts.KafkaPrivateKeyPathKey, true},
consts.KafkaCAKey: {consts.KafkaCACrtFile, consts.KafkaCAPathKey, true},
consts.KafkaClientKeyStoreP12File: {consts.KafkaClientKeyStoreP12File, consts.KafkaKeystorePathKey, false},
consts.KafkaClientTruststoreJksFile: {consts.KafkaClientTruststoreJksFile, consts.KafkaTruststorePathKey, false},
},
}, nil
default:
return nil, fmt.Errorf("unknown service: %v", service)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/secret/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (s *Secret) CreateKCatConfig() error {
}

func (s *Secret) CreateEnvConfig() error {
kafkaEnv := config.NewEnvConfig(s.Secret, s.DestinationPath)
kafkaEnv := config.NewEnvConfig(s.Secret, s.DestinationPath, s.Service)
_, err := kafkaEnv.Generate()
if err != nil {
return fmt.Errorf("generate %s config-type", s.ConfigType)
Expand Down

0 comments on commit 6a00345

Please sign in to comment.