From 420fc8efc24d7a77598307557e5b38077d0efafc Mon Sep 17 00:00:00 2001 From: Michael Kuhn Date: Tue, 21 Nov 2017 04:49:33 +0100 Subject: Disable add key button if SSH is disabled (#2873) --- models/error.go | 14 ++++++++++++++ models/ssh_key.go | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'models') diff --git a/models/error.go b/models/error.go index aa9db7abef..9df419aee8 100644 --- a/models/error.go +++ b/models/error.go @@ -37,6 +37,20 @@ func (err ErrNamePatternNotAllowed) Error() string { return fmt.Sprintf("name pattern is not allowed [pattern: %s]", err.Pattern) } +// ErrSSHDisabled represents an "SSH disabled" error. +type ErrSSHDisabled struct { +} + +// IsErrSSHDisabled checks if an error is a ErrSSHDisabled. +func IsErrSSHDisabled(err error) bool { + _, ok := err.(ErrSSHDisabled) + return ok +} + +func (err ErrSSHDisabled) Error() string { + return "SSH is disabled" +} + // ____ ___ // | | \______ ___________ // | | / ___// __ \_ __ \ diff --git a/models/ssh_key.go b/models/ssh_key.go index 15544efbc6..2d9f521fd4 100644 --- a/models/ssh_key.go +++ b/models/ssh_key.go @@ -260,7 +260,7 @@ func SSHNativeParsePublicKey(keyLine string) (string, int, error) { // It returns the actual public key line on success. func CheckPublicKeyString(content string) (_ string, err error) { if setting.SSH.Disabled { - return "", errors.New("SSH is disabled") + return "", ErrSSHDisabled{} } content, err = parseKeyString(content) -- cgit v1.2.3