Commit d31abf98 authored by Ales Mrazek's avatar Ales Mrazek

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
......
This diff is collapsed.
......@@ -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.
This diff is collapsed.
from .regex import ipv4_address, ipv6_address
##########################################################################
# Trust-Anchor ResourceRecord PARSER
##########################################################################
class TrustAnchorRR:
alg_enum = {
1: "RSAMD5",
2: "DH",
......@@ -142,3 +147,32 @@ class TrustAnchorRR:
dnskey_ta['public-key'])
return dnskey_str
##########################################################################
# IP-Adress PARSER
##########################################################################
class IpAddress:
@staticmethod
def parse(address: str):
address = address.strip()
if '@' in address:
addr, port = address.split("@")
port = int(port)
else:
addr = address
port = None
return str(addr), port
@staticmethod
def check(ip_addr: str):
ip_addr = ip_addr.strip()
if ipv6_address.match(ip_addr) or ipv4_address.match(ip_addr):
return True
else:
return False
......@@ -21,13 +21,16 @@ ipv6_address = compile('^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}'
+ '(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$')
# IPv6 prefix format checker
ipv6_prefix = compile('^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}'
+ '|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}'
+ ':[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4})'
+ '{1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}'
+ ':){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}'
+ '|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:'
+ '(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|'
+ '(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|'
+ '([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}'
+ '(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))(/(([0-9])|([0-9]{2})|(1[0-1][0-9])|(12[0-8])))$')
ipv6_with_prefix = compile('^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}'
+ '|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}'
+ ':[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4})'
+ '{1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}'
+ ':){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}'
+ '|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:'
+ '(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|'
+ '(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|'
+ '([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}'
+ '(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))(\/(([0-9])|([0-9]{2})|(1[0-1][0-9])|'
+ '(12[0-8])))$')
ipv6_prefix = compile('(\/(([0-9])|([0-9]{2})|(1[0-1][0-9])|(12[0-8])))$')
This diff is collapsed.
......@@ -7,8 +7,8 @@ Then unbound.conf and unbound-test.conf are compared.
from json import load, dump
from yangson.datamodel import DataModel
from resolvers_yang.generator import Generator
from resolvers_yang.converter import Converter
from resolvers_yang.unbound import unbound_conf_gen
from resolvers_yang.unbound import unbound_conf_loader
examample_path = "../examples/example-data.json"
test_path = "test-data.json"
......@@ -41,8 +41,7 @@ data.validate()
data_defaults = data.add_defaults()
# generate configuration strings
generator1 = Generator()
unb_conf = generator1.generate_unbound(data_defaults)
unb_conf = unbound_conf_gen.generate(data_defaults)
# write Unbound configurationwith
with open(unb_path, "w") as unb_file:
......@@ -56,8 +55,7 @@ with open(unb_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)
json_data = unbound_conf_loader.load(unbconf_data)
# load data to DataModel
model_data = model.from_raw(json_data)
......@@ -86,8 +84,7 @@ data.validate()
data_defaults = data.add_defaults()
# generate configuration strings
generator2 = Generator()
unbtest_conf = generator2.generate_unbound(data_defaults)
unbtest_conf = unbound_conf_gen.generate(data_defaults)
# write Unbound configuration
unbtest_file = open(unbtest_path, "w+")
......
......@@ -10,7 +10,7 @@
},
{
"name": "cznic-resolver-common",
"revision": "2018-12-13",
"revision": "2018-12-17",
"feature": [
"set-group"
],
......
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