100 lines
2.5 KiB
Go
100 lines
2.5 KiB
Go
package authtokens
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
//ErrInvalidToken occurs when given credentials are invalid.
|
|
type ErrInvalidToken struct{}
|
|
|
|
//Error returns error message
|
|
func (e *ErrInvalidToken) Error() string {
|
|
return "invalid token"
|
|
}
|
|
|
|
//ErrExpiredToken occurs when given token is expired.
|
|
type ErrExpiredToken struct{}
|
|
|
|
//Error returns error message
|
|
func (e *ErrExpiredToken) Error() string {
|
|
return "expired token"
|
|
}
|
|
|
|
//ErrInvalidCredentials occurs when given credentials are invalid.
|
|
type ErrInvalidCredentials struct{}
|
|
|
|
//Error returns error message
|
|
func (e *ErrInvalidCredentials) Error() string {
|
|
return "invalid credentials"
|
|
}
|
|
|
|
//ErrTokenNotFound occurs when given token does not exist.
|
|
type ErrTokenNotFound struct{}
|
|
|
|
//Error returns error message
|
|
func (e *ErrTokenNotFound) Error() string {
|
|
return "token not found"
|
|
}
|
|
|
|
//ErrNilToken occurs when given token is nil.
|
|
type ErrNilToken struct{}
|
|
|
|
//Error returns error message
|
|
func (e *ErrNilToken) Error() string {
|
|
return "token is nil"
|
|
}
|
|
|
|
//ErrUserNotFound occurs when no user by given userName is found
|
|
type ErrUserNotFound struct {
|
|
user string
|
|
}
|
|
|
|
//Error returns error message
|
|
func (e ErrUserNotFound) Error() string {
|
|
return fmt.Sprintf("user '%s' not found", e.user)
|
|
}
|
|
|
|
//NewErrUserNotFound occurs when no user by given userName is found
|
|
func NewErrUserNotFound(userName string) error {
|
|
return &ErrUserNotFound{userName}
|
|
}
|
|
|
|
//ErrFailedToGetTokens when repository failed retrieving tokens.
|
|
type ErrFailedToGetTokens struct {
|
|
user string
|
|
original error
|
|
}
|
|
|
|
//Error returns error message
|
|
func (e ErrFailedToGetTokens) Error() string {
|
|
return fmt.Sprintf("failed to get tokens for user '%s': %s", e.user, e.original.Error())
|
|
}
|
|
|
|
//NewErrFailedToGetTokens occurs when repository fails to retrieve tokens.
|
|
func NewErrFailedToGetTokens(userName string, original error) error {
|
|
return &ErrFailedToGetTokens{userName, original}
|
|
}
|
|
|
|
//ErrRepositoryConnectionFailure occurs when repository connection failed
|
|
type ErrRepositoryConnectionFailure struct {
|
|
name string
|
|
}
|
|
|
|
//Error returns error message
|
|
func (e ErrRepositoryConnectionFailure) Error() string {
|
|
return fmt.Sprintf("failed to connect to repository %s", e.name)
|
|
}
|
|
|
|
//NewErrRepositoryConnectionFailure occurs when repository connection failed
|
|
func NewErrRepositoryConnectionFailure(name string) error {
|
|
return &ErrRepositoryConnectionFailure{name}
|
|
}
|
|
|
|
//ErrUnauthorized occurs when a token is valid, but does not contain the given rights
|
|
type ErrUnauthorized struct{}
|
|
|
|
//Error returns error message
|
|
func (e ErrUnauthorized) Error() string {
|
|
return "unauthorized token"
|
|
}
|