From 328f802b8e87ae1f6bd8319be2f427e588043397 Mon Sep 17 00:00:00 2001 From: vitshev Date: Mon, 16 Dec 2024 18:02:07 +0100 Subject: [PATCH] fix(configuration): replace string literals with constants Signed-off-by: vitshev --- configuration/configuration.go | 15 +++++++++++---- registry/registry.go | 8 ++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/configuration/configuration.go b/configuration/configuration.go index 25e09ba7c..0da95892b 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -904,6 +904,13 @@ func setFieldValue(field reflect.Value, value interface{}) error { return nil } +const ( + ClientAuthRequestClientCert = "request-client-cert" + ClientAuthRequireAnyClientCert = "require-any-client-cert" + ClientAuthVerifyClientCertIfGiven = "verify-client-cert-if-given" + ClientAuthRequireAndVerifyClientCert = "require-and-verify-client-cert" +) + type ClientAuth string // UnmarshalYAML implements the yaml.Umarshaler interface @@ -916,10 +923,10 @@ func (clientAuth *ClientAuth) UnmarshalYAML(unmarshal func(interface{}) error) e } switch clientAuthString { - case "request-client-cert": - case "require-any-client-cert": - case "verify-client-cert-if-given": - case "require-and-verify-client-cert": + case ClientAuthRequestClientCert: + case ClientAuthRequireAnyClientCert: + case ClientAuthVerifyClientCertIfGiven: + case ClientAuthRequireAndVerifyClientCert: default: return fmt.Errorf("invalid ClientAuth %s Must be one of: request-client-cert, require-any-client-cert, verify-client-cert-if-given, require-and-verify-client-cert", clientAuthString) } diff --git a/registry/registry.go b/registry/registry.go index 84c6c3424..29fc1c401 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -81,10 +81,10 @@ var tlsVersions = map[string]uint16{ // tlsClientAuth maps user-specified values to TLS Client Authentication constants. var tlsClientAuth = map[string]tls.ClientAuthType{ - "request-client-cert": tls.RequestClientCert, - "require-any-client-cert": tls.RequireAnyClientCert, - "verify-client-cert-if-given": tls.VerifyClientCertIfGiven, - "require-and-verify-client-cert": tls.RequireAndVerifyClientCert, + configuration.ClientAuthRequestClientCert: tls.RequestClientCert, + configuration.ClientAuthRequireAnyClientCert: tls.RequireAnyClientCert, + configuration.ClientAuthVerifyClientCertIfGiven: tls.VerifyClientCertIfGiven, + configuration.ClientAuthRequireAndVerifyClientCert: tls.RequireAndVerifyClientCert, } // defaultLogFormatter is the default formatter to use for logs.