1
0
Fork 0
mirror of https://github.com/Luzifer/dns.git synced 2024-12-23 03:11:20 +00:00

Load zones to manage from consul

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-12-15 01:30:22 +01:00
parent 5e6e526b55
commit cf908822be
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
3 changed files with 29 additions and 78 deletions

View file

@ -4,6 +4,32 @@ import os
import requests import requests
def get_zones():
if os.getenv('CONSUL_HTTP_ADDR') == '' or os.getenv('CONSUL_HTTP_TOKEN') == '':
raise Exception(
'Consul query does not work with CONSUL_HTTP_ADDR or CONSUL_HTTP_TOKEN unset')
resp = requests.get(
'{}/v1/kv/dns?keys=true'.format(
os.getenv('CONSUL_HTTP_ADDR'),
),
headers={
'X-Consul-Token': os.getenv('CONSUL_HTTP_TOKEN'),
}
)
if resp.status_code == 404:
return []
zones = {}
for key in resp.json():
zone = key.split('/')[1]
if zone not in zones:
zones[zone] = {'from_consul': True}
return zones
def query_zone_entries(zone): def query_zone_entries(zone):
if os.getenv('CONSUL_HTTP_ADDR') == '' or os.getenv('CONSUL_HTTP_TOKEN') == '': if os.getenv('CONSUL_HTTP_ADDR') == '' or os.getenv('CONSUL_HTTP_TOKEN') == '':
raise Exception( raise Exception(

View file

@ -134,6 +134,9 @@ def write_zone(zone, ttl, soa, nameserver, mailserver, entries):
def main(): def main():
zone_data = yaml.load(open("zones.yml")) zone_data = yaml.load(open("zones.yml"))
consul_zones = consul.get_zones()
zone_data['zones'] = {**consul_zones, **zone_data['zones']}
for zone, config in zone_data['zones'].items(): for zone, config in zone_data['zones'].items():
ttl = default(config, "default_ttl", DEFAULT_TTL) ttl = default(config, "default_ttl", DEFAULT_TTL)

View file

@ -16,84 +16,6 @@ nameserver:
- ns3.kserver.biz. - ns3.kserver.biz.
zones: zones:
2k0.de:
from_consul: true
ahlers.me:
from_consul: true
ahlers.space:
from_consul: true
ahlers.tk:
from_consul: true
badges.fyi:
from_consul: true
cloudkeys.de:
from_consul: true
holiday-api.fyi:
from_consul: true
k9s.me:
from_consul: true
kahlers.biz:
from_consul: true
kahlers.de:
from_consul: true
knut-ahlers.de:
from_consul: true
knut.cc:
from_consul: true
knut.in:
from_consul: true
knut.me:
from_consul: true
knut.page:
from_consul: true
knut.so:
from_consul: true
knut.work:
from_consul: true
knut.ws:
from_consul: true
knutahlers.de:
from_consul: true
knutshome.de:
from_consul: true
luzifer.cc:
from_consul: true
luzifer.io:
from_consul: true
luzifer.link:
from_consul: true
luzifer.rip:
from_consul: true
mondash.org:
from_consul: true
ots.fyi:
from_consul: true
server.test: server.test:
entries: entries:
- name: health - name: health