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.
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.
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.
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.