This repository was archived by the owner on Feb 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.go
More file actions
97 lines (87 loc) · 1.92 KB
/
setup.go
File metadata and controls
97 lines (87 loc) · 1.92 KB
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
package plugin
import (
"github.com/coredns/caddy"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
"github.com/gophercloud/gophercloud"
)
func init() {
caddy.RegisterPlugin("openstack", caddy.Plugin{
ServerType: "dns",
Action: setup,
})
}
func setup(c *caddy.Controller) error {
os, err := openstackParse(c)
if err != nil {
return plugin.Error("openstack", err)
}
config := dnsserver.GetConfig(c)
os.Zone = config.Zone
c.OnStartup(func() error {
go os.runFetchEntries(os.Entries)
return nil
})
config.AddPlugin(func(next plugin.Handler) plugin.Handler {
return os
})
return nil
}
func openstackParse(c *caddy.Controller) (*OpenStack, error) {
entries := make(DNSEntries)
authOpts := gophercloud.AuthOptions{
Username: "coredns",
DomainName: "default",
}
os := OpenStack{
Region: "RegionOne",
EnableWildcard: false,
}
os.Entries = &entries
os.AuthOptions = &authOpts
for c.Next() {
for c.NextBlock() {
switch c.Val() {
case "auth_url":
args := c.RemainingArgs()
if len(args) != 1 {
return nil, c.ArgErr()
}
authOpts.IdentityEndpoint = args[0]
case "username":
args := c.RemainingArgs()
if len(args) != 1 {
return nil, c.ArgErr()
}
authOpts.Username = args[0]
case "password":
args := c.RemainingArgs()
if len(args) != 1 {
return nil, c.ArgErr()
}
authOpts.Password = args[0]
case "domain_name":
args := c.RemainingArgs()
if len(args) != 1 {
return nil, c.ArgErr()
}
authOpts.DomainName = args[0]
case "region":
args := c.RemainingArgs()
if len(args) != 1 {
return nil, c.ArgErr()
}
os.Region = args[0]
case "wildcard":
args := c.RemainingArgs()
if len(args) != 0 {
return nil, c.ArgErr()
}
os.EnableWildcard = true
default:
return nil, c.Errf("unknown property '%s'", c.Val())
}
}
}
return &os, nil
}