Некоторые проверки не удались
CI / test (push) Successful in 2m5s
Docker / Build and publish worker image (push) Failing after 31s
39 строки
990 B
Go
39 строки
990 B
Go
package models
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
|
|
"rocketgit.ru/rsmon/worker/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
|
|
}
|
|
}
|