aboutsummaryrefslogtreecommitdiff
path: root/plugin/azure/setup.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2019-08-09 16:10:26 +0100
committerGravatar Yong Tang <yong.tang.github@outlook.com> 2019-08-09 08:10:26 -0700
commit1bb753c5b0bf8048f6cf704c92b493c535ef3b0c (patch)
treeae38b163d46c888f255f0b4ee831fc48a5954f2b /plugin/azure/setup.go
parent879466b0288a2d11e278950375c7593b60ea0677 (diff)
downloadcoredns-1bb753c5b0bf8048f6cf704c92b493c535ef3b0c.tar.gz
coredns-1bb753c5b0bf8048f6cf704c92b493c535ef3b0c.tar.zst
coredns-1bb753c5b0bf8048f6cf704c92b493c535ef3b0c.zip
plugin/azure: clean up readme (#3102)
document the environment option and some cleanups. Go over the code and fix/tweak random bits here and there. Condense a few lines here and there. Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'plugin/azure/setup.go')
-rw-r--r--plugin/azure/setup.go36
1 files changed, 19 insertions, 17 deletions
diff --git a/plugin/azure/setup.go b/plugin/azure/setup.go
index 1ac0cc723..ef5711c00 100644
--- a/plugin/azure/setup.go
+++ b/plugin/azure/setup.go
@@ -8,7 +8,6 @@ import (
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/pkg/fall"
clog "github.com/coredns/coredns/plugin/pkg/log"
- "github.com/coredns/coredns/plugin/pkg/upstream"
azuredns "github.com/Azure/azure-sdk-for-go/profiles/latest/dns/mgmt/dns"
azurerest "github.com/Azure/go-autorest/autorest/azure"
@@ -31,19 +30,21 @@ func setup(c *caddy.Controller) error {
return plugin.Error("azure", err)
}
ctx := context.Background()
+
dnsClient := azuredns.NewRecordSetsClient(env.Values[auth.SubscriptionID])
- dnsClient.Authorizer, err = env.GetAuthorizer()
- if err != nil {
- return c.Errf("failed to create azure plugin: %v", err)
+ if dnsClient.Authorizer, err = env.GetAuthorizer(); err != nil {
+ return plugin.Error("azure", err)
}
- h, err := New(ctx, dnsClient, keys, upstream.New())
+
+ h, err := New(ctx, dnsClient, keys)
if err != nil {
- return c.Errf("failed to initialize azure plugin: %v", err)
+ return plugin.Error("azure", err)
}
h.Fall = fall
if err := h.Run(ctx); err != nil {
- return c.Errf("failed to run azure plugin: %v", err)
+ return plugin.Error("azure", err)
}
+
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
h.Next = next
return h
@@ -54,26 +55,25 @@ func setup(c *caddy.Controller) error {
func parse(c *caddy.Controller) (auth.EnvironmentSettings, map[string][]string, fall.F, error) {
resourceGroupMapping := map[string][]string{}
resourceGroupSet := map[string]struct{}{}
- var err error
- var fall fall.F
-
azureEnv := azurerest.PublicCloud
env := auth.EnvironmentSettings{Values: map[string]string{}}
+ var fall fall.F
+
for c.Next() {
args := c.RemainingArgs()
for i := 0; i < len(args); i++ {
parts := strings.SplitN(args[i], ":", 2)
if len(parts) != 2 {
- return env, resourceGroupMapping, fall, c.Errf("invalid resource group / zone '%s'", args[i])
+ return env, resourceGroupMapping, fall, c.Errf("invalid resource group/zone: %q", args[i])
}
resourceGroup, zoneName := parts[0], parts[1]
if resourceGroup == "" || zoneName == "" {
- return env, resourceGroupMapping, fall, c.Errf("invalid resource group / zone '%s'", args[i])
+ return env, resourceGroupMapping, fall, c.Errf("invalid resource group/zone: %q", args[i])
}
if _, ok := resourceGroupSet[args[i]]; ok {
- return env, resourceGroupMapping, fall, c.Errf("conflict zone '%s'", args[i])
+ return env, resourceGroupMapping, fall, c.Errf("conflicting zone: %q", args[i])
}
resourceGroupSet[args[i]] = struct{}{}
@@ -106,18 +106,20 @@ func parse(c *caddy.Controller) (auth.EnvironmentSettings, map[string][]string,
return env, resourceGroupMapping, fall, c.ArgErr()
}
env.Values[auth.ClientSecret] = c.Val()
- azureEnv, err = azurerest.EnvironmentFromName(c.Val())
- if err != nil {
- return env, resourceGroupMapping, fall, c.Errf("cannot set azure environment: %s", err.Error())
+ var err error
+ if azureEnv, err = azurerest.EnvironmentFromName(c.Val()); err != nil {
+ return env, resourceGroupMapping, fall, c.Errf("cannot set azure environment: %q", err.Error())
}
case "fallthrough":
fall.SetZonesFromArgs(c.RemainingArgs())
default:
- return env, resourceGroupMapping, fall, c.Errf("unknown property '%s'", c.Val())
+ return env, resourceGroupMapping, fall, c.Errf("unknown property: %q", c.Val())
}
}
}
+
env.Values[auth.Resource] = azureEnv.ResourceManagerEndpoint
env.Environment = azureEnv
+
return env, resourceGroupMapping, fall, nil
}