Improve DHCP + Zeroconf manifest validation (#49321)

This commit is contained in:
Paulus Schoutsen 2021-04-16 16:32:12 -07:00 committed by GitHub
parent f464663732
commit 984962d985
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 8 deletions

View File

@ -10,15 +10,15 @@
"dhcp": [ "dhcp": [
{ {
"hostname": "lyric-*", "hostname": "lyric-*",
"macaddress": "48A2E6" "macaddress": "48A2E6*"
}, },
{ {
"hostname": "lyric-*", "hostname": "lyric-*",
"macaddress": "B82CA0" "macaddress": "B82CA0*"
}, },
{ {
"hostname": "lyric-*", "hostname": "lyric-*",
"macaddress": "00D02D" "macaddress": "00D02D*"
} }
], ],
"iot_class": "cloud_polling" "iot_class": "cloud_polling"

View File

@ -75,17 +75,17 @@ DHCP = [
{ {
"domain": "lyric", "domain": "lyric",
"hostname": "lyric-*", "hostname": "lyric-*",
"macaddress": "48A2E6" "macaddress": "48A2E6*"
}, },
{ {
"domain": "lyric", "domain": "lyric",
"hostname": "lyric-*", "hostname": "lyric-*",
"macaddress": "B82CA0" "macaddress": "B82CA0*"
}, },
{ {
"domain": "lyric", "domain": "lyric",
"hostname": "lyric-*", "hostname": "lyric-*",
"macaddress": "00D02D" "macaddress": "00D02D*"
}, },
{ {
"domain": "myq", "domain": "myq",

View File

@ -148,6 +148,13 @@ def verify_version(value: str):
return value return value
def verify_wildcard(value: str):
"""Verify the matcher contains a wildcard."""
if "*" not in value:
raise vol.Invalid(f"'{value}' needs to contain a wildcard matcher")
return value
MANIFEST_SCHEMA = vol.Schema( MANIFEST_SCHEMA = vol.Schema(
{ {
vol.Required("domain"): str, vol.Required("domain"): str,
@ -160,7 +167,9 @@ MANIFEST_SCHEMA = vol.Schema(
vol.Schema( vol.Schema(
{ {
vol.Required("type"): str, vol.Required("type"): str,
vol.Optional("macaddress"): vol.All(str, verify_uppercase), vol.Optional("macaddress"): vol.All(
str, verify_uppercase, verify_wildcard
),
vol.Optional("manufacturer"): vol.All(str, verify_lowercase), vol.Optional("manufacturer"): vol.All(str, verify_lowercase),
vol.Optional("name"): vol.All(str, verify_lowercase), vol.Optional("name"): vol.All(str, verify_lowercase),
} }
@ -174,7 +183,9 @@ MANIFEST_SCHEMA = vol.Schema(
vol.Optional("dhcp"): [ vol.Optional("dhcp"): [
vol.Schema( vol.Schema(
{ {
vol.Optional("macaddress"): vol.All(str, verify_uppercase), vol.Optional("macaddress"): vol.All(
str, verify_uppercase, verify_wildcard
),
vol.Optional("hostname"): vol.All(str, verify_lowercase), vol.Optional("hostname"): vol.All(str, verify_lowercase),
} }
) )