forked from harness/harness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.go
52 lines (43 loc) · 1.51 KB
/
plugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package sender
import (
"fmt"
"github.com/drone/drone/model"
"github.com/drone/drone/plugins/internal"
)
type plugin struct {
endpoint string
}
// NewRemote returns a new remote gating service.
func NewRemote(endpoint string) model.SenderService {
return &plugin{endpoint}
}
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{}{
"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
}