mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Check that documentation urls are valid (#31188)
* Check that documentation urls are valid * Validate documentation url in pieces
This commit is contained in:
parent
1278f32306
commit
52c1bc9c26
@ -2,7 +2,7 @@
|
|||||||
"domain": "solarlog",
|
"domain": "solarlog",
|
||||||
"name": "Solar-Log",
|
"name": "Solar-Log",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integration/solarlog",
|
"documentation": "https://www.home-assistant.io/integrations/solarlog",
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": ["@Ernst79"],
|
"codeowners": ["@Ernst79"],
|
||||||
"requirements": ["sunwatcher==0.2.1"]
|
"requirements": ["sunwatcher==0.2.1"]
|
||||||
|
@ -1,11 +1,17 @@
|
|||||||
"""Manifest validation."""
|
"""Manifest validation."""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
from voluptuous.humanize import humanize_error
|
from voluptuous.humanize import humanize_error
|
||||||
|
|
||||||
from .model import Integration
|
from .model import Integration
|
||||||
|
|
||||||
|
DOCUMENTATION_URL_SCHEMA = "https"
|
||||||
|
DOCUMENTATION_URL_HOST = "www.home-assistant.io"
|
||||||
|
DOCUMENTATION_URL_PATH_PREFIX = "/integrations/"
|
||||||
|
DOCUMENTATION_URL_EXCEPTIONS = ["https://www.home-assistant.io/hassio"]
|
||||||
|
|
||||||
SUPPORTED_QUALITY_SCALES = [
|
SUPPORTED_QUALITY_SCALES = [
|
||||||
"gold",
|
"gold",
|
||||||
"internal",
|
"internal",
|
||||||
@ -13,6 +19,25 @@ SUPPORTED_QUALITY_SCALES = [
|
|||||||
"silver",
|
"silver",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def documentation_url(value: str) -> str:
|
||||||
|
"""Validate that a documentation url has the correct path and domain."""
|
||||||
|
if value in DOCUMENTATION_URL_EXCEPTIONS:
|
||||||
|
return value
|
||||||
|
|
||||||
|
parsed_url = urlparse(value)
|
||||||
|
if not parsed_url.scheme == DOCUMENTATION_URL_SCHEMA:
|
||||||
|
raise vol.Invalid("Documentation url is not prefixed with https")
|
||||||
|
if not parsed_url.netloc == DOCUMENTATION_URL_HOST:
|
||||||
|
raise vol.Invalid("Documentation url not hosted at www.home-assistant.io")
|
||||||
|
if not parsed_url.path.startswith(DOCUMENTATION_URL_PATH_PREFIX):
|
||||||
|
raise vol.Invalid(
|
||||||
|
"Documentation url does not begin with www.home-assistant.io/integrations"
|
||||||
|
)
|
||||||
|
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
MANIFEST_SCHEMA = vol.Schema(
|
MANIFEST_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required("domain"): str,
|
vol.Required("domain"): str,
|
||||||
@ -23,9 +48,9 @@ MANIFEST_SCHEMA = vol.Schema(
|
|||||||
vol.All([vol.All(vol.Schema({}, extra=vol.ALLOW_EXTRA), vol.Length(min=1))])
|
vol.All([vol.All(vol.Schema({}, extra=vol.ALLOW_EXTRA), vol.Length(min=1))])
|
||||||
),
|
),
|
||||||
vol.Optional("homekit"): vol.Schema({vol.Optional("models"): [str]}),
|
vol.Optional("homekit"): vol.Schema({vol.Optional("models"): [str]}),
|
||||||
vol.Required(
|
vol.Required("documentation"): vol.All(
|
||||||
"documentation"
|
vol.Url(), documentation_url # pylint: disable=no-value-for-parameter
|
||||||
): vol.Url(), # pylint: disable=no-value-for-parameter
|
),
|
||||||
vol.Optional("quality_scale"): vol.In(SUPPORTED_QUALITY_SCALES),
|
vol.Optional("quality_scale"): vol.In(SUPPORTED_QUALITY_SCALES),
|
||||||
vol.Required("requirements"): [str],
|
vol.Required("requirements"): [str],
|
||||||
vol.Required("dependencies"): [str],
|
vol.Required("dependencies"): [str],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user