-
Notifications
You must be signed in to change notification settings - Fork 4
/
caddyfile.go
104 lines (98 loc) · 1.97 KB
/
caddyfile.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package caddy_webhook
import (
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
)
func parseHandlerCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) {
wh := new(WebHook)
err := wh.UnmarshlCaddyfile(h.Dispenser)
if err != nil {
return nil, err
}
return wh, nil
}
// UnmarshCaddyfile configures the handler directive from Caddyfile.
// Syntax:
//
// webhook [<url> <path>] {
// repo <text>
// path <text>
// branch <text>
// depth <int>
// type <text>
// secret <text>
// command <text>...
// key <text>
// username <text>
// password <text>
// token <text>
// submodule
// }
func (w *WebHook) UnmarshlCaddyfile(d *caddyfile.Dispenser) error {
if d.NextArg() && d.NextArg() {
w.Repository = d.Val()
}
if d.NextArg() {
w.Path = d.Val()
}
for d.NextBlock(0) {
switch d.Val() {
case "repo":
if w.Repository != "" {
return d.Err("url specified twice")
}
if !d.Args(&w.Repository) {
return d.ArgErr()
}
case "path":
if w.Path != "" {
return d.Err("path specified twice")
}
if !d.Args(&w.Path) {
return d.ArgErr()
}
case "branch":
if !d.Args(&w.Branch) {
return d.ArgErr()
}
case "depth":
if !d.Args(&w.Depth) {
return d.ArgErr()
}
case "type":
if !d.Args(&w.Type) {
return d.ArgErr()
}
case "secret":
if !d.Args(&w.Secret) {
return d.ArgErr()
}
case "submodule":
w.Submodule = true
case "command":
w.Command = d.RemainingArgs()
case "key":
if !d.Args(&w.Key) {
return d.ArgErr()
}
case "key_password":
if !d.Args(&w.KeyPassword) {
return d.ArgErr()
}
case "username":
if !d.Args(&w.Username) {
return d.ArgErr()
}
case "password":
if !d.Args(&w.Password) {
return d.ArgErr()
}
case "token":
if !d.Args(&w.Token) {
return d.ArgErr()
}
}
}
return nil
}