Commit d31abf98 authored by Aleš Mrázek's avatar Aleš Mrázek

changed library structure; examples and docs corrections due to library structure changes

parent f9e683f3
Pipeline #45219 passed with stages
in 1 minute and 5 seconds
......@@ -16,20 +16,23 @@ Data model and library for DNS resolvers:
* [Example JSON data](https://gitlab.labs.nic.cz/labs/resolvers-yang/raw/master/examples/example-data.json)
#### YANG Modules
* [cznic-resolver-common](https://gitlab.labs.nic.cz/labs/resolvers-yang/blob/master/yang-modules/cznic-resolver-common.yang)
* [cznic-resolver-knot](https://gitlab.labs.nic.cz/labs/resolvers-yang/blob/master/yang-modules/cznic-resolver-knot.yang)
* [cznic-resolver-unbound](https://gitlab.labs.nic.cz/labs/resolvers-yang/blob/master/yang-modules/cznic-resolver-unbound.yang)
* [cznic-dns-parameters](https://gitlab.labs.nic.cz/labs/resolvers-yang/blob/master/yang-modules/cznic-dns-parameters.yang)
* [cznic-deckard](https://gitlab.labs.nic.cz/labs/resolvers-yang/blob/master/yang-modules/cznic-deckard.yang)
* [cznic-resolver-common](https://gitlab.labs.nic.cz/labs/resolvers-yang/raw/master/yang-modules/cznic-resolver-common.yang)
* [cznic-resolver-knot](https://gitlab.labs.nic.cz/labs/resolvers-yang/raw/master/yang-modules/cznic-resolver-knot.yang)
* [cznic-resolver-unbound](https://gitlab.labs.nic.cz/labs/resolvers-yang/raw/master/yang-modules/cznic-resolver-unbound.yang)
* [cznic-dns-rdata](https://gitlab.labs.nic.cz/labs/resolvers-yang/raw/master/yang-modules/cznic-dns-rdata.yang)
* [cznic-deckard](https://gitlab.labs.nic.cz/labs/resolvers-yang/raw/master/yang-modules/cznic-deckard.yang)
## Getting Started
Requires **Python 3.5** or newer
Requires **Python 3.6** or newer
```bash
$ sudo apt-get install python3
$ sudo apt-get install python3-pip
# Ubuntu/Debian
$ sudo apt-get install python3 python3-pip
# Arch Linux
$ sudo pacman -S python python-pip
```
**Installation**
......
......@@ -8,9 +8,9 @@ All examples are located in ``examples/`` directory.
**Requirements:**
* Python 3.5+
* `resolvers-yang <https://gitlab.labs.nic.cz/labs/resolvers-yang>`_ library must be installed.
* `yangson <https://github.com/CZ-NIC/yangson>`_ library
* Python 3.6+
* `resolvers-yang <https://gitlab.labs.nic.cz/labs/resolvers-yang>`_
* `yangson <https://github.com/CZ-NIC/yangson>`_
Using Python virtual environment is recommended. Look at :ref:`installation`
......@@ -36,19 +36,19 @@ Run ``generate_conf.py`` script with path to Json file as parameter::
$ python generate_conf.py example-data.json
If generated ``unbound.conf`` is converted to JSON by ``unb_to_json.py`` script. The result does not have to be the same as input JSON for ``generate_conf.py`` script, because the configuration solely for Knot Resolver is ignored for Unbound.
If generated ``unbound.conf`` is converted to JSON by ``load_unb_conf_file_to_json.py`` script. The result does not have to be the same as input JSON for ``generate_conf.py`` script, because the configuration exclusively for Knot Resolver is ignored for Unbound.
==============
unb_to_json.py
==============
=============================
unbound_to_json.py
=============================
The script will convert Unbound configuration file ``unbound.conf`` to Json-encoded file ``unb-data.json``, which is validate with ``resolvers-yang`` data model.
As example configuration file can be used ``unbound.conf`` created by running ``generate_conf.py``
Run ``unb_to_conf.py`` with path to ``unbound.conf`` as parameter::
Run ``unbound_to_json.py`` with path to ``unbound.conf`` as parameter::
$ python unb_to_json.py unbound.conf
$ python unbound_to_json.py unbound.conf
No output means that the JSON data in created ``unb-data.json`` is valid.
No output means that the data in created ``unb-data.json`` are valid.
If you generate another ``unbound.conf`` from this Json using ``generate_conf.py`` script, it should be equal to ``unbound.conf``, which was used as input parameter for ``unb_to_json.py`` script.
\ No newline at end of file
If you generate another ``unbound.conf`` from this Json using ``generate_conf.py`` script, it should be equal to ``unbound.conf``, which was used as input parameter for ``load_unb_conf_file_to_json.py`` script.
\ No newline at end of file
......@@ -4,10 +4,13 @@
Getting Started
**************************
Resolvers-YANG library requires `Python 3.5 <https://www.python.org/>`_ or newer::
Resolvers-YANG library requires `Python 3.6 <https://www.python.org/>`_ or newer::
$ sudo apt-get install python3
$ sudo apt-get install python3-pip
# Ubuntu/Debian
$ sudo apt-get install python3 python3-pip
# Arch Linux
$ sudo pacman -S python python-pip
===========
Development
......
......@@ -48,76 +48,90 @@ Validate data against the data model:
>>> json_data.validate()
>>> json_data = json_data.add_defaults()
Now the data is valid and you can work with it.
Now the data are valid and you can work with it.
===============
Library Modules
===============
---------------------------------------------------------
Generator module
----------------
==============
Resolvers-YANG
==============
.. automodule:: generator
:members: Generator
YANG modules
^^^^^^^^^^^^
::
.. autoclass:: Generator
:members: generate_kresd, generate_unbound
yang-modules/
├── cznic-deckard.yang
├── cznic-deckard.yinx
├── cznic-dns-parameters.yang
├── cznic-dns-parameters.yinx
├── cznic-dns-rdata.yang
├── cznic-dns-rdata.yinx
├── cznic-resolver-common.yang
├── cznic-resolver-common.yinx
├── cznic-resolver-knot.yang
├── cznic-resolver-knot.yinx
├── cznic-resolver-unbound.yang
├── cznic-resolver-unbound.yinx
├── iana-dns-class-rr-type.yang
├── ietf-inet-types@2013-07-15.yang
├── ietf-netconf-acm@2012-02-22.yang
├── ietf-yang-library@2016-06-21.yang
├── ietf-yang-types@2013-07-15.yang
├── Makefile
├── model.tree
├── yanglib-deckard.json
└── yanglib.json
Import ``Generator`` class which contains ``generate_unbound`` and ``generate_kresd`` functions to generate Unbound and Knot Resolver configuration strings from valid python dictionary loaded from Json. Returns string.
Library
^^^^^^^
.. doctest::
::
resolvers_yang/
├── __init__.py
├── kresd/
│   ├── __init__.py
│   └── kresd_conf_gen.py
├── unbound/
| ├── __init__.py
| ├── unbound_conf_gen.py
| └── unbound_conf_loader.py
├── errors.py
├── parser.py
└── regex.py
Knot-Resolver modules
---------------------
^^^^^^^^^^^^^^^^^
kresd_conf_gen.py
^^^^^^^^^^^^^^^^^
>>> from resolvers_yang.generator import Generator
>>> generator = Generator()
.. automodule:: kresd.kresd_conf_gen
Call generator functions to generate `unbound.conf` and `kresd.conf`.
Import ``kresd.kresd_conf_gen`` module which contains ``generate`` function to generate Knot-Resolver configuration strings from valid python dictionary loaded from Json. Returns string.
.. doctest::
>>> unbound_conf = generator.generate_unbound(json_data)
>>> print(unbound_conf) # doctest: +NORMALIZE_WHITESPACE
server:
interface: 127.0.0.1@53
interface: ::1@53
interface: 198.51.100.1@8853
outgoing-interface: 2001:db8:0:2::1
do-ip6: yes
do-ip4: yes
edns-buffer-size: 4096
username: "jetconf"
root-hints: "/etc/resolver/root.hints"
harden-glue: yes
qname-minimisation: yes
rrset-roundrobin: yes
do-not-query-localhost: no
verbosity: 2
trust-anchor: ". IN DS 19036 8 2 49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE32F24E8FB5"
trust-anchor: ". IN DS 20326 8 2 E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC683457104237C7F8EC8D"
trust-anchor: ". IN DNSKEY 257 3 8 AwEAAagAIKlVZrpC6Ia7gEzahOR+9W29euxhJhVVLOyQbSEW0O8gcCjFFVQUTf6v58fLjwBd0YI0EzrAcQqBGCzh/RStIoO8g0NfnfL2MTJRkxoXbfDaUeVPQuYEhg37NZWAJQ9VnMVDxP/VHL496M/QZxkjf5/Efucp2gaDX6RS6CXpoY68LsvPVjR0ZSwzz1apAzvN9dlzEheX7ICJBBtuA6G3LQpzW5hOA2hzCTMjJPJ8LbqF6dsV6DoBQzgul0sGIcGOYl7OyQdXfZ57relSQageu+ipAdTTJ25AsRTAoub8ONGcLmqrAmRLKBP1dfwhYB4N7knNnulqQxA+Uk1ihz0=" domain-insecure: "bad.example.com"
domain-insecure: "worse.example.com"
msg-cache-size: 104857600
cache-max-ttl: 172800
cache-min-ttl: 0
val-override-date: "20181028131530"
dns64-prefix: 64:ff9b::/96
<BLANKLINE>
stub-zone:
name: "stub.example.com"
stub-addr: "192.0.2.1@53"
<BLANKLINE>
stub-zone:
name: "stub.example.net"
stub-addr: "198.51.100.1@53"
<BLANKLINE>
>>> from resolvers_yang.kresd import kresd_conf_gen
.. autofunction:: generate
Call ``kresd_conf_gen.generate()`` functions to create kresd_conf string.
.. doctest::
>>> kresd_conf = generator.generate_kresd(json_data)
>>> kresd_conf = kresd_conf_gen.generate(json_data)
>>> print(kresd_conf) # doctest: +NORMALIZE_WHITESPACE
net = {'127.0.0.1@53', '::1@53', '198.51.100.1@8853'}
net.outgoing_v6('2001:db8:0:2::1')
......@@ -125,12 +139,11 @@ Call generator functions to generate `unbound.conf` and `kresd.conf`.
net.ipv4 = true
net.bufsize(4096)
user('jetconf','wheel')
STUB('192.0.2.1@53', '198.51.100.1@53')
modules.load('hints')
hints.set("localhost 127.0.0.1")
hints.set("localhost ::1")
hints.set("loopback 127.0.0.1")
hints.add_hosts(/etc/hosts)
hints.add_hosts('/etc/hosts')
hints.root({['a.root-servers.net'] = {'198.41.0.4', '2001:503:ba3e::2:30'}})
hints.root_file('/etc/resolver/root.hints')
mode('strict')
......@@ -141,22 +154,75 @@ Call generator functions to generate `unbound.conf` and `kresd.conf`.
trust_anchors.add('. IN DS 19036 8 2 49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE32F24E8FB5')
trust_anchors.add('. IN DS 20326 8 2 E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC683457104237C7F8EC8D')
trust_anchors.add('. IN DNSKEY 257 3 8 AwEAAagAIKlVZrpC6Ia7gEzahOR+9W29euxhJhVVLOyQbSEW0O8gcCjFFVQUTf6v58fLjwBd0YI0EzrAcQqBGCzh/RStIoO8g0NfnfL2MTJRkxoXbfDaUeVPQuYEhg37NZWAJQ9VnMVDxP/VHL496M/QZxkjf5/Efucp2gaDX6RS6CXpoY68LsvPVjR0ZSwzz1apAzvN9dlzEheX7ICJBBtuA6G3LQpzW5hOA2hzCTMjJPJ8LbqF6dsV6DoBQzgul0sGIcGOYl7OyQdXfZ57relSQageu+ipAdTTJ25AsRTAoub8ONGcLmqrAmRLKBP1dfwhYB4N7knNnulqQxA+Uk1ihz0=')
trust_anchors.set_insecure({'bad.example.com', 'worse.example.com'})
cache.size = 104857600
trust_anchors.negative = {'bad.example.com', 'worse.example.com'}
cache.open(104857600)
cache.max_ttl(172800)
cache.min_ttl(0)
modules.load('prefill')
prefill.config({
['.'] = {
url = 'https://www.internic.net/domain/root.zone',
ca_file = '/etc/pki/tls/certs/ca-bundle.crt',
interval = 86400
}
})
modules.load('dns64')
dns64.config('64:ff9b::/96')
<BLANKLINE>
prefill.config({['.'] = {url = 'https://www.internic.net/domain/root.zone', ca_file = '/etc/pki/tls/certs/ca-bundle.crt', interval = 86400}})
modules = {dns64 = '64:ff9b::'}
Unbound modules
---------------
^^^^^^^^^^^^^^^^^^^^^^^^
unbound_conf_gen.py
^^^^^^^^^^^^^^^^^^^^^^^^
.. automodule:: unbound.unbound_conf_gen
Import ``unbound.unbound_conf_gen`` module which contains ``generate`` function to generate Unbound configuration strings from valid python dictionary loaded from Json. Returns string.
.. doctest::
>>> from resolvers_yang.unbound import unbound_conf_gen
.. autofunction:: generate
Call ``unbound_conf_gen.generate()`` functions to create unbound_conf string.
.. doctest::
>>> unbound_conf = unbound_conf_gen.generate(json_data)
>>> print(unbound_conf) # doctest: +NORMALIZE_WHITESPACE
server:
interface: 127.0.0.1@53
interface: ::1@53
interface: 198.51.100.1@8853
outgoing-interface: 2001:db8:0:2::1
do-ip6: yes
do-ip4: yes
edns-buffer-size: 4096
username: "jetconf"
verbosity: 2
trust-anchor: ". IN DS 19036 8 2 49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE32F24E8FB5"
trust-anchor: ". IN DS 20326 8 2 E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC683457104237C7F8EC8D"
trust-anchor: ". IN DNSKEY 257 3 8 AwEAAagAIKlVZrpC6Ia7gEzahOR+9W29euxhJhVVLOyQbSEW0O8gcCjFFVQUTf6v58fLjwBd0YI0EzrAcQqBGCzh/RStIoO8g0NfnfL2MTJRkxoXbfDaUeVPQuYEhg37NZWAJQ9VnMVDxP/VHL496M/QZxkjf5/Efucp2gaDX6RS6CXpoY68LsvPVjR0ZSwzz1apAzvN9dlzEheX7ICJBBtuA6G3LQpzW5hOA2hzCTMjJPJ8LbqF6dsV6DoBQzgul0sGIcGOYl7OyQdXfZ57relSQageu+ipAdTTJ25AsRTAoub8ONGcLmqrAmRLKBP1dfwhYB4N7knNnulqQxA+Uk1ihz0="
domain-insecure: "bad.example.com"
domain-insecure: "worse.example.com"
msg-cache-size: 104857600
cache-max-ttl: 172800
cache-min-ttl: 0
val-override-date: "20181028131530"
dns64-prefix: 64:ff9b::/96
root-hints: "/etc/resolver/root.hints"
harden-glue: yes
qname-minimisation: yes
rrset-roundrobin: yes
do-not-query-localhost: no
<BLANKLINE>
stub-zone:
name: "stub.example.com"
stub-addr: "192.0.2.1@53"
<BLANKLINE>
stub-zone:
name: "stub.example.net"
stub-addr: "198.51.100.1@53"
<BLANKLINE>
``unbound_conf`` and ``kresd_conf`` are raw strings , which can be save as text files.
......@@ -167,35 +233,37 @@ Call generator functions to generate `unbound.conf` and `kresd.conf`.
... unb_file.write(unbound_conf)
1264
Converter module
----------------
^^^^^^^^^^^^^^^^^^^^^^^^^^^
unbound_conf_loader.py
^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. automodule:: converter
:members: Converter
.. automodule:: unbound.unbound_conf_loader
.. autoclass:: Converter
:members: from_unbound
Import ``unbound.unbound_conf_loader`` class which contains ``load`` function for loading Unbound configuration string to python dictionary, which can be validate against `resolvers-yang` data model and save as Json file.
.. doctest::
Import ``Converter`` class which contains ``from_unbound`` function for converting Unbound configuration string to python dictionary, which can be validate against `resolvers-yang` data model and save as Json file.
>>> from resolvers_yang.unbound import unbound_conf_loader
.. doctest::
>>> from resolvers_yang.converter import Converter
.. autofunction:: load
Input parameter of ``from_unbound`` function is a list of string lines loaded from ``unbound.conf`` file. Returns python dictionary.
Input parameter of ``load`` function is string loaded from ``unbound.conf`` file. Returns python dictionary.
.. doctest::
>>> with open("unbound.conf", "r") as unb_file:
... unbconf_data = unb_file.read()
Call ``load`` function to load configuration string to dictionary.
.. doctest::
>>> converter = Converter()
>>> json_data = converter.from_unbound(unbconf_data)
>>> json_data = unbound_conf_loader.load(unbconf_data)
>>> json_data
{'cznic-resolver-common:dns-resolver': {'server': {'user-name': 'jetconf'}, 'network': {'listen-interfaces': [{'name': 'interface0', 'ip-address': '127.0.0.1', 'port': 53}, {'name': 'interface1', 'ip-address': '::1', 'port': 53}, {'name': 'interface2', 'ip-address': '198.51.100.1', 'port': 8853}], 'source-address': {'ipv6': '2001:db8:0:2::1'}, 'udp-payload-size': 4096, 'recursion-transport': {'l2-protocols': 'ipv4 ipv6'}}, 'resolver': {'stub-zones': [{'domain': 'stub.example.com', 'nameserver': '192.0.2.1', 'port': 53}, {'domain': 'stub.example.net', 'nameserver': '198.51.100.1', 'port': 53}], 'options': {'glue-checking': True, 'qname-minimisation': True, 'reorder-rrset': True, 'query-loopback': True}, 'hints': {'root-zone-file': '/etc/resolver/root.hints'}}, 'logging': {'verbosity': 2}, 'dnssec': {'trust-anchors': [{'domain': '.', 'auto-update': True, 'trust-anchor': [{'id': 0, 'ds': {'algorithm': 'RSASHA256', 'digest': '49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE32F24E8FB5', 'digest-type': 'SHA-256', 'key-tag': 19036}}, {'id': 1, 'ds': {'algorithm': 'RSASHA256', 'digest': 'E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC683457104237C7F8EC8D', 'digest-type': 'SHA-256', 'key-tag': 20326}}, {'id': 2, 'dnskey': {'algorithm': 'RSASHA256', 'flags': 'ZONE SEP', 'protocol': 3, 'public-key': 'AwEAAagAIKlVZrpC6Ia7gEzahOR+9W29euxhJhVVLOyQbSEW0O8gcCjFFVQUTf6v58fLjwBd0YI0EzrAcQqBGCzh/RStIoO8g0NfnfL2MTJRkxoXbfDaUeVPQuYEhg37NZWAJQ9VnMVDxP/VHL496M/QZxkjf5/Efucp2gaDX6RS6CXpoY68LsvPVjR0ZSwzz1apAzvN9dlzEheX7ICJBBtuA6G3LQpzW5hOA2hzCTMjJPJ8LbqF6dsV6DoBQzgul0sGIcGOYl7OyQdXfZ57relSQageu+ipAdTTJ25AsRTAoub8ONGcLmqrAmRLKBP1dfwhYB4N7knNnulqQxA+Uk1ihz0='}}]}], 'negative-trust-anchors': ['bad.example.com', 'worse.example.com']}, 'cache': {'max-size': 104857600, 'max-ttl': 172800, 'min-ttl': 0}, 'debugging': {'cznic-resolver-unbound:val-override-date': '2018-10-28T13:15:30Z'}, 'dns64': {'prefix': '64:ff9b::/96'}}}
......
......@@ -2,16 +2,21 @@
YANG Data Model
***************
------------------------------------------------------------
=============
YANG Modules
=============
All Modules are located in ``yang-modules/`` project directory.
* `cznic-dns-types`_
* `cznic-dns-rdata`_
* `cznic-resolver-common`_
* `cznic-resolver-knot`_
------------------------------------------------------------
=============
Data Model
=============
......@@ -123,17 +128,17 @@ logging
dnssec:
-------------
^^^^^^^
cache:
-------------
^^^^^^
dns64:
-------------
^^^^^^
.. _Current schema tree: https://gitlab.labs.nic.cz/jetconf/jetconf-resolver/raw/master/data-model/model.tree
.. _Example JSON data: https://gitlab.labs.nic.cz/jetconf/jetconf-resolver/raw/master/tests/complete/example-data.json
.. _cznic-dns-types: https://gitlab.labs.nic.cz/jetconf/jetconf-resolver/raw/master/yang-modules/cznic-dns-types@2018-05-14.yang
.. _cznic-resolver-common: https://gitlab.labs.nic.cz/jetconf/jetconf-resolver/raw/master/yang-modules/cznic-resolver-knot@2018-07-27.yang
.. _cznic-resolver-knot: https://gitlab.labs.nic.cz/labs/resolvers-yang/raw/master/yang-modules/cznic-resolver-knot@2018-07-27.yang
.. _Current schema tree: https://gitlab.labs.nic.cz/labs/resolvers-yang/raw/master/yang-modules/model.tree
.. _Example JSON data: https://gitlab.labs.nic.cz/labs/resolvers-yang/raw/master/examples/example-data.json
.. _cznic-dns-rdata: https://gitlab.labs.nic.cz/labs/resolvers-yang/raw/master/yang-modules/cznic-dns-rdata.yang
.. _cznic-resolver-common: https://gitlab.labs.nic.cz/labs/resolvers-yang/raw/master/yang-modules/cznic-resolver-common.yang
.. _cznic-resolver-knot: https://gitlab.labs.nic.cz/labs/resolvers-yang/raw/master/yang-modules/cznic-resolver-knot.yang
import sys
from json import load, dumps
from yangson.datamodel import DataModel
from json import load
from resolvers_yang.generator import Generator
from resolvers_yang.unbound import unbound_conf_gen
from resolvers_yang.kresd import kresd_conf_gen
json_path = sys.argv[1]
......@@ -23,29 +25,33 @@ data = model.from_raw(ri)
data.validate()
# adding missing default values
data_defaults = data.add_defaults()
data = data.add_defaults()
data.validate()
# get path where is mock data located
mock_path = data["cznic-deckard:deckard"]["mock-data"].value
if 'cznic-deckard:deckard' in data:
mock_path = data["cznic-deckard:deckard"]["mock-data"].value
# load mock data text file from path as string
mock_data = open(mock_path).read()
# load mock data text file from path as string
mock_data = open(mock_path).read()
# slicing mock_data
mock_begin = mock_data.find("SCENARIO_BEGIN")
mock_data = mock_data[mock_begin:]
# slicing mock_data
mock_begin = mock_data.find("SCENARIO_BEGIN")
mock_data = "\nCONFIG_END\n\n" + mock_data[mock_begin:]
else:
mock_data = ""
print("Failed to load mock-data: 'cznic-deckard:deckard' node not found ")
# generate configuration strings
generator = Generator()
unb_conf = generator.generate_unbound(data_defaults)
kresd_conf = generator.generate_kresd(data_defaults)
unbound_conf = unbound_conf_gen.generate(data)
kresd_conf = kresd_conf_gen.generate(data)
# write kresd.conf
knot_file = open(kresd_path, "w+")
knot_file.write(kresd_conf)
knot_file.close()
# write Knot Resolver configuration
with open(kresd_path, "w") as knot_file:
knot_file.write(kresd_conf)
# write unbound.rpl = unbconf string + mock data
unb_file = open(unb_path, "w+")
unb_file.write(unb_conf + "\nCONFIG_END\n\n" + mock_data)
unb_file.close()
with open(unb_path, "w") as unb_file:
unb_file.write(unbound_conf + mock_data)
......@@ -28,7 +28,8 @@
},
"recursion-transport": {
"l2-protocols": "ipv4 ipv6"
}
},
"udp-payload-size": 4096
},
"resolver": {
"stub-zones": [
......
......@@ -2,7 +2,8 @@ import sys
from json import load
from yangson.datamodel import DataModel
from resolvers_yang.generator import Generator
from resolvers_yang.unbound import unbound_conf_gen
from resolvers_yang.kresd import kresd_conf_gen
json_path = sys.argv[1]
......@@ -30,9 +31,8 @@ data.validate()
data_defaults = data.add_defaults()
# generate configuration strings
generator = Generator()
unb_conf = generator.generate_unbound(data_defaults)
kresd_conf = generator.generate_kresd(data_defaults)
unbound_conf = unbound_conf_gen.generate(data_defaults)
kresd_conf = kresd_conf_gen.generate(data_defaults)
# write Knot Resolver configuration
with open(kresd_path, "w") as knot_file:
......@@ -40,8 +40,6 @@ with open(kresd_path, "w") as knot_file:
# write Unbound configuration
with open(unb_path, "w") as unb_file:
unb_file.write(unb_conf)
print("{0} {1} configuration files were successfully created.".format(kresd_path, unb_path))
unb_file.write(unbound_conf)
......@@ -2,7 +2,7 @@ import sys
from json import dump
from yangson.datamodel import DataModel
from resolvers_yang.converter import Converter
from resolvers_yang.unbound import unbound_conf_loader
unbconf_path = sys.argv[1]
......@@ -19,9 +19,8 @@ model = DataModel.from_file(yangdir + "/yanglib.json", [yangdir])
with open(unbconf_path, "r") as unb_file:
unbconf_data = unb_file.read()
# call of conversion function unbconf_data >> Dictionary
converter = Converter()
json_data = converter.from_unbound(unbconf_data)
# call of conversion function unbconf_data >> dictionary
json_data = unbound_conf_loader.load(unbconf_data)
# load data to DataModel
model_data = model.from_raw(json_data)
......@@ -33,5 +32,3 @@ model_data.validate()
with open(data_json_path, 'w') as json_file:
dump(json_data, json_file, indent=2, sort_keys=False)
print("Data was successfully writted to json file named " + data_json_path)
class UnboundConfValueError(ValueError):
def __init__(self, arg):
self.strerror = arg
self.args = {arg}
class ResolversYangException(Exception):
pass
This diff is collapsed.
"""
Module for converting data from valid loaded Json(Python Dictionary) to Knot Resolver configuration strings.
"""
from re import sub
from resolvers_yang.parser import TrustAnchorRR as TA_parser
from resolvers_yang.regex import ipv6_prefix
def generate(config: dict) -> str:
"""
:param config: Dictionary loaded from Resolvers-YANG Model valid Json file.
:type config: dict
:return: Configuration strings for Knot-Resolver separated by newlines.
:rtype: str
"""
kresd_conf = ""
if 'cznic-resolver-common:dns-resolver' in config:
conf = config['cznic-resolver-common:dns-resolver']
else:
conf = config
if 'network' in conf:
if kresd_conf != "":
kresd_conf += "\n"
kresd_conf += Network.generate(conf['network'])
if 'server' in conf:
if kresd_conf != "":
kresd_conf += "\n"
kresd_conf += Server.generate(conf['server'])
if 'resolver' in conf:
if kresd_conf != "":
kresd_conf += "\n"
kresd_conf += Resolver.generate(conf['resolver'])
if 'logging' in conf:
if kresd_conf != "":
kresd_conf += "\n"
kresd_conf += Logging.generate(conf['logging'])
if 'dnssec' in conf:
if kresd_conf != "":
kresd_conf += "\n"
kresd_conf += Dnssec.generate(conf['dnssec'])
if 'cache' in conf:
if kresd_conf != "":
kresd_conf += "\n"
kresd_conf += Cache.generate(conf['cache'])
if 'dns64' in conf:
if kresd_conf != "":
kresd_conf += "\n"
kresd_conf += Dns64.generate(conf['dns64'])
return kresd_conf
class Server:
@staticmethod
</