From 2ac8e11f466f838ff34314c5e4e2785ebe2d036d Mon Sep 17 00:00:00 2001 From: Unknwon Date: Wed, 2 Sep 2015 02:40:15 -0400 Subject: #842 able to use access token replace basic auth --- models/error.go | 20 ++++++++++++++++++++ models/token.go | 7 +------ 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'models') diff --git a/models/error.go b/models/error.go index 4d888c87..92cc187b 100644 --- a/models/error.go +++ b/models/error.go @@ -183,6 +183,26 @@ func (err ErrDeployKeyNameAlreadyUsed) Error() string { return fmt.Sprintf("public key already exists: [repo_id: %d, name: %s]", err.RepoID, err.Name) } +// _____ ___________ __ +// / _ \ ____ ____ ____ ______ _____\__ ___/___ | | __ ____ ____ +// / /_\ \_/ ___\/ ___\/ __ \ / ___// ___/ | | / _ \| |/ // __ \ / \ +// / | \ \__\ \__\ ___/ \___ \ \___ \ | |( <_> ) <\ ___/| | \ +// \____|__ /\___ >___ >___ >____ >____ > |____| \____/|__|_ \\___ >___| / +// \/ \/ \/ \/ \/ \/ \/ \/ \/ + +type ErrAccessTokenNotExist struct { + SHA string +} + +func IsErrAccessTokenNotExist(err error) bool { + _, ok := err.(ErrAccessTokenNotExist) + return ok +} + +func (err ErrAccessTokenNotExist) Error() string { + return fmt.Sprintf("access token does not exist: [sha: %s]", err.SHA) +} + // ________ .__ __ .__ // \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____ // / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \ diff --git a/models/token.go b/models/token.go index 6c4328e5..852a910f 100644 --- a/models/token.go +++ b/models/token.go @@ -5,17 +5,12 @@ package models import ( - "errors" "time" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/uuid" ) -var ( - ErrAccessTokenNotExist = errors.New("Access token does not exist") -) - // AccessToken represents a personal access token. type AccessToken struct { ID int64 `xorm:"pk autoincr"` @@ -42,7 +37,7 @@ func GetAccessTokenBySHA(sha string) (*AccessToken, error) { if err != nil { return nil, err } else if !has { - return nil, ErrAccessTokenNotExist + return nil, ErrAccessTokenNotExist{sha} } return t, nil } -- cgit v1.2.3