-
Notifications
You must be signed in to change notification settings - Fork 0
/
caddyfile.go
54 lines (50 loc) · 1.35 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
package caddy_saml_sso
import (
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
)
func init() {
httpcaddyfile.RegisterHandlerDirective("saml_sso", parseCaddyfile)
}
// UnmarshalCaddyfile implements caddyfile.Unmarshaler.
func (m *Middleware) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
for d.Next() {
// token value
parameter := d.Val()
// rest of params
args := d.RemainingArgs()
switch parameter {
case "saml_idp_url":
if len(args) != 1 {
return d.Err("invalid saml_idp_url")
}
m.SamlIdpUrl = args[0]
case "saml_cert_file":
if len(args) != 1 {
return d.Err("invalid saml_cert_file")
}
m.SamlCertFile = args[0]
case "saml_key_file":
if len(args) != 1 {
return d.Err("invalid saml_key_file")
}
m.SamlKeyFile = args[0]
case "saml_root_url":
if len(args) != 1 {
return d.Err("invalid saml_root_url")
}
m.SamlRootUrl = args[0]
default:
//d.Err("Unknow cam parameter: " + parameter)
log("skipping: %s %v", parameter, args)
}
}
return nil
}
// parseCaddyfile unmarshals tokens from h into a new Middleware.
func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) {
var m Middleware
err := m.UnmarshalCaddyfile(h.Dispenser)
return m, err
}