From 07739ee84eefac53317fac338a50453c41277e95 Mon Sep 17 00:00:00 2001
From: Jamie Curnow <jc@jc21.com>
Date: Wed, 1 Jun 2022 09:02:57 +0400
Subject: [PATCH] dns_azure

---
 backend/internal/dnsproviders/common.go      |  1 +
 backend/internal/dnsproviders/dns_autodns.go |  2 +-
 backend/internal/dnsproviders/dns_azure.go   | 70 ++++++++++++++++++++
 frontend/src/locale/src/en.json              |  3 +
 4 files changed, 75 insertions(+), 1 deletion(-)
 create mode 100644 backend/internal/dnsproviders/dns_azure.go

diff --git a/backend/internal/dnsproviders/common.go b/backend/internal/dnsproviders/common.go
index 1689263..a0bf963 100644
--- a/backend/internal/dnsproviders/common.go
+++ b/backend/internal/dnsproviders/common.go
@@ -40,6 +40,7 @@ func List() []Provider {
 		getDNSAli(),
 		getDNSAws(),
 		getDNSAutoDNS(),
+		getDNSAzure(),
 		getDNSCf(),
 		getDNSCloudns(),
 		getDNSCx(),
diff --git a/backend/internal/dnsproviders/dns_autodns.go b/backend/internal/dnsproviders/dns_autodns.go
index da610d6..e593b89 100644
--- a/backend/internal/dnsproviders/dns_autodns.go
+++ b/backend/internal/dnsproviders/dns_autodns.go
@@ -48,7 +48,7 @@ func getDNSAutoDNS() Provider {
 			},
 			{
 				Name:       "Context",
-				Type:       "string",
+				Type:       "text",
 				MetaKey:    "context",
 				EnvKey:     "AUTODNS_CONTEXT",
 				IsRequired: true,
diff --git a/backend/internal/dnsproviders/dns_azure.go b/backend/internal/dnsproviders/dns_azure.go
new file mode 100644
index 0000000..69c3fb9
--- /dev/null
+++ b/backend/internal/dnsproviders/dns_azure.go
@@ -0,0 +1,70 @@
+package dnsproviders
+
+const azureSchema = `
+{
+	"type": "object",
+	"required": [
+		"subscription_id",
+		"tenant_id",
+		"app_id",
+		"client_secret"
+	],
+	"additionalProperties": false,
+	"properties": {
+		"subscription_id": {
+			"type": "string",
+			"minLength": 1
+		},
+		"tenant_id": {
+			"type": "string",
+			"minLength": 1
+		},
+		"app_id": {
+			"type": "string",
+			"minLength": 1
+		},
+		"client_secret": {
+			"type": "string",
+			"minLength": 1
+		}
+	}
+}
+`
+
+func getDNSAzure() Provider {
+	return Provider{
+		AcmeshName: "dns_azure",
+		Schema:     azureSchema,
+		Fields: []providerField{
+			{
+				Name:       "Subscription ID",
+				Type:       "text",
+				MetaKey:    "subscription_id",
+				EnvKey:     "AZUREDNS_SUBSCRIPTIONID",
+				IsRequired: true,
+			},
+			{
+				Name:       "Tenant ID",
+				Type:       "text",
+				MetaKey:    "tenant_id",
+				EnvKey:     "AZUREDNS_TENANTID",
+				IsRequired: true,
+			},
+			{
+				Name:       "APP ID",
+				Type:       "text",
+				MetaKey:    "app_id",
+				EnvKey:     "AZUREDNS_APPID",
+				IsRequired: true,
+			},
+			{
+				Name:       "Client Secret",
+				Type:       "password",
+				MetaKey:    "client_secret",
+				EnvKey:     "AZUREDNS_CLIENTSECRET",
+				IsRequired: true,
+				IsSecret:   true,
+			},
+		},
+	}
+}
diff --git a/frontend/src/locale/src/en.json b/frontend/src/locale/src/en.json
index fb06c23..2eb1c9a 100644
--- a/frontend/src/locale/src/en.json
+++ b/frontend/src/locale/src/en.json
@@ -14,6 +14,9 @@
 	"acmesh.dns_autodns": {
 		"defaultMessage": "autoDNS (InternetX)"
 	},
+	"acmesh.dns_azure": {
+		"defaultMessage": "Azure"
+	},
 	"acmesh.dns_cf": {
 		"defaultMessage": "Cloudflare"
 	},