1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-24 10:07:21 +02:00
woodpecker/plugins/sender/plugin.go

53 lines
1.5 KiB
Go
Raw Normal View History

package sender
import (
"fmt"
2019-08-27 13:01:29 +02:00
"github.com/laszlocph/woodpecker/model"
"github.com/laszlocph/woodpecker/plugins/internal"
)
type plugin struct {
endpoint string
}
// NewRemote returns a new remote gating service.
func NewRemote(endpoint string) model.SenderService {
return &plugin{endpoint}
}
2017-05-05 19:13:40 +02:00
func (p *plugin) SenderAllowed(user *model.User, repo *model.Repo, build *model.Build, conf *model.Config) (bool, error) {
path := fmt.Sprintf("%s/senders/%s/%s/%s/verify", p.endpoint, repo.Owner, repo.Name, build.Sender)
data := map[string]interface{}{
2018-03-21 15:02:17 +02:00
"build": build,
"config": conf,
}
err := internal.Send("POST", path, &data, nil)
if err != nil {
return false, err
}
return true, err
}
func (p *plugin) SenderCreate(repo *model.Repo, sender *model.Sender) error {
path := fmt.Sprintf("%s/senders/%s/%s", p.endpoint, repo.Owner, repo.Name)
return internal.Send("POST", path, sender, nil)
}
func (p *plugin) SenderUpdate(repo *model.Repo, sender *model.Sender) error {
path := fmt.Sprintf("%s/senders/%s/%s", p.endpoint, repo.Owner, repo.Name)
return internal.Send("PUT", path, sender, nil)
}
func (p *plugin) SenderDelete(repo *model.Repo, login string) error {
path := fmt.Sprintf("%s/senders/%s/%s/%s", p.endpoint, repo.Owner, repo.Name, login)
return internal.Send("DELETE", path, nil, nil)
}
func (p *plugin) SenderList(repo *model.Repo) ([]*model.Sender, error) {
path := fmt.Sprintf("%s/senders/%s/%s", p.endpoint, repo.Owner, repo.Name)
out := []*model.Sender{}
err := internal.Send("GET", path, nil, out)
return out, err
}