Commit 3e53f9c9 authored by Aleš Mrázek's avatar Aleš Mrázek
Browse files

update parser and kresd_conf_gen

parent d31abf98
......@@ -21,8 +21,6 @@ All Modules are located in ``yang-modules/`` project directory.
Data Model
=============
Data Model is located in ``data-model/`` project directory.
* `Current schema tree`_
* `Example JSON data`_
......
......@@ -23,31 +23,31 @@ def generate(config: dict) -> str:
if 'network' in conf:
if kresd_conf != "":
kresd_conf += "\n"
kresd_conf += Network.generate(conf['network'])
kresd_conf += Network.generate(conf['network'].value)
if 'server' in conf:
if kresd_conf != "":
kresd_conf += "\n"
kresd_conf += Server.generate(conf['server'])
kresd_conf += Server.generate(conf['server'].value)
if 'resolver' in conf:
if kresd_conf != "":
kresd_conf += "\n"
kresd_conf += Resolver.generate(conf['resolver'])
kresd_conf += Resolver.generate(conf['resolver'].value)
if 'logging' in conf:
if kresd_conf != "":
kresd_conf += "\n"
kresd_conf += Logging.generate(conf['logging'])
kresd_conf += Logging.generate(conf['logging'].value)
if 'dnssec' in conf:
if kresd_conf != "":
kresd_conf += "\n"
kresd_conf += Dnssec.generate(conf['dnssec'])
kresd_conf += Dnssec.generate(conf['dnssec'].value)
if 'cache' in conf:
if kresd_conf != "":
kresd_conf += "\n"
kresd_conf += Cache.generate(conf['cache'])
kresd_conf += Cache.generate(conf['cache'].value)
if 'dns64' in conf:
if kresd_conf != "":
kresd_conf += "\n"
kresd_conf += Dns64.generate(conf['dns64'])
kresd_conf += Dns64.generate(conf['dns64'].value)
return kresd_conf
......@@ -57,7 +57,7 @@ class Server:
@staticmethod
def generate(server: dict) -> str:
server_conf = ""
server_conf += Server.username(server['user-name'].value, server['group-name'].value)
server_conf += Server.username(server['user-name'], server['group-name'])
return server_conf
......@@ -80,19 +80,19 @@ class Network:
if 'listen-interfaces' in network:
if network_conf != "":
network_conf += "\n"
network_conf += Network.listen_interfaces(network['listen-interfaces'])
network_conf += Network.listen_interfaces(network['listen-interfaces'].value)
if 'source-address' in network:
if network_conf != "":
network_conf += "\n"
network_conf += Network.source_address(network['source-address'])
network_conf += Network.source_address(network['source-address'].value)
if 'recursion-transport' in network:
if network_conf != "":
network_conf += "\n"
network_conf += Network.recursion_transport(network['recursion-transport'])
network_conf += Network.recursion_transport(network['recursion-transport'].value)
if 'udp-payload-size' in network:
if network_conf != "":
network_conf += "\n"
network_conf += Network.udp_payload_size(network['udp-payload-size'])
network_conf += Network.udp_payload_size(network['udp-payload-size'].value)
return network_conf
......@@ -186,66 +186,70 @@ class Resolver:
if 'stub-zones' in resolver:
if resolver_conf != "":
resolver_conf += "\n"
resolver_conf += Resolver.stub_zones(resolver['stub-zones'])
resolver_conf += Resolver.stub_zones(resolver['stub-zones'].value)
# hints
if 'hints' in resolver:
hints = resolver['hints']
if 'cznic-resolver-knot:hint' in hints:
if resolver_conf != "":
resolver_conf += "\n"
resolver_conf += Resolver.hints_hint(hints['cznic-resolver-knot:hint'])
resolver_conf += Resolver.hints_hint(hints['cznic-resolver-knot:hint'].value)
if 'cznic-resolver-knot:hosts-file' in hints:
if resolver_conf != "":
resolver_conf += "\n"
resolver_conf += Resolver.hints_hosts_file(hints['cznic-resolver-knot:hosts-file'])
resolver_conf += Resolver.hints_hosts_file(hints['cznic-resolver-knot:hosts-file'].value)
if 'root-hint' in hints:
if resolver_conf != "":
resolver_conf += "\n"
resolver_conf += Resolver.hints_root_hint(hints['root-hint'])
resolver_conf += Resolver.hints_root_hint(hints['root-hint'].value)
if 'root-zone-file' in hints:
if resolver_conf != "":
resolver_conf += "\n"
resolver_conf += Resolver.hints_root_zone_file(hints['root-zone-file'])
resolver_conf += Resolver.hints_root_zone_file(hints['root-zone-file'].value)
# options
if 'options' in resolver:
options = resolver['options']
if 'glue-checking' in options:
if resolver_conf != "":
resolver_conf += "\n"
resolver_conf += Resolver.option_glue_checking(options['glue-checking'])
resolver_conf += Resolver.option_glue_checking(options['glue-checking'].value)
if 'qname-minimisation' in options:
if resolver_conf != "":
resolver_conf += "\n"
resolver_conf += Resolver.option_qname_minimisation(options['qname-minimisation'])
resolver_conf += Resolver.option_qname_minimisation(options['qname-minimisation'].value)
if 'reorder-rrset' in options:
if resolver_conf != "":
resolver_conf += "\n"
resolver_conf += Resolver.option_reorder_rrset(options['reorder-rrset'])
resolver_conf += Resolver.option_reorder_rrset(options['reorder-rrset'].value)
if 'query-loopback' in options:
if resolver_conf != "":
resolver_conf += "\n"
resolver_conf += Resolver.option_query_loopback(options['query-loopback'])
resolver_conf += Resolver.option_query_loopback(options['query-loopback'].value)
return resolver_conf
@staticmethod
def stub_zones(zones: list) -> str:
# TODO: Unbound can resolve host name Kresd can not.
#conf_strings = [str]
conf_string = ""
# TODO: not DONE
# for zone in zones:
#
# if ipv4_address.match(str(zone["nameserver"])) or ipv6_address.match(str(zone["nameserver"])):
# nameserver = zone['nameserver']
# else:
# nameserver = gethostbyname(str(zone["nameserver"]))
#
# if 'port' in zone:
# address = "{0}@{1}".format(nameserver, str(zone['port']))
# else:
# address = nameserver
#
# conf_string += "policy.add(policy.suffix(policy.STUB('" + address + "'), " \
# "{todname('" + zone['domain'] + "')}))"
for zone in zones:
# if ipv4_address.match(str(zone["nameserver"])) or ipv6_address.match(str(zone["nameserver"])):
# nameserver = zone['nameserver']
# else:
# nameserver = gethostbyname(str(zone["nameserver"]))
if 'port' in zone:
address = "{0}@{1}".format(zone["nameserver"], str(zone['port']))
else:
address = zone["nameserver"]
if conf_string is not "":
conf_string += "\n"
#conf_strings.append("policy.add(policy.suffix(policy.STUB('{0}'), {policy.todname('{1}')}))".format(address, zone['domain']))
conf_string += "policy.add(policy.suffix(policy.STUB('{0}'), " \
"{policy.todname('{1}')}))".format(address, zone['domain'])
return conf_string
......@@ -429,20 +433,22 @@ class Dnssec:
if 'trust-anchors' in dnssec:
if dnssec_conf != "":
dnssec_conf += "\n"
dnssec_conf += Dnssec.trust_anchors(dnssec['trust-anchors'])
dnssec_conf += Dnssec.trust_anchors(dnssec['trust-anchors'].value)
if 'negative-trust-anchors' in dnssec:
if dnssec_conf != "":
dnssec_conf += "\n"
dnssec_conf += Dnssec.negative_trust_anchors(dnssec['negative-trust-anchors'])
dnssec_conf += Dnssec.negative_trust_anchors(dnssec['negative-trust-anchors'].value)
return dnssec_conf
@staticmethod
def trust_anchors(trust_anchors: list):
conf_string = ""
# TODO: not sure if it is right
for trust_anchor in trust_anchors:
if trust_anchor['auto-update']:
break
if 'trust-anchor' in trust_anchor:
for ta in trust_anchor['trust-anchor']:
if 'ds' in ta:
......@@ -474,19 +480,19 @@ class Cache:
if 'max-size' in cache:
if cache_conf != "":
cache_conf += "\n"
cache_conf += Cache.max_size(cache['max-size'])
cache_conf += Cache.max_size(cache['max-size'].value)
if 'max-ttl' in cache:
if cache_conf != "":
cache_conf += "\n"
cache_conf += Cache.max_ttl(cache['max-ttl'])
cache_conf += Cache.max_ttl(cache['max-ttl'].value)
if 'min-ttl' in cache:
if cache_conf != "":
cache_conf += "\n"
cache_conf += Cache.min_ttl(cache['min-ttl'])
cache_conf += Cache.min_ttl(cache['min-ttl'].value)
if 'cznic-resolver-knot:prefill' in cache:
if cache_conf != "":
cache_conf += "\n"
cache_conf += Cache.prefill(cache['cznic-resolver-knot:prefill'])
cache_conf += Cache.prefill(cache['cznic-resolver-knot:prefill'].value)
return cache_conf
......
......@@ -140,11 +140,11 @@ class TrustAnchorRR:
dnskey_str = "{0} IN DNSKEY {1} {2} {3} {4}".format(domain,
flags,
dnskey_ta['protocol'], algorithm,
dnskey_ta['public-key'])
dnskey_ta['public-key'].decode('ascii'))
else:
dnskey_str = "{0} IN DNSKEY {1} {2} {3}".format(domain,
dnskey_ta['protocol'], algorithm,
dnskey_ta['public-key'])
dnskey_ta['public-key'].decode('ascii'))
return dnskey_str
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment