feat: publish standalone worker
Separate worker packaging and service lifecycle from the control plane.
Этот коммит содержится в:
38
app/models/api_key.go
Обычный файл
38
app/models/api_key.go
Обычный файл
@@ -0,0 +1,38 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
|
||||
"rsgit.ru/rsmon/rsmon/app/models/concerns"
|
||||
)
|
||||
|
||||
// ApiKey represents an API authentication key. //nolint:revive // accepted lint exception
|
||||
type ApiKey struct { //nolint:revive // accepted lint exception
|
||||
concerns.Model
|
||||
|
||||
Name string `json:"name" gorm:"not null"`
|
||||
AccountID int64 `json:"account_id,omitempty"`
|
||||
Account User `json:"-"`
|
||||
UserID *int64 `gorm:"type:bigint REFERENCES users(id)" json:"-"`
|
||||
User *User `json:"-"`
|
||||
Accesses []Access `json:"accesses" gorm:"foreignkey:api_key_id"`
|
||||
|
||||
concerns.HasToken
|
||||
concerns.Timestamped
|
||||
Audited
|
||||
}
|
||||
|
||||
func (n *ApiKey) BeforeCreate(tx *gorm.DB) error { //nolint:revive // accepted lint exception
|
||||
n.SetToken()
|
||||
return nil
|
||||
}
|
||||
|
||||
// FillAccesses provides functionality.
|
||||
func (n *ApiKey) FillAccesses() {
|
||||
for k, a := range n.Accesses { //nolint:gocritic // range copy is acceptable here
|
||||
if a.ID <= 0 {
|
||||
n.Accesses[k].ID = 0
|
||||
}
|
||||
n.Accesses[k].AccountID = n.AccountID
|
||||
}
|
||||
}
|
||||
Ссылка в новой задаче
Block a user