Documentation
¶
Index ¶
- Variables
- func DeleteAPIKey(ctx context.Context, db *gorm.DB, id string, userID uuid.UUID) error
- func MarkExpiredAPIKeys(ctx context.Context, db *gorm.DB) error
- func RevokeAPIKey(ctx context.Context, db *gorm.DB, id string, userID uuid.UUID) error
- func UpdateAPIKeyLastUsed(ctx context.Context, db *gorm.DB, id uuid.UUID) error
- func UpdateAPIKeyState(ctx context.Context, db *gorm.DB, id uuid.UUID, userID uuid.UUID, state string) error
- type APIKey
- type APIKeyStatus
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrInvalidAPIKeyName is returned when the API key name is invalid. ErrInvalidAPIKeyName = errors.New("invalid API key name") // ErrAPIKeyNotFound is returned when the API key is not found. ErrAPIKeyNotFound = errors.New("API key not found") // ErrAPIKeyRevoked is returned when the API key is revoked. ErrAPIKeyRevoked = errors.New("API key is revoked") // ErrAPIKeyExpired is returned when the API key is expired. ErrAPIKeyExpired = errors.New("API key is expired") // ErrDuplicateAPIKeyName is returned when the API key name already exists for the user. ErrDuplicateAPIKeyName = errors.New("API key name already exists for this user") )
Functions ¶
func DeleteAPIKey ¶
DeleteAPIKey deletes an API key.
func MarkExpiredAPIKeys ¶
MarkExpiredAPIKeys marks all expired API keys as expired.
func RevokeAPIKey ¶
RevokeAPIKey revokes an API key.
func UpdateAPIKeyLastUsed ¶
UpdateAPIKeyLastUsed updates the last used timestamp.
Types ¶
type APIKey ¶
type APIKey struct {
ID uuid.UUID `json:"id" gorm:"column:id;type:uuid;primaryKey"`
UserID uuid.UUID `json:"user_id" gorm:"column:user_id;type:uuid;not null"`
Name string `json:"name" gorm:"column:name;type:varchar(255);not null"`
KeyHash string `json:"-" gorm:"column:key_hash;type:varchar(255);unique;not null"`
Scopes []string `json:"scopes" gorm:"column:scopes;type:text[]"`
ExpiresAt *time.Time `json:"expires_at" gorm:"column:expires_at;type:timestamp"`
LastUsedAt *time.Time `json:"last_used_at" gorm:"column:last_used_at;type:timestamp"`
RevokedAt *time.Time `json:"revoked_at" gorm:"column:revoked_at;type:timestamp"`
State string `json:"state" gorm:"column:state;type:varchar(50);not null;default:'active'"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime;column:created_at;not null"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime;column:updated_at;not null"`
}
func CreateAPIKey ¶
CreateAPIKey creates a new API key.
func GetAPIKeyByHash ¶
GetAPIKeyByHash retrieves an active API key by its hash.
func ListAPIKeys ¶
ListAPIKeys lists all API keys for a user.
func (*APIKey) GetStatus ¶
func (a *APIKey) GetStatus() APIKeyStatus
GetStatus returns the current status of the API key.
type APIKeyStatus ¶
type APIKeyStatus string
const ( StatusActive APIKeyStatus = "active" StatusRevoked APIKeyStatus = "revoked" StatusExpired APIKeyStatus = "expired" )
Click to show internal directories.
Click to hide internal directories.