Skip to content

Commit

Permalink
[airos] complied with style issue from code review
Browse files Browse the repository at this point in the history
[airos][test] be professional and wear a 👔

[airos][doc] changed to comply to pull request review

[airos] renamed to more declarative name

[airos] switched to friendlier names in dictionary iteration

[airos] fixed invalid schema

[airos] fixed empty dictionary result

[airos] draft for key derivation in user converter

[airos] draft for specifying user password from netjson

[airos] included password as blob

[airos] added doc about user password for airos

[airos] fixed bugs with child_value being used as child_key

[airos] added test for conversion from intermediate_data

[airos] comply with PEP8 naming convention

[airos] fixed indentation issues for dictionaries

[airos] fixed typo in class attribute

[airos] made indented code more compact

[airos] fixed typo in converter class

[airos] fixed indentation in list comprehension

[airos] renamed to more readable name

[airos] remove commented code

[airos] made more compat code

[airos] retabbed test code to use 4 spaces

[airos] removed unused import

[airos] changed to 4 spaces indentation in template

[qa] Fixed flake8 & isort warnings

[airos] renamed renderer for PEP8 compliance
  • Loading branch information
edoput committed Jul 20, 2017
1 parent eb40826 commit 25cd7f6
Show file tree
Hide file tree
Showing 27 changed files with 962 additions and 1,153 deletions.
2 changes: 1 addition & 1 deletion bin/netjsonconfig
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ backends = {
'openwrt': netjsonconfig.OpenWrt,
'openwisp': netjsonconfig.OpenWisp,
'openvpn': netjsonconfig.OpenVpn,
'airos': netjsonconfig.AirOS,
'airos': netjsonconfig.AirOs,
}

backend_class = backends[args.backend]
Expand Down
32 changes: 31 additions & 1 deletion docs/source/backends/airos.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,36 @@ By setting the key ``ntp_servers`` in your input you can provide a list of ntp s
]
}
Users
-----

We can specify the user password as a blob divided into ``salt`` and ``hash``.

From the antenna configuration take the user section.

.. code-block:: ini
users.status=enabled
users.1.status=enabled
users.1.name=ubnt
users.1.password=$1$yRo1tmtC$EcdoRX.JnD4VaEYgghgWg1
I the line ``users.1.password=$1$yRo1tmtC$EcdoRX.JnD4VaEYgghgWg1`` there are both the salt and the password hash in the format ``$ algorithm $ salt $ hash $``, e.g in the previous block ``algorithm=1``, ``salt=yRo1tmtC`` and ``hash=EcdoRX.JnD4VaEYgghgWg1``.

To specify the password in NetJSON use the ``user`` property.

.. code-block:: json
{
"type": "DeviceConfiguration",
"user": {
"name": "ubnt",
"passsword": "EcdoRX.JnD4VaEYgghgWg1",
"salt": "yRo1tmtC"
}
}
WPA2
----

Expand Down Expand Up @@ -180,4 +210,4 @@ And another that set the authentication protocol to WPA2 enterprise, but this is
]
}
Leaving the `NetJSON Encryption object <http://netjson.org/rfc.html#rfc.section.5.4.2.1>` empty defaults to no encryption at all
Leaving the `NetJSON Encryption object <http://netjson.org/rfc.html#rfc.section.5.4.2.1>` empty defaults to no encryption at all.
106 changes: 53 additions & 53 deletions docs/source/backends/intermediate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ Intermediate representation

The intermediate representation is the output of the a :ref:`converter`,
it is backend specific and is built as a tree structure made from python
builtins values
builtins values.

A tree is a *acyclic, directional graph* with an element called *root*.

The root of our tree is stored in the first element of a tuple, along with
the root's direct sons as a list
the root's direct sons as a list:

.. code-block:: python
Expand All @@ -30,9 +30,9 @@ As an example here we present the tree `('spam', ['eggs', 'snakes'])`
}

As a son may be a carrier of a value so we store it in a dictionary instead of adding a *leaf*
with another level of recursion
with another level of recursion.

As an example here we present the tree `('spam', [ { 'eggs': 2 }, { 'snakes' : { 'loved' : 'python' }}])`
As an example here we present the tree `('spam', [ { 'eggs': 2 }, { 'snakes' : { 'loved' : 'python' }}])`:

.. graphviz::

