errors.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package tokens
  15. import (
  16. "yunion.io/x/pkg/errors"
  17. "yunion.io/x/onecloud/pkg/httperrors"
  18. )
  19. const (
  20. ErrVerMismatch = errors.Error("[auth] version mismatch")
  21. ErrProjectDisabled = errors.Error("[auth] project disabled")
  22. ErrUserDisabled = errors.Error("[auth] user disabled")
  23. ErrInvalidToken = errors.Error("[auth] invalid token")
  24. ErrExpiredToken = errors.Error("[auth] expired token")
  25. ErrInvalidFernetToken = errors.Error("[auth] invalid fernet token")
  26. ErrInvalidAuthMethod = errors.Error("[auth] invalid auth methods")
  27. ErrUserNotFound = errors.Error("[auth] user not found")
  28. ErrDomainDisabled = errors.Error("[auth] domain is disabled")
  29. ErrEmptyAuth = errors.Error("[auth] empty auth request")
  30. ErrUserNotInProject = errors.Error("[auth] user not in project")
  31. ErrInvalidAccessKeyId = errors.Error("[auth] invalid access key id")
  32. ErrExpiredAccessKey = errors.Error("[auth] expired access key")
  33. ErrTokenNotFound = errors.Error("[auth] token not found")
  34. )
  35. func init() {
  36. httperrors.RegisterErrorHttpCode(ErrVerMismatch, 401)
  37. httperrors.RegisterErrorHttpCode(ErrProjectDisabled, 401)
  38. httperrors.RegisterErrorHttpCode(ErrUserDisabled, 401)
  39. httperrors.RegisterErrorHttpCode(ErrInvalidToken, 401)
  40. httperrors.RegisterErrorHttpCode(ErrExpiredToken, 401)
  41. httperrors.RegisterErrorHttpCode(ErrInvalidFernetToken, 401)
  42. httperrors.RegisterErrorHttpCode(ErrInvalidAuthMethod, 401)
  43. httperrors.RegisterErrorHttpCode(ErrUserNotFound, 401)
  44. httperrors.RegisterErrorHttpCode(ErrDomainDisabled, 401)
  45. httperrors.RegisterErrorHttpCode(ErrEmptyAuth, 401)
  46. httperrors.RegisterErrorHttpCode(ErrUserNotInProject, 401)
  47. httperrors.RegisterErrorHttpCode(ErrInvalidAccessKeyId, 401)
  48. httperrors.RegisterErrorHttpCode(ErrExpiredAccessKey, 401)
  49. httperrors.RegisterErrorHttpCode(ErrTokenNotFound, 401)
  50. }