metrics: reduce complexity for AddLoginResult method

fix a gocyclo warning
This commit is contained in:
Nicola Murino 2021-02-28 12:23:48 +01:00
parent a6e36e7cad
commit 901cafc6da
No known key found for this signature in database
GPG key ID: 2F1FB59433D5A8CB

View file

@ -830,44 +830,52 @@ func AddLoginAttempt(authMethod string) {
}
}
func incLoginOK(authMethod string) {
totalLoginOK.Inc()
switch authMethod {
case loginMethodPublicKey:
totalKeyLoginOK.Inc()
case loginMethodKeyboardInteractive:
totalInteractiveLoginOK.Inc()
case loginMethodKeyAndPassword:
totalKeyAndPasswordLoginOK.Inc()
case loginMethodKeyAndKeyboardInt:
totalKeyAndKeyIntLoginOK.Inc()
case loginMethodTLSCertificate:
totalTLSCertLoginOK.Inc()
case loginMethodTLSCertificateAndPwd:
totalTLSCertAndPwdLoginOK.Inc()
default:
totalPasswordLoginOK.Inc()
}
}
func incLoginFailed(authMethod string) {
totalLoginFailed.Inc()
switch authMethod {
case loginMethodPublicKey:
totalKeyLoginFailed.Inc()
case loginMethodKeyboardInteractive:
totalInteractiveLoginFailed.Inc()
case loginMethodKeyAndPassword:
totalKeyAndPasswordLoginFailed.Inc()
case loginMethodKeyAndKeyboardInt:
totalKeyAndKeyIntLoginFailed.Inc()
case loginMethodTLSCertificate:
totalTLSCertLoginFailed.Inc()
case loginMethodTLSCertificateAndPwd:
totalTLSCertAndPwdLoginFailed.Inc()
default:
totalPasswordLoginFailed.Inc()
}
}
// AddLoginResult increments the metrics for login results
func AddLoginResult(authMethod string, err error) {
if err == nil {
totalLoginOK.Inc()
switch authMethod {
case loginMethodPublicKey:
totalKeyLoginOK.Inc()
case loginMethodKeyboardInteractive:
totalInteractiveLoginOK.Inc()
case loginMethodKeyAndPassword:
totalKeyAndPasswordLoginOK.Inc()
case loginMethodKeyAndKeyboardInt:
totalKeyAndKeyIntLoginOK.Inc()
case loginMethodTLSCertificate:
totalTLSCertLoginOK.Inc()
case loginMethodTLSCertificateAndPwd:
totalTLSCertAndPwdLoginOK.Inc()
default:
totalPasswordLoginOK.Inc()
}
incLoginOK(authMethod)
} else {
totalLoginFailed.Inc()
switch authMethod {
case loginMethodPublicKey:
totalKeyLoginFailed.Inc()
case loginMethodKeyboardInteractive:
totalInteractiveLoginFailed.Inc()
case loginMethodKeyAndPassword:
totalKeyAndPasswordLoginFailed.Inc()
case loginMethodKeyAndKeyboardInt:
totalKeyAndKeyIntLoginFailed.Inc()
case loginMethodTLSCertificate:
totalTLSCertLoginFailed.Inc()
case loginMethodTLSCertificateAndPwd:
totalTLSCertAndPwdLoginFailed.Inc()
default:
totalPasswordLoginFailed.Inc()
}
incLoginFailed(authMethod)
}
}