From b39568920eb81742451f5f7e9f3219b1a6292fcc Mon Sep 17 00:00:00 2001 From: Henning Surmeier Date: Wed, 24 Nov 2021 18:32:16 +0100 Subject: [PATCH] use default encoding in crd controller --- pkg/controller/crd/stringsecret/stringsecret_controller.go | 6 +++++- pkg/controller/secret/secret_basic_auth.go | 2 +- pkg/controller/secret/secret_controller.go | 2 +- pkg/controller/secret/secret_string.go | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/controller/crd/stringsecret/stringsecret_controller.go b/pkg/controller/crd/stringsecret/stringsecret_controller.go index a1102152..57008c61 100644 --- a/pkg/controller/crd/stringsecret/stringsecret_controller.go +++ b/pkg/controller/crd/stringsecret/stringsecret_controller.go @@ -157,7 +157,11 @@ func setValuesForFields(fields []v1alpha1.Field, regenerate bool, values map[str reqLogger.Error(err, "could not parse length from map for new random string") return err } - randomString, randErr := secret.GenerateRandomString(fieldLength, field.Encoding, isByteLength) + encoding := field.Encoding + if encoding == "" { + encoding = secret.DefaultEncoding() + } + randomString, randErr := secret.GenerateRandomString(fieldLength, encoding, isByteLength) if randErr != nil { reqLogger.Error(err, "could not generate new random string") return err diff --git a/pkg/controller/secret/secret_basic_auth.go b/pkg/controller/secret/secret_basic_auth.go index 9356b25b..571840f4 100644 --- a/pkg/controller/secret/secret_basic_auth.go +++ b/pkg/controller/secret/secret_basic_auth.go @@ -41,7 +41,7 @@ func (bg BasicAuthGenerator) generateData(instance *corev1.Secret) (reconcile.Re } var encoding string - encoding, err = getEncodingFromAnnotation(defaultEncoding(), instance.Annotations) + encoding, err = getEncodingFromAnnotation(DefaultEncoding(), instance.Annotations) if err != nil { return reconcile.Result{}, err } diff --git a/pkg/controller/secret/secret_controller.go b/pkg/controller/secret/secret_controller.go index 64708ecd..17c34b69 100644 --- a/pkg/controller/secret/secret_controller.go +++ b/pkg/controller/secret/secret_controller.go @@ -32,7 +32,7 @@ func DefaultLength() int { return viper.GetInt("secret-length") } -func defaultEncoding() string { +func DefaultEncoding() string { return viper.GetString("secret-encoding") } diff --git a/pkg/controller/secret/secret_string.go b/pkg/controller/secret/secret_string.go index a4c6f5ac..7a2f2a47 100644 --- a/pkg/controller/secret/secret_string.go +++ b/pkg/controller/secret/secret_string.go @@ -43,7 +43,7 @@ func (pg StringGenerator) generateRandomSecret(conf secretConfig) error { length := conf.length isByteLength := conf.isByteLength - encoding, err := getEncodingFromAnnotation(defaultEncoding(), instance.Annotations) + encoding, err := getEncodingFromAnnotation(DefaultEncoding(), instance.Annotations) if err != nil { return err }