mirror of
https://github.com/Luzifer/dns.git
synced 2024-12-22 10:51:20 +00:00
Load zones to manage from consul
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
5e6e526b55
commit
cf908822be
3 changed files with 29 additions and 78 deletions
26
consul.py
26
consul.py
|
@ -4,6 +4,32 @@ import os
|
|||
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):
|
||||
if os.getenv('CONSUL_HTTP_ADDR') == '' or os.getenv('CONSUL_HTTP_TOKEN') == '':
|
||||
raise Exception(
|
||||
|
|
|
@ -134,6 +134,9 @@ def write_zone(zone, ttl, soa, nameserver, mailserver, entries):
|
|||
def main():
|
||||
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():
|
||||
ttl = default(config, "default_ttl", DEFAULT_TTL)
|
||||
|
||||
|
|
78
zones.yml
78
zones.yml
|
@ -16,84 +16,6 @@ nameserver:
|
|||
- ns3.kserver.biz.
|
||||
|
||||
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:
|
||||
entries:
|
||||
- name: health
|
||||
|
|
Loading…
Reference in a new issue