Refactor AgentFindByToken (#1891)

followup of #1890
This commit is contained in:
6543 2023-06-28 06:59:58 +02:00 committed by GitHub
parent b57b6f27f6
commit e1c31df6c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -20,6 +20,8 @@ import (
"github.com/woodpecker-ci/woodpecker/server/model"
)
var ErrNoTokenProvided = errors.New("Please provide a token")
func (s storage) AgentList(p *model.ListOptions) ([]*model.Agent, error) {
var agents []*model.Agent
return agents, s.paginate(p).Find(&agents)
@ -33,12 +35,10 @@ func (s storage) AgentFind(id int64) (*model.Agent, error) {
func (s storage) AgentFindByToken(token string) (*model.Agent, error) {
// Searching with an empty token would result in an empty where clause and therefore returning first item
if token == "" {
return nil, errors.New("Please provide a token")
return nil, ErrNoTokenProvided
}
agent := &model.Agent{
Token: token,
}
return agent, wrapGet(s.engine.Get(agent))
agent := new(model.Agent)
return agent, wrapGet(s.engine.Where("token = ?", token).Get(agent))
}
func (s storage) AgentCreate(agent *model.Agent) error {