Skip to content

Commit 25cd7f6

Browse files
committed
[airos] complied with style issue from code review
[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
1 parent eb40826 commit 25cd7f6

27 files changed

+962
-1153
lines changed

bin/netjsonconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ backends = {
170170
'openwrt': netjsonconfig.OpenWrt,
171171
'openwisp': netjsonconfig.OpenWisp,
172172
'openvpn': netjsonconfig.OpenVpn,
173-
'airos': netjsonconfig.AirOS,
173+
'airos': netjsonconfig.AirOs,
174174
}
175175

176176
backend_class = backends[args.backend]

docs/source/backends/airos.rst

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,36 @@ By setting the key ``ntp_servers`` in your input you can provide a list of ntp s
139139
]
140140
}
141141
142+
Users
143+
-----
144+
145+
We can specify the user password as a blob divided into ``salt`` and ``hash``.
146+
147+
From the antenna configuration take the user section.
148+
149+
.. code-block:: ini
150+
151+
users.status=enabled
152+
users.1.status=enabled
153+
users.1.name=ubnt
154+
users.1.password=$1$yRo1tmtC$EcdoRX.JnD4VaEYgghgWg1
155+
156+
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``.
157+
158+
To specify the password in NetJSON use the ``user`` property.
159+
160+
.. code-block:: json
161+
162+
{
163+
"type": "DeviceConfiguration",
164+
"user": {
165+
"name": "ubnt",
166+
"passsword": "EcdoRX.JnD4VaEYgghgWg1",
167+
"salt": "yRo1tmtC"
168+
}
169+
}
170+
171+
142172
WPA2
143173
----
144174

@@ -180,4 +210,4 @@ And another that set the authentication protocol to WPA2 enterprise, but this is
180210
]
181211
}
182212
183-
Leaving the `NetJSON Encryption object <http://netjson.org/rfc.html#rfc.section.5.4.2.1>` empty defaults to no encryption at all
213+
Leaving the `NetJSON Encryption object <http://netjson.org/rfc.html#rfc.section.5.4.2.1>` empty defaults to no encryption at all.

docs/source/backends/intermediate.rst

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ Intermediate representation
1010

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

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

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

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

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

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

3737
.. graphviz::
3838

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

4747
}
4848

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

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

6060
Instead when the configuration requires that the son values must be prefixed from a number,
6161
e.g. `vlan.1.devname=eth0` we store a list of dictionaries.
@@ -65,27 +65,27 @@ e.g. `vlan.1.devname=eth0` we store a list of dictionaries.
6565
(
6666
'spam',
6767
[
68-
{
69-
'eggs' : 2,
68+
{
69+
'eggs' : 2,
70+
},
71+
{
72+
'snakes' : {
73+
'loved' : [
74+
{
75+
'python2' : True,
76+
},
77+
{
78+
'python3' : True,
79+
},
80+
{
81+
'ipython' : True,
82+
}
83+
],
7084
},
71-
{
72-
'snakes' : {
73-
'loved' : [
74-
{
75-
'python2' : True,
76-
},
77-
{
78-
'python3' : True,
79-
},
80-
{
81-
'ipython' : True,
82-
}
83-
],
84-
},
85-
}
86-
]
85+
}
86+
])
8787
88-
And the resulting tree is this
88+
And the resulting tree is:
8989

9090
.. graphviz::
9191

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

110110
}
111111

112-
And the configuration is
112+
And the configuration is:
113113

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

124124
Flattening
125125
----------
126126

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

130-
This input NetJSON will be converted to a python :ref:`configuration_dictionary`
130+
This input NetJSON will be converted to a python :ref:`configuration_dictionary`:
131131

132132
.. code-block:: json
133133
134134
//netjson
135135
{
136136
"type" : "DeviceConfiguration",
137137
"interfaces" : [
138-
{
139-
"name" : "eth0.1",
140-
"type" : "ethernet",
141-
"comment" : "management vlan"
142-
},
143-
{
144-
"name" : "eth0.2",
145-
"type" : "ethernet",
146-
"comment" : "traffic vlan"
147-
}
138+
{
139+
"name" : "eth0.1",
140+
"type" : "ethernet",
141+
"comment" : "management vlan"
142+
},
143+
{
144+
"name" : "eth0.2",
145+
"type" : "ethernet",
146+
"comment" : "traffic vlan"
147+
}
148148
]
149149
}
150150
@@ -153,21 +153,21 @@ This input NetJSON will be converted to a python :ref:`configuration_dictionary`
153153
#python
154154
{
155155
'interfaces' : [
156-
{
157-
'name' : 'eth0.1',
158-
'type' : 'ethernet',
159-
'comment' : 'management'
160-
},
161-
{
162-
'name' : 'eth0.2',
163-
'type' : 'ethernet',
164-
'comment' : 'traffic'
165-
}
156+
{
157+
'name' : 'eth0.1',
158+
'type' : 'ethernet',
159+
'comment' : 'management vlan'
160+
},
161+
{
162+
'name' : 'eth0.2',
163+
'type' : 'ethernet',
164+
'comment' : 'traffic vlan'
165+
}
166166
]
167167
}
168168
169169
170-
And this must be converted to an appropiate AirOS configuration which looks like this
170+
And this must be converted to an appropiate AirOS configuration which looks like this:
171171

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

187187
.. code-block:: python
188188
@@ -208,9 +208,9 @@ resemble the target text, the output configuration
208208
209209
)
210210
211-
And to do that we get rid of the multiple indentation levels by flattening the tree structure
211+
And to do that we get rid of the multiple indentation levels by flattening the tree structure.
212212

213-
The tree associated with the previous NetJSON example is this
213+
The tree associated with the previous NetJSON example is this:
214214

215215
.. graphviz::
216216

netjsonconfig/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
from .backends.openwrt.openwrt import OpenWrt # noqa
44
from .backends.openwisp.openwisp import OpenWisp # noqa
55
from .backends.openvpn.openvpn import OpenVpn # noqa
6-
from .backends.airos.airos import AirOS # noqa
6+
from .backends.airos.airos import AirOs # noqa

0 commit comments

Comments
 (0)