api_token.go 417 B

123456789101112131415161718192021222324252627
  1. package models
  2. import (
  3. "time"
  4. "gorm.io/gorm"
  5. )
  6. type APIToken struct {
  7. gorm.Model
  8. UniqueID string `gorm:"unique"`
  9. ProjectID uint
  10. CreatedByUserID uint
  11. Expiry *time.Time
  12. Revoked bool
  13. PolicyName string
  14. // SecretKey is hashed like a password before storage
  15. SecretKey string
  16. }
  17. func (p *APIToken) IsExpired() bool {
  18. timeLeft := p.Expiry.Sub(time.Now())
  19. return timeLeft < 0
  20. }