Skip to content

Commit

Permalink
Fix usage of mac address patterns in schema.py to allow using variabl…
Browse files Browse the repository at this point in the history
…es (Closes openwisp#238)

- Adds BLANK and VAR patterns
- Patches MAC patterns
- Removes usage of maxLength and minLength in mac and bssid properties
  • Loading branch information
lpalgarvio committed Jun 20, 2022
1 parent 6db272c commit 9b1a5fd
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions netjsonconfig/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

DEFAULT_FILE_MODE = '0644'
X509_FILE_MODE = '0600'
BLANK_PATTERN = '(\s)'
VAR_PATTERN = '([{]{2}.*[}]{2})'
MAC_PATTERN = '([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})'
MAC_PATTERN_BLANK = '^({0}|)$'.format(MAC_PATTERN)
MAC_VAR_PATTERN = '^({0}|)$'.format(MAC_PATTERN + '|' + VAR_PATTERN)
MAC_VAR_BLANK_PATTERN = '^({0}|)$'.format(MAC_PATTERN + '|' + VAR_PATTERN + '|' + BLANK_PATTERN)

schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
Expand Down Expand Up @@ -140,8 +143,7 @@
"type": "string",
"title": "MAC address",
"description": "if specified overrides default macaddress for this interface",
"pattern": MAC_PATTERN_BLANK, # can be empty
"maxLength": 17,
"pattern": MAC_VAR_BLANK_PATTERN, # can be empty
"propertyOrder": 3,
},
"autostart": {
Expand Down Expand Up @@ -318,8 +320,7 @@
"bssid": {
"type": "string",
"title": "BSSID",
"pattern": MAC_PATTERN_BLANK,
"maxLength": 17,
"pattern": MAC_VAR_BLANK_PATTERN, # can be empty
"propertyOrder": 4,
},
}
Expand Down Expand Up @@ -846,7 +847,7 @@
"required": ["bssid"],
"properties": {
"mode": {"enum": ["adhoc"]},
"bssid": {"pattern": MAC_PATTERN, "minLength": 17},
"bssid": {"pattern": MAC_VAR_PATTERN},
},
},
{"$ref": "#/definitions/base_wireless_settings"},
Expand Down

0 comments on commit 9b1a5fd

Please sign in to comment.