1
0
mirror of https://github.com/distribution/distribution synced 2024-12-25 15:05:51 +01:00

fix(configuration): replace string literals with constants

Signed-off-by: vitshev <vitshev@tracto.ai>
This commit is contained in:
vitshev 2024-12-16 18:02:07 +01:00 committed by vitshev
parent 916bdeae94
commit 328f802b8e
No known key found for this signature in database
GPG Key ID: 8134E7CAB222896C
2 changed files with 15 additions and 8 deletions

@ -904,6 +904,13 @@ func setFieldValue(field reflect.Value, value interface{}) error {
return nil 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 type ClientAuth string
// UnmarshalYAML implements the yaml.Umarshaler interface // UnmarshalYAML implements the yaml.Umarshaler interface
@ -916,10 +923,10 @@ func (clientAuth *ClientAuth) UnmarshalYAML(unmarshal func(interface{}) error) e
} }
switch clientAuthString { switch clientAuthString {
case "request-client-cert": case ClientAuthRequestClientCert:
case "require-any-client-cert": case ClientAuthRequireAnyClientCert:
case "verify-client-cert-if-given": case ClientAuthVerifyClientCertIfGiven:
case "require-and-verify-client-cert": case ClientAuthRequireAndVerifyClientCert:
default: 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) 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)
} }

@ -81,10 +81,10 @@ var tlsVersions = map[string]uint16{
// tlsClientAuth maps user-specified values to TLS Client Authentication constants. // tlsClientAuth maps user-specified values to TLS Client Authentication constants.
var tlsClientAuth = map[string]tls.ClientAuthType{ var tlsClientAuth = map[string]tls.ClientAuthType{
"request-client-cert": tls.RequestClientCert, configuration.ClientAuthRequestClientCert: tls.RequestClientCert,
"require-any-client-cert": tls.RequireAnyClientCert, configuration.ClientAuthRequireAnyClientCert: tls.RequireAnyClientCert,
"verify-client-cert-if-given": tls.VerifyClientCertIfGiven, configuration.ClientAuthVerifyClientCertIfGiven: tls.VerifyClientCertIfGiven,
"require-and-verify-client-cert": tls.RequireAndVerifyClientCert, configuration.ClientAuthRequireAndVerifyClientCert: tls.RequireAndVerifyClientCert,
} }
// defaultLogFormatter is the default formatter to use for logs. // defaultLogFormatter is the default formatter to use for logs.