Skip to content

Commit cfc388a

Browse files
[change] Update dependencies #203
Closes #203 By Gagan Deep: The hostname validation has been adapted from jsonschema~=3.2.0 (jsonschema._format.is_host_name). The newer versions of jsonschema enforces FQDN validation which is not always required in OpenWISP. E.g. setting up hostname of a device. Co-authored-by: Gagan Deep <pandafy.dev@gmail.com>
1 parent 109b3f4 commit cfc388a

5 files changed

Lines changed: 33 additions & 13 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434

3535
- name: Install python dependencies
3636
run: |
37-
pip install -U "pip==20.2.4" wheel setuptools
37+
pip install -U pip wheel setuptools
3838
pip install -U -r requirements-test.txt
3939
4040
- name: Install netjsonconfig

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ netjsonconfig
77
.. image:: https://coveralls.io/repos/openwisp/netjsonconfig/badge.svg
88
:target: https://coveralls.io/r/openwisp/netjsonconfig
99

10-
.. image:: https://requires.io/github/openwisp/netjsonconfig/requirements.svg?branch=master
11-
:target: https://requires.io/github/openwisp/netjsonconfig/requirements/?branch=master
12-
:alt: Requirements Status
10+
.. image:: https://img.shields.io/librariesio/release/github/openwisp/netjsonconfig
11+
:target: https://libraries.io/github/openwisp/netjsonconfig#repository_dependencies
12+
:alt: Dependency monitoring
1313

1414
.. image:: https://img.shields.io/gitter/room/nwjs/nw.js.svg?style=flat-square
1515
:target: https://gitter.im/openwisp/general

docs/source/index.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ netjsonconfig
33
=============
44

55
.. image:: https://travis-ci.org/openwisp/netjsonconfig.svg
6-
:target: https://travis-ci.org/openwisp/netjsonconfig
6+
:target: https://travis-ci.org/openwisp/netjsonconfig
77

88
.. image:: https://coveralls.io/repos/openwisp/netjsonconfig/badge.svg
9-
:target: https://coveralls.io/r/openwisp/netjsonconfig
9+
:target: https://coveralls.io/r/openwisp/netjsonconfig
1010

11-
.. image:: https://requires.io/github/openwisp/netjsonconfig/requirements.svg?branch=master
12-
:target: https://requires.io/github/openwisp/netjsonconfig/requirements/?branch=master
13-
:alt: Requirements Status
11+
.. image:: https://img.shields.io/librariesio/release/github/openwisp/netjsonconfig
12+
:target: https://libraries.io/github/openwisp/netjsonconfig#repository_dependencies
13+
:alt: Dependency monitoring
1414

1515
.. image:: https://badge.fury.io/py/netjsonconfig.svg
16-
:target: http://badge.fury.io/py/netjsonconfig
16+
:target: http://badge.fury.io/py/netjsonconfig
1717

1818
.. image:: https://img.shields.io/gitter/room/nwjs/nw.js.svg?style=flat-square
19-
:target: https://gitter.im/openwisp/general
19+
:target: https://gitter.im/openwisp/general
2020

2121
Netjsonconfig is part of the `OpenWISP project <http://openwrt.org>`_ and it's the official
2222
configuration engine of `OpenWISP 2 <https://github.com/openwisp/ansible-openwisp2>`_.

netjsonconfig/backends/base/backend.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import gzip
22
import ipaddress
33
import json
4+
import re
45
import tarfile
56
from collections import OrderedDict
67
from copy import deepcopy
@@ -13,6 +14,8 @@
1314
from ...schema import DEFAULT_FILE_MODE
1415
from ...utils import evaluate_vars, merge_config
1516

17+
_host_name_re = re.compile(r"^[A-Za-z0-9][A-Za-z0-9\.\-]{1,255}$")
18+
1619

1720
class BaseBackend(object):
1821
"""
@@ -131,6 +134,24 @@ def _cidr_notation(value):
131134
assert False, str(e)
132135
return True
133136

137+
@draft4_format_checker.checks('hostname', JsonSchemaError)
138+
def _is_hostname(value):
139+
"""
140+
The hostname validation has been taken from jsonschema~=3.2.0
141+
(jsonschema._format.is_host_name). The newer versions of
142+
jsonschema enforces FQDN validation which is not always
143+
required in OpenWISP. E.g. setting up hostname of a device.
144+
"""
145+
if not isinstance(value, str):
146+
return True
147+
if not _host_name_re.match(value):
148+
return False
149+
components = value.split(".")
150+
for component in components:
151+
if len(component) > 63:
152+
return False
153+
return True
154+
134155
def validate(self):
135156
try:
136157
Draft4Validator(self.schema, format_checker=draft4_format_checker).validate(

requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
jinja2~=3.0.0
2-
jsonschema>=3.0,<3.3
3-
six
2+
jsonschema~=4.4.0

0 commit comments

Comments
 (0)