Skip to content

Commit

Permalink
[fix] Allow variables in mac address patterns in schema.py (Closes #238)
Browse files Browse the repository at this point in the history
- Adds BLANK and VAR patterns
- Patches MAC patterns
- Removes usage of maxLength and minLength in mac and bssid properties

Co-authored-by: Gagan Deep <the.one.above.all.titan@gmail.com>
  • Loading branch information
lpalgarvio and pandafy committed Jul 26, 2022
1 parent 6db272c commit a446f78
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions netjsonconfig/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

DEFAULT_FILE_MODE = '0644'
X509_FILE_MODE = '0600'
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}|{1})$'.format(MAC_PATTERN, VAR_PATTERN)
MAC_VAR_BLANK_PATTERN = '^({0}|)$'.format(MAC_VAR_PATTERN)

schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
Expand Down Expand Up @@ -140,8 +142,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 +319,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 +846,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 a446f78

Please sign in to comment.