Expand All @@ -46,7 +46,7 @@ As an example here we present the tree `('spam', [ { 'eggs': 2 }, { 'snakes' : {

}

This tree could be tranlated to a configuration file for AirOS that looks like this
This tree could be tranlated to a configuration file for AirOS that looks like this:

.. code-block:: ini
Expand All @@ -55,7 +55,7 @@ This tree could be tranlated to a configuration file for AirOS that looks like t
So our tree representation is based on the simple assumption that a *leaf* is a dictionary
without nested values and nested values in a dictionary creates a father-son relationship
without nested values and nested values in a dictionary creates a father-son relationship.

Instead when the configuration requires that the son values must be prefixed from a number,
e.g. `vlan.1.devname=eth0` we store a list of dictionaries.
Expand All @@ -65,27 +65,27 @@ e.g. `vlan.1.devname=eth0` we store a list of dictionaries.
(
'spam',
[
{
'eggs' : 2,
{
'eggs' : 2,
},
{
'snakes' : {
'loved' : [
{
'python2' : True,
},
{
'python3' : True,
},
{
'ipython' : True,
}
],
},
{
'snakes' : {
'loved' : [
{
'python2' : True,
},
{
'python3' : True,
},
{
'ipython' : True,
}
],
},
}
]
}
])
And the resulting tree is this
And the resulting tree is:

.. graphviz::

Expand All @@ -109,7 +109,7 @@ And the resulting tree is this

}

And the configuration is
And the configuration is:

.. code-block:: ini
Expand All @@ -119,32 +119,32 @@ And the configuration is
spam.snakes.loved.2.ipython=true
The process by which we can go from the intermediate representation from
the output configuration is called flattening
the output configuration is called flattening, you can find more in the next section.

Flattening
----------

To avoid at all cost a recursive logic in the template we flatten the intermediate
representation to something that has a *namespace* a *key* and a *value*
representation to something that has a *namespace* a *key* and a *value*.

This input NetJSON will be converted to a python :ref:`configuration_dictionary`
This input NetJSON will be converted to a python :ref:`configuration_dictionary`:

.. code-block:: json
//netjson
{
"type" : "DeviceConfiguration",
"interfaces" : [
{
"name" : "eth0.1",
"type" : "ethernet",
"comment" : "management vlan"
},
{
"name" : "eth0.2",
"type" : "ethernet",
"comment" : "traffic vlan"
}
{
"name" : "eth0.1",
"type" : "ethernet",
"comment" : "management vlan"
},
{
"name" : "eth0.2",
"type" : "ethernet",
"comment" : "traffic vlan"
}
]
}
Expand All @@ -153,21 +153,21 @@ This input NetJSON will be converted to a python :ref:`configuration_dictionary`
#python
{
'interfaces' : [
{
'name' : 'eth0.1',
'type' : 'ethernet',
'comment' : 'management'
},
{
'name' : 'eth0.2',
'type' : 'ethernet',
'comment' : 'traffic'
}
{
'name' : 'eth0.1',
'type' : 'ethernet',
'comment' : 'management vlan'
},
{
'name' : 'eth0.2',
'type' : 'ethernet',
'comment' : 'traffic vlan'
}
]
}
And this must be converted to an appropiate AirOS configuration which looks like this
And this must be converted to an appropiate AirOS configuration which looks like this:

.. code-block:: ini
Expand All @@ -182,7 +182,7 @@ And this must be converted to an appropiate AirOS configuration which looks like
vlan.status=enabled
To do this we must convert the :ref:`configuration_dictionary` into something that
resemble the target text, the output configuration
resembles the target text, the output configuration.

.. code-block:: python
Expand All @@ -208,9 +208,9 @@ resemble the target text, the output configuration
)
And to do that we get rid of the multiple indentation levels by flattening the tree structure
And to do that we get rid of the multiple indentation levels by flattening the tree structure.

The tree associated with the previous NetJSON example is this
The tree associated with the previous NetJSON example is this:

.. graphviz::

Expand Down
2 changes: 1 addition & 1 deletion netjsonconfig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from .backends.openwrt.openwrt import OpenWrt # noqa
from .backends.openwisp.openwisp import OpenWisp # noqa
from .backends.openvpn.openvpn import OpenVpn # noqa
from .backends.airos.airos import AirOS # noqa
from .backends.airos.airos import AirOs # noqa
Loading

0 comments on commit 25cd7f6

Please sign in to comment.