Add dns-config module for Mail-in-a-Box DNS management and Azure integration

This commit is contained in:
2026-04-12 22:06:24 +02:00
parent d9b1b5f869
commit c5170e67b0
6 changed files with 205 additions and 0 deletions

15
dns-config/azure.py Normal file
View File

@@ -0,0 +1,15 @@
from azure.identity import DefaultAzureCredential
from azure.mgmt.dns import DnsManagementClient
import os
AZURE_SUBSCRIPTION_ID = os.environ.get("AZURE_SUBSCRIPTION_ID", None)
def get_dns_nameservers(resource_group_name: str, zone_name: str, azure_subscription_id: str | None = None) -> list[str]:
try:
creds = DefaultAzureCredential()
dns_client = DnsManagementClient(creds, azure_subscription_id or AZURE_SUBSCRIPTION_ID)
zone = dns_client.zones.get(resource_group_name, zone_name)
return zone.name_servers
except Exception as e:
print(f"Error fetching DNS nameservers: {e}")
return []