Add and fix errname

This commit is contained in:
Kristoffer Dalby 2021-11-15 16:33:16 +00:00
parent 0c45f8d252
commit 0c005a6b01
No known key found for this signature in database
GPG key ID: 09F62DC067465735
10 changed files with 50 additions and 51 deletions

View file

@ -13,8 +13,8 @@ import (
)
const (
errorAuthKeyNotFound = Error("AuthKey not found")
errorAuthKeyExpired = Error("AuthKey expired")
errPreAuthKeyNotFound = Error("AuthKey not found")
errPreAuthKeyExpired = Error("AuthKey expired")
errSingleUseAuthKeyHasBeenUsed = Error("AuthKey has already been used")
)
@ -120,11 +120,11 @@ func (h *Headscale) checkKeyValidity(k string) (*PreAuthKey, error) {
result.Error,
gorm.ErrRecordNotFound,
) {
return nil, errorAuthKeyNotFound
return nil, errPreAuthKeyNotFound
}
if pak.Expiration != nil && pak.Expiration.Before(time.Now()) {
return nil, errorAuthKeyExpired
return nil, errPreAuthKeyExpired
}
if pak.Reusable || pak.Ephemeral { // we don't need to check if has been used before