mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Remove http.development (#10267)
* Remove http.development * Remove development * Remove development from tests * Remove constant
This commit is contained in:
parent
619d329a16
commit
4dc9ac820f
@ -76,7 +76,6 @@ def setup(hass, yaml_config):
|
|||||||
|
|
||||||
server = HomeAssistantWSGI(
|
server = HomeAssistantWSGI(
|
||||||
hass,
|
hass,
|
||||||
development=False,
|
|
||||||
server_host=config.host_ip_addr,
|
server_host=config.host_ip_addr,
|
||||||
server_port=config.listen_port,
|
server_port=config.listen_port,
|
||||||
api_password=None,
|
api_password=None,
|
||||||
|
@ -218,7 +218,10 @@ class ExternalPanel(AbstractPanel):
|
|||||||
URL_PANEL_COMPONENT_FP.format(self.component_name, self.md5)
|
URL_PANEL_COMPONENT_FP.format(self.component_name, self.md5)
|
||||||
|
|
||||||
if self.component_name not in self.REGISTERED_COMPONENTS:
|
if self.component_name not in self.REGISTERED_COMPONENTS:
|
||||||
hass.http.register_static_path(self.webcomponent_url, self.path)
|
hass.http.register_static_path(
|
||||||
|
self.webcomponent_url, self.path,
|
||||||
|
# if path is None, we're in prod mode, so cache static assets
|
||||||
|
frontend_repository_path is None)
|
||||||
self.REGISTERED_COMPONENTS.add(self.component_name)
|
self.REGISTERED_COMPONENTS.add(self.component_name)
|
||||||
|
|
||||||
|
|
||||||
@ -280,10 +283,11 @@ def async_setup(hass, config):
|
|||||||
is_dev = repo_path is not None
|
is_dev = repo_path is not None
|
||||||
|
|
||||||
if is_dev:
|
if is_dev:
|
||||||
hass.http.register_static_path("/home-assistant-polymer", repo_path)
|
hass.http.register_static_path(
|
||||||
|
"/home-assistant-polymer", repo_path, False)
|
||||||
hass.http.register_static_path(
|
hass.http.register_static_path(
|
||||||
"/static/translations",
|
"/static/translations",
|
||||||
os.path.join(repo_path, "build/translations"))
|
os.path.join(repo_path, "build/translations"), False)
|
||||||
sw_path = os.path.join(repo_path, "build/service_worker.js")
|
sw_path = os.path.join(repo_path, "build/service_worker.js")
|
||||||
static_path = os.path.join(repo_path, 'hass_frontend')
|
static_path = os.path.join(repo_path, 'hass_frontend')
|
||||||
else:
|
else:
|
||||||
@ -293,13 +297,13 @@ def async_setup(hass, config):
|
|||||||
static_path = frontend_path
|
static_path = frontend_path
|
||||||
|
|
||||||
hass.http.register_static_path("/service_worker.js", sw_path, False)
|
hass.http.register_static_path("/service_worker.js", sw_path, False)
|
||||||
hass.http.register_static_path("/robots.txt",
|
hass.http.register_static_path(
|
||||||
os.path.join(static_path, "robots.txt"))
|
"/robots.txt", os.path.join(static_path, "robots.txt"), not is_dev)
|
||||||
hass.http.register_static_path("/static", static_path)
|
hass.http.register_static_path("/static", static_path, not is_dev)
|
||||||
|
|
||||||
local = hass.config.path('www')
|
local = hass.config.path('www')
|
||||||
if os.path.isdir(local):
|
if os.path.isdir(local):
|
||||||
hass.http.register_static_path("/local", local)
|
hass.http.register_static_path("/local", local, not is_dev)
|
||||||
|
|
||||||
index_view = IndexView(is_dev)
|
index_view = IndexView(is_dev)
|
||||||
hass.http.register_view(index_view)
|
hass.http.register_view(index_view)
|
||||||
|
@ -28,9 +28,8 @@ from homeassistant.util.logging import HideSensitiveDataFilter
|
|||||||
from .auth import auth_middleware
|
from .auth import auth_middleware
|
||||||
from .ban import ban_middleware
|
from .ban import ban_middleware
|
||||||
from .const import (
|
from .const import (
|
||||||
KEY_USE_X_FORWARDED_FOR, KEY_TRUSTED_NETWORKS,
|
KEY_USE_X_FORWARDED_FOR, KEY_TRUSTED_NETWORKS, KEY_BANS_ENABLED,
|
||||||
KEY_BANS_ENABLED, KEY_LOGIN_THRESHOLD,
|
KEY_LOGIN_THRESHOLD, KEY_AUTHENTICATED)
|
||||||
KEY_DEVELOPMENT, KEY_AUTHENTICATED)
|
|
||||||
from .static import (
|
from .static import (
|
||||||
staticresource_middleware, CachingFileResponse, CachingStaticResource)
|
staticresource_middleware, CachingFileResponse, CachingStaticResource)
|
||||||
from .util import get_real_ip
|
from .util import get_real_ip
|
||||||
@ -43,7 +42,6 @@ CONF_API_PASSWORD = 'api_password'
|
|||||||
CONF_SERVER_HOST = 'server_host'
|
CONF_SERVER_HOST = 'server_host'
|
||||||
CONF_SERVER_PORT = 'server_port'
|
CONF_SERVER_PORT = 'server_port'
|
||||||
CONF_BASE_URL = 'base_url'
|
CONF_BASE_URL = 'base_url'
|
||||||
CONF_DEVELOPMENT = 'development'
|
|
||||||
CONF_SSL_CERTIFICATE = 'ssl_certificate'
|
CONF_SSL_CERTIFICATE = 'ssl_certificate'
|
||||||
CONF_SSL_KEY = 'ssl_key'
|
CONF_SSL_KEY = 'ssl_key'
|
||||||
CONF_CORS_ORIGINS = 'cors_allowed_origins'
|
CONF_CORS_ORIGINS = 'cors_allowed_origins'
|
||||||
@ -84,7 +82,6 @@ HTTP_SCHEMA = vol.Schema({
|
|||||||
vol.Optional(CONF_SERVER_HOST, default=DEFAULT_SERVER_HOST): cv.string,
|
vol.Optional(CONF_SERVER_HOST, default=DEFAULT_SERVER_HOST): cv.string,
|
||||||
vol.Optional(CONF_SERVER_PORT, default=SERVER_PORT): cv.port,
|
vol.Optional(CONF_SERVER_PORT, default=SERVER_PORT): cv.port,
|
||||||
vol.Optional(CONF_BASE_URL): cv.string,
|
vol.Optional(CONF_BASE_URL): cv.string,
|
||||||
vol.Optional(CONF_DEVELOPMENT, default=DEFAULT_DEVELOPMENT): cv.string,
|
|
||||||
vol.Optional(CONF_SSL_CERTIFICATE, default=None): cv.isfile,
|
vol.Optional(CONF_SSL_CERTIFICATE, default=None): cv.isfile,
|
||||||
vol.Optional(CONF_SSL_KEY, default=None): cv.isfile,
|
vol.Optional(CONF_SSL_KEY, default=None): cv.isfile,
|
||||||
vol.Optional(CONF_CORS_ORIGINS, default=[]):
|
vol.Optional(CONF_CORS_ORIGINS, default=[]):
|
||||||
@ -113,7 +110,6 @@ def async_setup(hass, config):
|
|||||||
api_password = conf[CONF_API_PASSWORD]
|
api_password = conf[CONF_API_PASSWORD]
|
||||||
server_host = conf[CONF_SERVER_HOST]
|
server_host = conf[CONF_SERVER_HOST]
|
||||||
server_port = conf[CONF_SERVER_PORT]
|
server_port = conf[CONF_SERVER_PORT]
|
||||||
development = conf[CONF_DEVELOPMENT] == '1'
|
|
||||||
ssl_certificate = conf[CONF_SSL_CERTIFICATE]
|
ssl_certificate = conf[CONF_SSL_CERTIFICATE]
|
||||||
ssl_key = conf[CONF_SSL_KEY]
|
ssl_key = conf[CONF_SSL_KEY]
|
||||||
cors_origins = conf[CONF_CORS_ORIGINS]
|
cors_origins = conf[CONF_CORS_ORIGINS]
|
||||||
@ -128,7 +124,6 @@ def async_setup(hass, config):
|
|||||||
|
|
||||||
server = HomeAssistantWSGI(
|
server = HomeAssistantWSGI(
|
||||||
hass,
|
hass,
|
||||||
development=development,
|
|
||||||
server_host=server_host,
|
server_host=server_host,
|
||||||
server_port=server_port,
|
server_port=server_port,
|
||||||
api_password=api_password,
|
api_password=api_password,
|
||||||
@ -176,7 +171,7 @@ def async_setup(hass, config):
|
|||||||
class HomeAssistantWSGI(object):
|
class HomeAssistantWSGI(object):
|
||||||
"""WSGI server for Home Assistant."""
|
"""WSGI server for Home Assistant."""
|
||||||
|
|
||||||
def __init__(self, hass, development, api_password, ssl_certificate,
|
def __init__(self, hass, api_password, ssl_certificate,
|
||||||
ssl_key, server_host, server_port, cors_origins,
|
ssl_key, server_host, server_port, cors_origins,
|
||||||
use_x_forwarded_for, trusted_networks,
|
use_x_forwarded_for, trusted_networks,
|
||||||
login_threshold, is_ban_enabled):
|
login_threshold, is_ban_enabled):
|
||||||
@ -194,10 +189,8 @@ class HomeAssistantWSGI(object):
|
|||||||
self.app[KEY_TRUSTED_NETWORKS] = trusted_networks
|
self.app[KEY_TRUSTED_NETWORKS] = trusted_networks
|
||||||
self.app[KEY_BANS_ENABLED] = is_ban_enabled
|
self.app[KEY_BANS_ENABLED] = is_ban_enabled
|
||||||
self.app[KEY_LOGIN_THRESHOLD] = login_threshold
|
self.app[KEY_LOGIN_THRESHOLD] = login_threshold
|
||||||
self.app[KEY_DEVELOPMENT] = development
|
|
||||||
|
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self.development = development
|
|
||||||
self.api_password = api_password
|
self.api_password = api_password
|
||||||
self.ssl_certificate = ssl_certificate
|
self.ssl_certificate = ssl_certificate
|
||||||
self.ssl_key = ssl_key
|
self.ssl_key = ssl_key
|
||||||
|
@ -7,6 +7,5 @@ KEY_BANS_ENABLED = 'ha_bans_enabled'
|
|||||||
KEY_BANNED_IPS = 'ha_banned_ips'
|
KEY_BANNED_IPS = 'ha_banned_ips'
|
||||||
KEY_FAILED_LOGIN_ATTEMPTS = 'ha_failed_login_attempts'
|
KEY_FAILED_LOGIN_ATTEMPTS = 'ha_failed_login_attempts'
|
||||||
KEY_LOGIN_THRESHOLD = 'ha_login_threshold'
|
KEY_LOGIN_THRESHOLD = 'ha_login_threshold'
|
||||||
KEY_DEVELOPMENT = 'ha_development'
|
|
||||||
|
|
||||||
HTTP_HEADER_X_FORWARDED_FOR = 'X-Forwarded-For'
|
HTTP_HEADER_X_FORWARDED_FOR = 'X-Forwarded-For'
|
||||||
|
@ -8,8 +8,6 @@ from aiohttp.web_exceptions import HTTPNotFound
|
|||||||
from aiohttp.web_urldispatcher import StaticResource
|
from aiohttp.web_urldispatcher import StaticResource
|
||||||
from yarl import unquote
|
from yarl import unquote
|
||||||
|
|
||||||
from .const import KEY_DEVELOPMENT
|
|
||||||
|
|
||||||
_FINGERPRINT = re.compile(r'^(.+)-[a-z0-9]{32}\.(\w+)$', re.IGNORECASE)
|
_FINGERPRINT = re.compile(r'^(.+)-[a-z0-9]{32}\.(\w+)$', re.IGNORECASE)
|
||||||
|
|
||||||
|
|
||||||
@ -53,10 +51,9 @@ class CachingFileResponse(FileResponse):
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def sendfile(request, fobj, count):
|
def sendfile(request, fobj, count):
|
||||||
"""Sendfile that includes a cache header."""
|
"""Sendfile that includes a cache header."""
|
||||||
if not request.app[KEY_DEVELOPMENT]:
|
cache_time = 31 * 86400 # = 1 month
|
||||||
cache_time = 31 * 86400 # = 1 month
|
self.headers[hdrs.CACHE_CONTROL] = "public, max-age={}".format(
|
||||||
self.headers[hdrs.CACHE_CONTROL] = "public, max-age={}".format(
|
cache_time)
|
||||||
cache_time)
|
|
||||||
|
|
||||||
yield from orig_sendfile(request, fobj, count)
|
yield from orig_sendfile(request, fobj, count)
|
||||||
|
|
||||||
|
@ -22,9 +22,9 @@ BASE_CONFIG = (
|
|||||||
|
|
||||||
|
|
||||||
def change_yaml_files(check_dict):
|
def change_yaml_files(check_dict):
|
||||||
"""Change the ['yaml_files'] property and remove the config path.
|
"""Change the ['yaml_files'] property and remove the configuration path.
|
||||||
|
|
||||||
Also removes other files like service.yaml that gets loaded
|
Also removes other files like service.yaml that gets loaded.
|
||||||
"""
|
"""
|
||||||
root = get_test_config_dir()
|
root = get_test_config_dir()
|
||||||
keys = check_dict['yaml_files'].keys()
|
keys = check_dict['yaml_files'].keys()
|
||||||
@ -178,7 +178,6 @@ class TestCheckConfig(unittest.TestCase):
|
|||||||
self.assertDictEqual({
|
self.assertDictEqual({
|
||||||
'components': {'http': {'api_password': 'abc123',
|
'components': {'http': {'api_password': 'abc123',
|
||||||
'cors_allowed_origins': [],
|
'cors_allowed_origins': [],
|
||||||
'development': '0',
|
|
||||||
'ip_ban_enabled': True,
|
'ip_ban_enabled': True,
|
||||||
'login_attempts_threshold': -1,
|
'login_attempts_threshold': -1,
|
||||||
'server_host': '0.0.0.0',
|
'server_host': '0.0.0.0',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user