diff options
author | 2020-11-05 15:25:12 +0100 | |
---|---|---|
committer | 2020-11-10 13:08:23 +0100 | |
commit | 1815faa0ee14d5c27105a39f641a5b46939e72f8 (patch) | |
tree | a717a1b6a08a67d1a9341339bfd7c63170f5cf6c /certServiceK8sExternalProvider/src/cmpv2controller/logger/certificate_request_logger.go | |
parent | 8ad5e5e43ba2044e7deb1b92d131ceb086c89574 (diff) |
[OOM-K8S-CERT-EXTERNAL-PROVIDER] Refactoring & code improvements
Issue-ID: OOM-2559
Signed-off-by: Jan Malkiewicz <jan.malkiewicz@nokia.com>
Change-Id: I52c38aacf064682f0018ac37b1400893bd9e53fc
Diffstat (limited to 'certServiceK8sExternalProvider/src/cmpv2controller/logger/certificate_request_logger.go')
-rw-r--r-- | certServiceK8sExternalProvider/src/cmpv2controller/logger/certificate_request_logger.go | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/certServiceK8sExternalProvider/src/cmpv2controller/logger/certificate_request_logger.go b/certServiceK8sExternalProvider/src/cmpv2controller/logger/certificate_request_logger.go index 786557c1..649ce47f 100644 --- a/certServiceK8sExternalProvider/src/cmpv2controller/logger/certificate_request_logger.go +++ b/certServiceK8sExternalProvider/src/cmpv2controller/logger/certificate_request_logger.go @@ -27,6 +27,7 @@ import ( "strconv" cmapi "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1" + "onap.org/oom-certservice/k8s-external-provider/src/leveledlogger" ) @@ -36,26 +37,31 @@ const ( ) func LogCertRequestProperties(log leveledlogger.Logger, request *cmapi.CertificateRequest, csr *x509.CertificateRequest) { - logSupportedProperties(log, request, csr) + logSupportedProperties(log, csr) logPropertiesNotSupportedByCertService(log, request, csr) logPropertiesOverriddenByCMPv2Server(log, request) } -func logSupportedProperties(log leveledlogger.Logger, request *cmapi.CertificateRequest, csr *x509.CertificateRequest) { - logSupportedProperty(log, csr.Subject.Organization, "organization") - logSupportedProperty(log, csr.Subject.OrganizationalUnit, "organization unit") - logSupportedProperty(log, csr.Subject.Country, "country") - logSupportedProperty(log, csr.Subject.Province, "state") - logSupportedProperty(log, csr.Subject.Locality, "location") - logSupportedProperty(log, csr.DNSNames, "dns names") +func logSupportedProperties(log leveledlogger.Logger, csr *x509.CertificateRequest) { + logSupportedSingleValueProperty(log, csr.Subject.CommonName, "common name") + logSupportedMultiValueProperty(log, csr.Subject.Organization, "organization") + logSupportedMultiValueProperty(log, csr.Subject.OrganizationalUnit, "organization unit") + logSupportedMultiValueProperty(log, csr.Subject.Country, "country") + logSupportedMultiValueProperty(log, csr.Subject.Province, "state") + logSupportedMultiValueProperty(log, csr.Subject.Locality, "location") + logSupportedMultiValueProperty(log, csr.DNSNames, "dns names") } -func logSupportedProperty(log leveledlogger.Logger, values []string, propertyName string) { +func logSupportedMultiValueProperty(log leveledlogger.Logger, values []string, propertyName string) { if len(values) > 0 { log.Info(getSupportedMessage(propertyName, extractStringArray(values))) } } +func logSupportedSingleValueProperty(log leveledlogger.Logger, value string, propertyName string) { + log.Info(getSupportedMessage(propertyName, value)) +} + func logPropertiesOverriddenByCMPv2Server(log leveledlogger.Logger, request *cmapi.CertificateRequest) { if request.Spec.Duration != nil && len(request.Spec.Duration.String()) > 0 { log.Info(getOverriddenMessage("duration", request.Spec.Duration.Duration.String())) @@ -131,14 +137,14 @@ func extractIPAddresses(addresses []net.IP) string { return values } -func getNotSupportedMessage(property string, value string) string { - return "WARNING: Property '" + property + "' with value: " + value + " is not supported by " + CertServiceName +func getSupportedMessage(property string, value string) string { + return "+ property '" + property + "' with value '" + value + "' will be sent in certificate signing request to " + CMPv2ServerName } -func getSupportedMessage(property string, value string) string { - return "Property '" + property + "' with value: " + value + " will be sent in certificate signing request to " + CMPv2ServerName +func getNotSupportedMessage(property string, value string) string { + return "- property '" + property + "' with value '" + value + "' is not supported by " + CertServiceName } func getOverriddenMessage(property string, values string) string { - return "Property '" + property + "' with value: " + values + " will be overridden by " + CMPv2ServerName + return "* property '" + property + "' with value '" + values + "' will be overridden by " + CMPv2ServerName } |