From d25fe1b92fa55aa634a35c0ef6dbcc0da8dc8413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Pedro=20Algarvio?= Date: Mon, 20 Jun 2022 17:20:32 +0100 Subject: [PATCH] Allow variables in mac address patterns in schema.py (Closes #238) - Adds BLANK and VAR patterns - Patches MAC patterns - Removes usage of maxLength and minLength in mac and bssid properties Co-authored-by: Gagan Deep --- netjsonconfig/schema.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/netjsonconfig/schema.py b/netjsonconfig/schema.py index b4a264716..90b3d8d59 100644 --- a/netjsonconfig/schema.py +++ b/netjsonconfig/schema.py @@ -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#", @@ -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": { @@ -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, }, } @@ -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"},