Add url to validation (#2874)
* Add url to validation * Fix pylint issue * Clean-up
This commit is contained in:
parent
c74e167a7b
commit
ca1de9cac1
2 changed files with 29 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
|||
"""Helpers for config validation using voluptuous."""
|
||||
from datetime import timedelta
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from typing import Any, Union, TypeVar, Callable, Sequence, List, Dict
|
||||
|
||||
|
@ -255,6 +256,17 @@ def time_zone(value):
|
|||
weekdays = vol.All(ensure_list, [vol.In(WEEKDAYS)])
|
||||
|
||||
|
||||
# pylint: disable=no-value-for-parameter
|
||||
def url(value: Any) -> str:
|
||||
"""Validate an URL."""
|
||||
url_in = str(value)
|
||||
|
||||
if urlparse(url_in).scheme in ['http', 'https']:
|
||||
return vol.Schema(vol.Url())(url_in)
|
||||
|
||||
raise vol.Invalid('invalid url')
|
||||
|
||||
|
||||
# Validator helpers
|
||||
|
||||
def key_dependency(key, dependency):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue