2017-04-11 17:06:45 +00:00
|
|
|
package sender
|
|
|
|
|
|
|
|
import (
|
2021-09-28 10:56:59 +00:00
|
|
|
"context"
|
2017-04-11 17:06:45 +00:00
|
|
|
"fmt"
|
|
|
|
|
2021-09-27 17:51:55 +00:00
|
|
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
2021-09-23 14:12:46 +00:00
|
|
|
"github.com/woodpecker-ci/woodpecker/server/plugins/internal"
|
2017-04-11 17:06:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type plugin struct {
|
|
|
|
endpoint string
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewRemote returns a new remote gating service.
|
|
|
|
func NewRemote(endpoint string) model.SenderService {
|
|
|
|
return &plugin{endpoint}
|
|
|
|
}
|
|
|
|
|
2017-05-05 17:13:40 +00:00
|
|
|
func (p *plugin) SenderAllowed(user *model.User, repo *model.Repo, build *model.Build, conf *model.Config) (bool, error) {
|
2017-04-14 08:41:24 +00:00
|
|
|
path := fmt.Sprintf("%s/senders/%s/%s/%s/verify", p.endpoint, repo.Owner, repo.Name, build.Sender)
|
2017-07-18 15:53:06 +00:00
|
|
|
data := map[string]interface{}{
|
2018-03-21 13:02:17 +00:00
|
|
|
"build": build,
|
2017-07-18 15:53:06 +00:00
|
|
|
"config": conf,
|
|
|
|
}
|
2021-09-28 10:56:59 +00:00
|
|
|
err := internal.Send(context.TODO(), "POST", path, &data, nil)
|
2017-04-11 17:06:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
2017-04-12 11:04:39 +00:00
|
|
|
return true, err
|
2017-04-11 17:06:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *plugin) SenderCreate(repo *model.Repo, sender *model.Sender) error {
|
2017-04-14 08:41:24 +00:00
|
|
|
path := fmt.Sprintf("%s/senders/%s/%s", p.endpoint, repo.Owner, repo.Name)
|
2021-09-28 10:56:59 +00:00
|
|
|
return internal.Send(context.TODO(), "POST", path, sender, nil)
|
2017-04-11 17:06:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *plugin) SenderUpdate(repo *model.Repo, sender *model.Sender) error {
|
2017-04-14 08:41:24 +00:00
|
|
|
path := fmt.Sprintf("%s/senders/%s/%s", p.endpoint, repo.Owner, repo.Name)
|
2021-09-28 10:56:59 +00:00
|
|
|
return internal.Send(context.TODO(), "PUT", path, sender, nil)
|
2017-04-11 17:06:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *plugin) SenderDelete(repo *model.Repo, login string) error {
|
2017-04-14 08:41:24 +00:00
|
|
|
path := fmt.Sprintf("%s/senders/%s/%s/%s", p.endpoint, repo.Owner, repo.Name, login)
|
2021-09-28 10:56:59 +00:00
|
|
|
return internal.Send(context.TODO(), "DELETE", path, nil, nil)
|
2017-04-11 17:06:45 +00:00
|
|
|
}
|
|
|
|
|
2021-09-24 14:29:26 +00:00
|
|
|
func (p *plugin) SenderList(repo *model.Repo) (out []*model.Sender, err error) {
|
2017-04-14 08:41:24 +00:00
|
|
|
path := fmt.Sprintf("%s/senders/%s/%s", p.endpoint, repo.Owner, repo.Name)
|
2021-09-28 10:56:59 +00:00
|
|
|
err = internal.Send(context.TODO(), "GET", path, nil, out)
|
2017-04-11 17:06:45 +00:00
|
|
|
return out, err
|
|
|
|
}
|