Time SNTP validate server format (#254)

This commit is contained in:
Otto Winter 2018-12-02 13:15:28 +01:00 committed by GitHub
parent f2f869db89
commit 3d49ffa134
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

@ -9,7 +9,7 @@ SNTPComponent = time_.time_ns.class_('SNTPComponent', time_.RealTimeClockCompone
PLATFORM_SCHEMA = time_.TIME_PLATFORM_SCHEMA.extend({
cv.GenerateID(): cv.declare_variable_id(SNTPComponent),
vol.Optional(CONF_SERVERS): vol.All(cv.ensure_list, [cv.string], vol.Length(min=1, max=3)),
vol.Optional(CONF_SERVERS): vol.All(cv.ensure_list, [cv.domain], vol.Length(min=1, max=3)),
vol.Optional(CONF_LAMBDA): cv.lambda_,
}).extend(cv.COMPONENT_SCHEMA.schema)

View file

@ -441,6 +441,13 @@ def hostname(value):
return value
def domain(value):
value = string(value)
if re.match(vol.DOMAIN_REGEX, value) is None:
raise vol.Invalid("Invalid domain: {}".format(value))
return value
def domain_name(value):
value = string(value)
if not value.startswith('.'):